You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/08/25 07:30:12 UTC

[GitHub] [shardingsphere-elasticjob] Technoboy- commented on issue #1410: OneOffJob reschedule error

Technoboy- commented on issue #1410:
URL: https://github.com/apache/shardingsphere-elasticjob/issues/1410#issuecomment-679855580


   I suggest to add a check logic for OneOffJobBootstrap#execute : 
   ```
   /**
        * Execute job.
        */
       public void execute() {
           Preconditions.checkArgument(Strings.isNullOrEmpty(jobScheduler.getJobConfig().getCron()), "Cron should be empty for OneOffJob.");
           jobScheduler.getJobScheduleController().executeJob();
       }
   ```
   
   and then fix RescheduleListenerManager like below :
   ```
   class CronSettingAndJobEventChangedJobListener extends AbstractJobListener {
           
           @Override
           protected void dataChanged(final String path, final Type eventType, final String data) {
               if (configNode.isConfigPath(path) && Type.NODE_CHANGED == eventType && !JobRegistry.getInstance().isShutdown(jobName)) {
                   JobConfiguration jobConfiguration = YamlEngine.unmarshal(data, JobConfigurationPOJO.class).toJobConfiguration();
                   if(StringUtils.isEmpty(jobConfiguration.getCron())){
                       JobRegistry.getInstance().getJobScheduleController(jobName).rescheduleJob();
                   } else{
                       JobRegistry.getInstance().getJobScheduleController(jobName).rescheduleJob(jobConfiguration.getCron());
                   }
               }
           }
       }
   ```
   
   Add JobScheduleController#rescheduleJob:
   ```
   /**
        * Reschedule OneOff job.
        */
       public synchronized void rescheduleJob() {
           try {
               SimpleTrigger trigger = (SimpleTrigger) scheduler.getTrigger(TriggerKey.triggerKey(triggerIdentity));
               if (!scheduler.isShutdown() && null != trigger) {
                   scheduler.rescheduleJob(TriggerKey.triggerKey(triggerIdentity), createOneOffTrigger());
               }
           } catch (final SchedulerException ex) {
               throw new JobSystemException(ex);
           }
       }
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org