@Override
 public final void execute(final JobExecutionContext context) throws JobExecutionException {
   log.debug("Elastic job: job execute begin, job execution context:{}.", context);
   shardingService.shardingIfNecessary();
   JobExecutionMultipleShardingContext shardingContext =
       executionContextService.getJobExecutionShardingContext();
   if (executionService.misfireIfNecessary(shardingContext.getShardingItems())) {
     log.info(
         "Previous job is still running, new job will start after previous job completed. Misfired job had recorded.");
     return;
   }
   executionService.cleanPreviousExecutionInfo();
   executeJobInternal(shardingContext);
   log.debug("Elastic job: execute normal completed, sharding context:{}.", shardingContext);
   while (!executionService.getMisfiredJobItems(shardingContext.getShardingItems()).isEmpty()
       && !stoped
       && !shardingService.isNeedSharding()) {
     log.debug("Elastic job: execute misfired job, sharding context:{}.", shardingContext);
     executionService.clearMisfire(shardingContext.getShardingItems());
     executeJobInternal(shardingContext);
     log.debug("Elastic job: misfired job completed, sharding context:{}.", shardingContext);
   }
   if (configService.isFailover() && !stoped) {
     failoverService.failoverIfNecessary();
   }
   log.debug("Elastic job: execute all completed, job execution context:{}.", context);
 }
 private void executeJobInternal(final JobExecutionMultipleShardingContext shardingContext) {
   if (shardingContext.getShardingItems().isEmpty()) {
     log.debug("Elastic job: sharding item is empty, job execution context:{}.", shardingContext);
     return;
   }
   executionService.registerJobBegin(shardingContext);
   executeJob(shardingContext);
   executionService.registerJobCompleted(shardingContext);
   if (configService.isFailover()) {
     failoverService.updateFailoverComplete(shardingContext.getShardingItems());
   }
 }
Exemplo n.º 3
0
 /**
  * 恢复因服务器崩溃而停止的作业.
  *
  * <p>不会恢复手工设置停止运行的作业.
  */
 public void resumeCrashedJob() {
   serverService.persistServerOnline();
   executionService.clearRunningInfo(shardingService.getLocalHostShardingItems());
   if (serverService.isJobStopedManually()) {
     return;
   }
   try {
     scheduler.resumeAll();
   } catch (final SchedulerException ex) {
     throw new JobException(ex);
   }
 }