Кварцевый планировщик запланирован но не огонь - PullRequest
0 голосов
/ 16 января 2019

Я пытаюсь запланировать планировщик и печатать (только здесь), когда мой планировщик запускается, когда я планирую его в таблице QRTZ_TRIGGERS, а также в таблице QRTZ_JOB_DETAILS, но не срабатывает вовремя. где моя конфигурация кварцевого планировщика, как,

@Configuration
public class QuartzSchedulerConfiguration {
    @Bean
    public Scheduler getScheduler() throws SchedulerException {
    return StdSchedulerFactory.getDefaultScheduler();
    }
}

и файл quartz.properties, например,

## QuartzProperties
org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount=10
org.quartz.threadPool.
threadsInheritContextClassLoaderOfInitializingThread=true
org.quartz.jobStore.tablePrefix=QRTZ_
#The datasource for the jobstore that is to be used
org.quartz.jobStore.dataSource=myDS
org.quartz.dataSource.myDS.driver=com.mysql.cj.jdbc.Driver
org.quartz.dataSource.myDS.URL=jdbc:mysql://localhost:3306/my_db? 
useSSL=false
org.quartz.dataSource.myDS.user=root
org.quartz.dataSource.myDS.password=1111
org.quartz.dataSource.myDS.maxConnections=20

и класс обслуживания имеют,

    @Autowired
private Scheduler scheduler;

public String addFTP(FTPDomain ftpDomain) {
    String msg = "";
    //Start schedule =======================================================
      String str = "2019-01-16 13:10:01"; 
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); 
        LocalDateTime localeDateTime = LocalDateTime.parse(str, formatter);
      System.out.println("Date time is "+localeDateTime);
      try { 
       ZonedDateTime dateTime = ZonedDateTime.of(localeDateTime, ZoneId.of("Asia/Kolkata"));
       if(dateTime.isBefore(ZonedDateTime.now())) {
           msg = "You are schedule a expired Date and time";
          System.out.println(msg);
       }
       JobDetail jobDetail = buildJobDetail(ftpDomain);
       Trigger trigger = buildJobTrigger(jobDetail, dateTime);
       scheduler.scheduleJob(jobDetail, trigger);    // ## here i schedule
       System.out.println(jobDetail.getKey().getName()+"   "+ jobDetail.getKey().getGroup()+""+ "Scheduller Scheduled Successfully!");
      } catch (SchedulerException ex) {
        System.out.println( "Error scheduling email. Please try later!");
   }
 //Stop schedulling=========================================================================
return ftpTransferDaoInterface.addFTP(ftpDomain);
}

 private JobDetail buildJobDetail(FTPDomain ftpDamain) {
    JobDataMap jobDataMap = new JobDataMap();
    jobDataMap.put("destPath", ftpDamain.getServerDestinationPath());
    jobDataMap.put("ip", ftpDamain.getServerIP());
    jobDataMap.put("user", ftpDamain.getServerUser());

    return JobBuilder.newJob(FTPTransferJob.class)
            .withIdentity(UUID.randomUUID().toString(), "schedule-jobs")
            .withDescription("Send schedule Job")
            .usingJobData(jobDataMap)
            .storeDurably().build();
 }

 private Trigger buildJobTrigger(JobDetail jobDetail, ZonedDateTime startAt) {
    return TriggerBuilder.newTrigger()
            .forJob(jobDetail)
            .withIdentity(jobDetail.getKey().getName(), "email-triggers")
            .withDescription("Send Email Trigger")
            .startAt(Date.from(startAt.toInstant()))
            .withSchedule(SimpleScheduleBuilder
                    .simpleSchedule()
                    .withMisfireHandlingInstructionFireNow()
            ).build();
 }

и мой класс Кварц JOB, как,

@Component
public class FTPTransferJob extends QuartzJobBean {
protected void executeInternal(JobExecutionContext context)
  throws JobExecutionException {
    System.err.println("Executing Job with key {}"+ 
                          context.getJobDetail().getKey());
    JobDataMap jobDataMap = context.getMergedJobDataMap();
    String destination = jobDataMap.getString("destPath");
    String ip = jobDataMap.getString("ip");
    String user = jobDataMap.getString("user");
    System.err.println("Schedulled Job Executed Here "+destination+", ip 
                                     is "+ip+", user is "+user);
 }
}

Кто-нибудь может найти решение? Спасибо ...

...