/** * Create a JobBuilder with which to define a <code>JobDetail</code>, * and set the class name of the <code>Job</code> to be executed. * * @return a new JobBuilder */ public static JobBuilder newJob(Class <? extends Job> jobClass) { JobBuilder b = new JobBuilder(); b.ofType(jobClass); return b; }
/** * Create a JobBuilder with which to define a <code>JobDetail</code>, * and set the class name of the <code>Job</code> to be executed. * * @return a new JobBuilder */ public static JobBuilder newJob(Class <? extends Job> jobClass) { JobBuilder b = new JobBuilder(); b.ofType(jobClass); return b; }
/** Add a task to the scheduler */ public void addTask(String name, Class<? extends Task> taskclass, TaskTimer timer) throws SchedulerException, ParseException { assert timer != null : "Cannot add scheduler task " + name + " as no timer is set"; JobDetail job = JobBuilder.newJob() .withIdentity(name, Scheduler.DEFAULT_GROUP) .ofType(taskclass) .build(); // new JobDetail(name, Scheduler.DEFAULT_GROUP, taskclass); if (timer.getCronExpression() != null && !timer.getCronExpression().isEmpty()) { logger.info( "Scheduled task metadata. Task name: {}" + ", cron expression: {}", taskclass.getName(), timer.getCronExpression()); } else { logger.info("Scheduled task metadata. Task name: {}", taskclass.getName()); } scheduler.scheduleJob(job, timer.getTrigger()); }
JobBuilder.newJob() .withIdentity(name, Scheduler.DEFAULT_GROUP) .ofType(taskclass)
private void scheduleNewBackupJob(BackupConfig newBackupConfig) { if (newBackupConfig == null || isBlank(newBackupConfig.getSchedule())) { return; } try { JobDetail jobDetail = newJob() .withIdentity(jobKey()) .ofType(ScheduleBackupQuartzJob.class) .usingJobData(jobDataMap()) .build(); CronTrigger trigger = newTrigger() .withIdentity(triggerKey()) .withSchedule(cronSchedule(new CronExpression(newBackupConfig.getSchedule()))) .build(); quartzScheduler.scheduleJob(jobDetail, trigger); LOG.info("Initialized backup job with schedule " + newBackupConfig.getSchedule()); clearServerHealthError(); } catch (SchedulerException e) { LOG.error("Unable to schedule backup job", e); setServerHealthError("Unable to schedule backup job.", "Check the server log for detailed errors: " + e.getMessage()); } catch (ParseException e) { LOG.error("Unable to schedule backup job", e); setServerHealthError("Unable to schedule backup job.", "Invalid cron syntax for backup configuration at offset " + e.getErrorOffset() + ": " + e.getMessage()); } }
private void scheduleJob(Scheduler scheduler, PipelineConfig pipelineConfig) { TimerConfig timer = pipelineConfig.getTimer(); if (timer != null) { try { CronTrigger trigger = newTrigger() .withIdentity(triggerKey(CaseInsensitiveString.str(pipelineConfig.name()), PIPELINE_TRIGGGER_TIMER_GROUP)) .withSchedule(cronSchedule(new CronExpression(timer.getTimerSpec()))) .build(); JobDetail jobDetail = newJob() .withIdentity(jobKey(CaseInsensitiveString.str(pipelineConfig.name()), PIPELINE_TRIGGGER_TIMER_GROUP)) .ofType(SchedulePipelineQuartzJob.class) .usingJobData(jobDataMapFor(pipelineConfig)) .build(); scheduler.scheduleJob(jobDetail, trigger); LOG.info("Initialized timer for pipeline {} with {}", pipelineConfig.name(), timer.getTimerSpec()); } catch (ParseException e) { showPipelineError(pipelineConfig, e, "Bad timer specification for timer in Pipeline: " + pipelineConfig.name(), "Cannot schedule pipeline using the timer"); } catch (SchedulerException e) { showPipelineError(pipelineConfig, e, "Could not register pipeline '" + pipelineConfig.name() + "' with timer", ""); } } }
public JobBuilder getJobBuilder() { JobBuilder b = JobBuilder.newJob() .ofType(getJobClass()) .requestRecovery(requestsRecovery()) .storeDurably(isDurable()) .usingJobData(getJobDataMap()) .withDescription(getDescription()) .withIdentity(getKey()); return b; } }
JobDetail job = newJob().withIdentity(jobTriggerName, JOB_INITIALIZATION_PLUGIN_NAME).ofType(FileScanJob.class) .usingJobData(FileScanJob.FILE_NAME, jobFile.getFileName()) .usingJobData(FileScanJob.FILE_SCAN_LISTENER_NAME, JOB_INITIALIZATION_PLUGIN_NAME + '_' + getName())
public JobBuilder getJobBuilder() { JobBuilder b = JobBuilder.newJob() .ofType(getJobClass()) .requestRecovery(requestsRecovery()) .storeDurably(isDurable()) .usingJobData(getJobDataMap()) .withDescription(getDescription()) .withIdentity(getKey()); return b; } }
JobDetail job = newJob().withIdentity(jobTriggerName, JOB_INITIALIZATION_PLUGIN_NAME).ofType(FileScanJob.class) .usingJobData(FileScanJob.FILE_NAME, jobFile.getFileName()) .usingJobData(FileScanJob.FILE_SCAN_LISTENER_NAME, JOB_INITIALIZATION_PLUGIN_NAME + '_' + getName())
private JobDetail buildSingleJob(String executionID) { JobDataMap data = new JobDataMap(); data.put(EXECUTION_ID, executionID); return JobBuilder.newJob().ofType(ExecutionJob.class).usingJobData(data).build(); }
@Override protected JobDetail createJobWithBasicMapValues(Object instance, String methodName, Class<?>[] inputTypes, Object[] inputParams) { String jobName = generateUniqueNameForInstance(instance, methodName); boolean allowsConcurrent = JobWrapper.methodAllowsConcurrent(instance, methodName); Class<? extends Job> jobType = allowsConcurrent ? PersistentJobWrapper.class : PersistentSequentialJobWrapper.class; JobDetail job = newJob() .withIdentity(jobName, Scheduler.DEFAULT_GROUP) .ofType(jobType) .build(); setBasicMapValues(job.getJobDataMap(), instance, methodName, inputTypes, inputParams); return job; }
@Override protected JobDetail createJobWithBasicMapValues(Object instance, String methodName, Class<?>[] inputTypes, Object[] inputParams) { boolean allowsConcurrent = JobWrapper.methodAllowsConcurrent(instance, methodName); Class<? extends Job> jobType = allowsConcurrent ? JobWrapper.class : SequentialJobWrapper.class; String jobName = generateUniqueNameForInstance(instance, methodName); JobDetail job = newJob() .withIdentity(jobName, Scheduler.DEFAULT_GROUP) .ofType(jobType) .build(); setBasicMapValues(job.getJobDataMap(), instance, methodName, inputTypes, inputParams); return job; }
/** * Get the job detail. * * @return - the job detail. */ private JobDetail getJobDetail() { JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put(ACTION_JOB_DATA_MAP_KEY, this); final JobDetail jobDetail = JobBuilder.newJob() .withIdentity(getJobName(), getJobGroup()) .usingJobData(jobDataMap) .ofType(JobDefinition.class) .build(); return jobDetail; }
private JobDetail buildScheduledJob(ExecutiontTaskParameters task) { JobDataMap data = new JobDataMap(); data.put(EXECUTION_TASK_ID, task.getId().toString()); data.put(EXECUTION_PARAMETERS, task.getExecutionsParameters()); return JobBuilder.newJob().ofType(ExecutionJob.class).withIdentity(task.getId().toString()).usingJobData(data).build(); }
/** * Get the job detail. * * @return - the job detail. */ private JobDetail getJobDetail() { JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put(ACTION_JOB_DATA_MAP_KEY, this); final JobDetail jobDetail = JobBuilder.newJob() .withIdentity(getJobName(), getJobGroup()) .usingJobData(jobDataMap) .ofType(JobDefinition.class) .build(); return jobDetail; }
protected JobDetail buildJobDetail(ScheduledPersistedActionImpl schedule) { JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put(JOB_ACTION_NODEREF, schedule.getActionNodeRef().toString()); jobDataMap.put(JOB_SCHEDULE_NODEREF, schedule.getPersistedAtNodeRef().toString()); return JobBuilder.newJob() .withIdentity(schedule.getPersistedAtNodeRef().toString(), SCHEDULER_GROUP) .ofType(ScheduledJobWrapper.class) .setJobData(jobDataMap) .build(); }
protected JobDetail buildJobDetail(ScheduledPersistedActionImpl schedule) { JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put(JOB_ACTION_NODEREF, schedule.getActionNodeRef().toString()); jobDataMap.put(JOB_SCHEDULE_NODEREF, schedule.getPersistedAtNodeRef().toString()); return JobBuilder.newJob() .withIdentity(schedule.getPersistedAtNodeRef().toString(), SCHEDULER_GROUP) .ofType(ScheduledJobWrapper.class) .setJobData(jobDataMap) .build(); }
protected void startJob(JobDefinition job) throws SchedulerException { String cron = cronToQuarzCron(job.getCron()); Trigger trigger = newTrigger() .withIdentity(job.getName(), SchedulerConsts.SCHEDULER_GROUP_NAME) .withSchedule(cronSchedule(cron)) .forJob(job.getName(), SchedulerConsts.SCHEDULER_GROUP_NAME) .build(); final Class jobClass = job.isConcurrent() ? CommandJob.class : StatefulCommandJob.class; final JobDetail jd = newJob() .withIdentity(job.getName(), SchedulerConsts.SCHEDULER_GROUP_NAME) .ofType(jobClass) .build(); jd.getJobDataMap().put(SchedulerConsts.CONFIG_JOB_COMMAND, job.getCommand()); jd.getJobDataMap().put(SchedulerConsts.CONFIG_JOB_COMMAND_CATALOG, job.getCatalog()); jd.getJobDataMap().put(SchedulerConsts.CONFIG_JOB_PARAMS, job.getParams()); scheduler.scheduleJob(jd, trigger); log.info("Job " + job.getName() + " added [" + job.getCron() + "]. Will fire first time at " + trigger.getNextFireTime()); }
@Before public void setUp() throws Exception { jobDetail = JobBuilder.newJob() .withIdentity("propTablesCleanupJob") .ofType(PropTablesCleanupJob.class).build(); jobDetail.getJobDataMap().put("propTablesCleaner", propTablesCleaner); cleanupJob = new PropTablesCleanupJob(); when(jobCtx.getJobDetail()).thenReturn(jobDetail); }