コード例 #1
0
 @Override
 public ScheduleToken schedule(Instant triggerDateTime, Object event) {
   Assert.state(initialized, () -> "Scheduler is not yet initialized");
   EventMessage eventMessage = GenericEventMessage.asEventMessage(event);
   String jobIdentifier = JOB_NAME_PREFIX + eventMessage.getIdentifier();
   QuartzScheduleToken tr = new QuartzScheduleToken(jobIdentifier, groupIdentifier);
   try {
     JobDetail jobDetail =
         buildJobDetail(eventMessage, new JobKey(jobIdentifier, groupIdentifier));
     scheduler.scheduleJob(jobDetail, buildTrigger(triggerDateTime, jobDetail.getKey()));
   } catch (SchedulerException e) {
     throw new SchedulingException("An error occurred while setting a timer for a saga", e);
   }
   return tr;
 }
コード例 #2
0
 /**
  * Builds the JobDetail instance for Quartz, which defines the Job that needs to be executed when
  * the trigger fires.
  *
  * <p>The resulting JobDetail must be identified by the given {@code jobKey} and represent a Job
  * that dispatches the given {@code event}.
  *
  * <p>This method may be safely overridden to change behavior. Defaults to a JobDetail to fire a
  * {@link FireEventJob}.
  *
  * @param event The event to be scheduled for dispatch
  * @param jobKey The key of the Job to schedule
  * @return a JobDetail describing the Job to be executed
  */
 protected JobDetail buildJobDetail(EventMessage event, JobKey jobKey) {
   JobDataMap jobData = jobDataBinder.toJobData(event);
   return JobBuilder.newJob(FireEventJob.class)
       .withDescription(event.getPayloadType().getName())
       .withIdentity(jobKey)
       .usingJobData(jobData)
       .build();
 }