org.quartz.JobBuilder Java Examples
The following examples show how to use
org.quartz.JobBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EmailService.java From quartz-manager with MIT License | 8 votes |
public void updateJob(String group, String name, JobDescriptor descriptor) { try { JobDetail oldJobDetail = scheduler.getJobDetail(jobKey(name, group)); if(Objects.nonNull(oldJobDetail)) { JobDataMap jobDataMap = oldJobDetail.getJobDataMap(); jobDataMap.put("subject", descriptor.getSubject()); jobDataMap.put("messageBody", descriptor.getMessageBody()); jobDataMap.put("to", descriptor.getTo()); jobDataMap.put("cc", descriptor.getCc()); jobDataMap.put("bcc", descriptor.getBcc()); JobBuilder jb = oldJobDetail.getJobBuilder(); JobDetail newJobDetail = jb.usingJobData(jobDataMap).storeDurably().build(); scheduler.addJob(newJobDetail, true); log.info("Updated job with key - {}", newJobDetail.getKey()); return; } log.warn("Could not find job with key - {}.{} to update", group, name); } catch (SchedulerException e) { log.error("Could not find job with key - {}.{} to update due to error - {}", group, name, e.getLocalizedMessage()); } }
Example #2
Source File: GetArchivesJob.java From sakai with Educational Community License v2.0 | 7 votes |
private void scheduleImport(String file, String siteId) { JobDataMap jobData = new JobDataMap(); jobData.put("zip", file); if (siteId != null) { jobData.put("siteId", siteId); } JobDetail jobDetail = JobBuilder.newJob(ImportJob.class) .withIdentity("Import Job") .setJobData(jobData) .build(); Scheduler scheduler = schedulerManager.getScheduler(); try { scheduler.addJob(jobDetail, true, true); scheduler.triggerJob(jobDetail.getKey()); } catch (SchedulerException e) { log.warn("Problem adding job to scheduler to import "+ file, e); } }
Example #3
Source File: ScheduleJobService.java From springboot-quartz with MIT License | 6 votes |
private void addJob(ScheduleJob scheduleJob) throws Exception{ checkNotNull(scheduleJob); Preconditions.checkNotNull(StringUtils.isEmpty(scheduleJob.getCronExpression()), "CronExpression is null"); TriggerKey triggerKey = TriggerKey.triggerKey(scheduleJob.getJobName(), scheduleJob.getJobGroup()); CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); if(trigger != null){ throw new Exception("job already exists!"); } // simulate job info db persist operation scheduleJob.setJobId(String.valueOf(QuartzJobFactory.jobList.size()+1)); QuartzJobFactory.jobList.add(scheduleJob); JobDetail jobDetail = JobBuilder.newJob(QuartzJobFactory.class).withIdentity(scheduleJob.getJobName(),scheduleJob.getJobGroup()).build(); jobDetail.getJobDataMap().put("scheduleJob", scheduleJob); CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression()); trigger = TriggerBuilder.newTrigger().withIdentity(scheduleJob.getJobName(), scheduleJob.getJobGroup()).withSchedule(cronScheduleBuilder).build(); scheduler.scheduleJob(jobDetail, trigger); }
Example #4
Source File: GetArchivesJob.java From sakai with Educational Community License v2.0 | 6 votes |
private void scheduleImport(String file, String siteId) { JobDataMap jobData = new JobDataMap(); jobData.put("zip", file); if (siteId != null) { jobData.put("siteId", siteId); } JobDetail jobDetail = JobBuilder.newJob(ImportJob.class) .withIdentity("Import Job") .setJobData(jobData) .build(); Scheduler scheduler = schedulerManager.getScheduler(); try { scheduler.addJob(jobDetail, true, true); scheduler.triggerJob(jobDetail.getKey()); } catch (SchedulerException e) { log.warn("Problem adding job to scheduler to import "+ file, e); } }
Example #5
Source File: TaskUtil.java From Summer with Apache License 2.0 | 6 votes |
public static TaskTrigger getIntervalTask(long interval, long delay, String taskName, TaskJob taskJob) { JobDetail job = JobBuilder.newJob(TaskObjJob.class).withIdentity(taskName).build(); Trigger trigger; if (delay > 0) { trigger = TriggerBuilder.newTrigger() .withIdentity(taskName) .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInMilliseconds(interval).repeatForever()) .startAt(new Date(System.currentTimeMillis() + delay)).build(); } else { trigger = TriggerBuilder.newTrigger() .withIdentity(taskName) .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInMilliseconds(interval).repeatForever()) .startNow().build(); } TaskObjJob.bindTriggerWithObj(trigger, taskJob); return new TaskTrigger(job, trigger); }
Example #6
Source File: SchedulerTool.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Convenience method for creating a JobDetail object from a JobBeanWrapper. The JobDetail object is * used to actually create a job within Quartz, and is also tracked by the {@link getJobDetail()} property * for use during the property editting process. * * @param job * @return JobDetail object constructed from the job argument */ private JobDetail createJobDetail (JobBeanWrapper job) { jobName = escapeEntities(jobName); JobDetail jd = JobBuilder.newJob(job.getJobClass()) .withIdentity(jobName, Scheduler.DEFAULT_GROUP) .requestRecovery() .storeDurably() .build(); JobDataMap map = jd.getJobDataMap(); map.put(JobBeanWrapper.SPRING_BEAN_NAME, job.getBeanId()); map.put(JobBeanWrapper.JOB_NAME, job.getJobName()); return jd; }
Example #7
Source File: TriggeredJobCompleteTest.java From quartz-redis-jobstore with Apache License 2.0 | 6 votes |
@Test public void triggeredJobCompleteNonConcurrent() throws JobPersistenceException { JobDetail job = JobBuilder.newJob(TestJobNonConcurrent.class) .withIdentity("testJobNonConcurrent1", "jobGroupNonConcurrent1") .usingJobData("timeout", 42) .withDescription("I am describing a job!") .build(); CronTriggerImpl trigger1 = getCronTrigger("triggerNonConcurrent1", "triggerNonConcurrentGroup1", job.getKey()); CronTriggerImpl trigger2 = getCronTrigger("triggerNonConcurrent2", "triggerNonConcurrentGroup1", job.getKey()); storeJobAndTriggers(job, trigger1, trigger2); jobStore.triggeredJobComplete(trigger1, job, Trigger.CompletedExecutionInstruction.SET_TRIGGER_COMPLETE); assertEquals(Trigger.TriggerState.COMPLETE, jobStore.getTriggerState(trigger1.getKey())); final String jobHashKey = schema.jobHashKey(job.getKey()); assertFalse(jedis.sismember(schema.blockedJobsSet(), jobHashKey)); }
Example #8
Source File: ReminderJob.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
public static JobDetail createDetails(MessageChannel channel, Member member, String message) { String userId; String guildId = null; if (channel instanceof PrivateChannel) { userId = ((PrivateChannel) channel).getUser().getId(); } else { guildId = member.getGuild().getId(); userId = member.getUser().getId(); } return JobBuilder .newJob(ReminderJob.class) .withIdentity(GROUP + " - " + UUID.randomUUID(), GROUP) .usingJobData(ATTR_GUILD_ID, guildId) .usingJobData(ATTR_USER_ID, userId) .usingJobData(ATTR_CHANNEL_ID, channel.getId()) .usingJobData(ATTR_MESSAGE, message) .build(); }
Example #9
Source File: QuartzManager.java From quartz-web with Apache License 2.0 | 6 votes |
public JobDetail updateStatefulMethodJob(String schedulerName, String jobName, String jobGroup, String jobClass, Object[] constructorArguments, String jobClassMethodName, Object[] jobClassMethodArgs, String description) throws SchedulerException { Assert.notNull(jobClass, "jobClass can not be null"); Assert.notEmpty(schedulerName, "schedulerName can not be empty"); Assert.notEmpty(jobName, "jobName can not be empty"); Assert.notEmpty(jobGroup, "jobGroup can not be empty"); Assert.notEmpty(jobClassMethodName, "jobClassMethodName can not be empty"); JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put("jobClass", jobClass); jobDataMap.put("constructorArguments", constructorArguments); jobDataMap.put("jobClassMethodName", jobClassMethodName); jobDataMap.put("jobClassMethodArgs", jobClassMethodArgs); JobDetail jobDetail = JobBuilder.newJob(StatefulMethodInvokeJob.class).withIdentity(jobName, jobGroup) .withDescription(description).setJobData(jobDataMap).storeDurably().build(); updateJob(schedulerName, jobDetail); return jobDetail; }
Example #10
Source File: QuartzManager.java From quartz-web with Apache License 2.0 | 6 votes |
public JobDetail addStatefulMethodJob(String schedulerName, String jobName, String jobGroup, String jobClass, Object[] constructorArguments, String jobClassMethodName, Object[] jobClassMethodArgs, String description) throws SchedulerException { Assert.notNull(jobClass, "jobClass can not be null"); Assert.notEmpty(schedulerName, "schedulerName can not be empty"); Assert.notEmpty(jobName, "jobName can not be empty"); Assert.notEmpty(jobGroup, "jobGroup can not be empty"); Assert.notEmpty(jobClassMethodName, "jobClassMethodName can not be empty"); JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put("jobClass", jobClass); jobDataMap.put("constructorArguments", constructorArguments); jobDataMap.put("jobClassMethodName", jobClassMethodName); jobDataMap.put("jobClassMethodArgs", jobClassMethodArgs); JobDetail jobDetail = JobBuilder.newJob(StatefulMethodInvokeJob.class).withIdentity(jobName, jobGroup) .withDescription(description).setJobData(jobDataMap).storeDurably().build(); addJob(schedulerName, jobDetail); return jobDetail; }
Example #11
Source File: ConfigScheduler.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 6 votes |
private synchronized void schedule() { try { scheduler = schedulerFactory.getScheduler(); JobDetail job = JobBuilder.newJob() .withIdentity(jobName) .ofType(ConfigSchedulerJob.class) .build(); jobKey = job.getKey(); job.getJobDataMap().put(CONFIG_SCHEDULER, this); CronExpression cronExpression = normalCronSchedule ? this.cronExpression : initialAndOnErrorCronExpression; CronTrigger trigger = TriggerBuilder.newTrigger() .withIdentity(jobName+"Trigger", Scheduler.DEFAULT_GROUP) .withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)) .build(); scheduler.startDelayed(0); scheduler.scheduleJob(job, trigger); log.debug("Schedule set "+cronExpression); } catch (Exception e) { log.error("Error scheduling "+e.getMessage()); } }
Example #12
Source File: JobScheduler.java From DataHubSystem with GNU Affero General Public License v3.0 | 6 votes |
@Override public void afterPropertiesSet () throws Exception { Map<String, AbstractJob> webappBeanNames = applicationContext.getBeansOfType (AbstractJob.class); triggers = new HashMap<> (); for (String webappBeanName : webappBeanNames.keySet ()) { AbstractJob cron = webappBeanNames.get (webappBeanName); CronTriggerFactoryBean trigger = new CronTriggerFactoryBean (); JobDetail job = JobBuilder.newJob (cron.getClass ()). storeDurably (true).build (); trigger.setJobDetail (job); trigger.setCronExpression (cron.getCronExpression ()); trigger.setName (webappBeanName + "Trigger"); trigger.afterPropertiesSet (); triggers.put (cron.getClass(), trigger.getObject ()); } super.setTriggers (triggers.values ().toArray ( new Trigger[triggers.size ()])); super.setJobFactory (autowiringJobFactory); super.afterPropertiesSet (); }
Example #13
Source File: JobStoreImplTest.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Test public void jobDataOnlySavedWhenDirty() throws Exception { JobDetail job = JobBuilder.newJob(MyJob.class).withIdentity("testJob").build(); OperableTrigger trigger = (OperableTrigger) TriggerBuilder.newTrigger().withIdentity("testJob").forJob(job).build(); jobStore.storeJobAndTrigger(job, trigger); int baseRecordVersion = queryJobDetail("testJob").getVersion(); // same job data after trigger fired... jobStore.triggersFired(Arrays.asList(trigger)); jobStore.triggeredJobComplete(trigger, job, CompletedExecutionInstruction.NOOP); // ...should not save the job assertThat(queryJobDetail("testJob").getVersion(), is(baseRecordVersion)); // different job data after trigger fired... jobStore.triggersFired(Arrays.asList(trigger)); job.getJobDataMap().put("testKey", "testValue"); jobStore.triggeredJobComplete(trigger, job, CompletedExecutionInstruction.NOOP); // ...should save the job assertThat(queryJobDetail("testJob").getVersion(), greaterThan(baseRecordVersion)); }
Example #14
Source File: AutoRun.java From sakai with Educational Community License v2.0 | 5 votes |
public void init() { if (config == null || serverConfigurationService.getBoolean(config, false)) { log.info("AutoRun running"); Scheduler scheduler = schedulerManager.getScheduler(); for (JobBeanWrapper job : startup) { try { JobDataMap jobData = new JobDataMap(); jobData.put(JobBeanWrapper.SPRING_BEAN_NAME, job.getBeanId()); jobData.put(JobBeanWrapper.JOB_NAME, job.getJobName()); JobDetail jobDetail = JobBuilder.newJob(job.getJobClass()) .withIdentity(job.getJobName(), null) .setJobData(jobData) .build(); // Non durable job that will get removed scheduler.addJob(jobDetail, true, true); scheduler.triggerJob(jobDetail.getKey()); log.info("Triggered job: {}", job.getJobName()); } catch (SchedulerException se) { log.warn("Failed to run job: {}", startup, se); } } } }
Example #15
Source File: QuartzManager.java From quartz-web with Apache License 2.0 | 5 votes |
public JobDetail updateStatefulMethodJob(String schedulerName, String jobName, String jobGroup, String description, MethodInvoker methodInvoker) throws SchedulerException { Assert.notNull(methodInvoker, "methodInvoker can not be null"); JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put("methodInvoker", methodInvoker); JobDetail jobDetail = JobBuilder.newJob(StatefulMethodInvokeJob.class).withIdentity(jobName, jobGroup) .withDescription(description).setJobData(jobDataMap).storeDurably().build(); updateJob(schedulerName, jobDetail); return jobDetail; }
Example #16
Source File: CalDavLoaderImpl.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
public void startLoading() { if (execService != null) { return; } log.trace("starting execution..."); int i = 0; for (final CalendarRuntime eventRuntime : EventStorage.getInstance().getEventCache().values()) { try { JobDetail job = JobBuilder.newJob().ofType(EventReloaderJob.class) .usingJobData(EventReloaderJob.KEY_CONFIG, eventRuntime.getConfig().getKey()) .withIdentity(eventRuntime.getConfig().getKey(), JOB_NAME_EVENT_RELOADER).storeDurably() .build(); this.scheduler.addJob(job, false); SimpleTrigger jobTrigger = TriggerBuilder.newTrigger().forJob(job) .withIdentity(eventRuntime.getConfig().getKey(), JOB_NAME_EVENT_RELOADER) .startAt(DateBuilder.futureDate(10 + i, IntervalUnit.SECOND)).withSchedule(SimpleScheduleBuilder .repeatMinutelyForever(eventRuntime.getConfig().getReloadMinutes())) .build(); this.scheduler.scheduleJob(jobTrigger); log.info("reload job scheduled for: {}", eventRuntime.getConfig().getKey()); } catch (SchedulerException e) { log.warn("Cannot schedule calendar reloader", e); } // next event 10 seconds later i += 10; } }
Example #17
Source File: PropTablesCleanupJobTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@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); }
Example #18
Source File: JobStoreImplTest.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Test public void testResetErrorTrigger() throws Exception { JobDetail jobDetail = JobBuilder.newJob(MyJob.class).withIdentity("job1", "jobGroup1").storeDurably(true).build(); this.jobStore.storeJob(jobDetail, false); Date baseFireTimeDate = DateBuilder.evenMinuteDateAfterNow(); long baseFireTime = baseFireTimeDate.getTime(); // create and store a trigger OperableTrigger trigger1 = new SimpleTriggerImpl("trigger1", "triggerGroup1", jobDetail.getKey().getName(), jobDetail.getKey().getGroup(), new Date(baseFireTime + 200000), new Date(baseFireTime + 200000), 2, 2000); trigger1.computeFirstFireTime(null); jobStore.storeTrigger(trigger1, false); long firstFireTime = new Date(trigger1.getNextFireTime().getTime()).getTime(); // pretend to fire it List<OperableTrigger> aqTs = jobStore.acquireNextTriggers( firstFireTime + 10000, 1, 0L); assertEquals(trigger1.getKey(), aqTs.get(0).getKey()); List<TriggerFiredResult> fTs = jobStore.triggersFired(aqTs); TriggerFiredResult ft = fTs.get(0); // get the trigger into error state jobStore.triggeredJobComplete(ft.getTriggerFiredBundle().getTrigger(), ft.getTriggerFiredBundle().getJobDetail(), Trigger.CompletedExecutionInstruction.SET_TRIGGER_ERROR); TriggerState state = jobStore.getTriggerState(trigger1.getKey()); assertEquals(TriggerState.ERROR, state); // test reset jobStore.resetTriggerFromErrorState(trigger1.getKey()); state = jobStore.getTriggerState(trigger1.getKey()); assertEquals(TriggerState.NORMAL, state); }
Example #19
Source File: TraceeJobListenerIT.java From tracee with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void traceeContextShouldBePropagatedToJobByDecoratedTrigger() throws SchedulerException { schedulerBackend.put("testKey", "testValue"); final JobDetail jobDetail = JobBuilder.newJob(TestJob.class).build(); final Trigger trigger = TriggerBuilder.newTrigger().forJob(jobDetail).startNow().build(); new TraceeContextInjector(schedulerBackend, Profile.DEFAULT).injectContext(trigger); scheduler.scheduleJob(jobDetail, trigger); verify(jobBackend, timeout(10000)).put(eq(TraceeConstants.INVOCATION_ID_KEY), any(String.class)); assertThat(jobBackend.getValuesBeforeLastClear(), hasEntry("testKey", "testValue")); }
Example #20
Source File: JobDetailImpl.java From lams with GNU General Public License v2.0 | 5 votes |
public JobBuilder getJobBuilder() { JobBuilder b = JobBuilder.newJob() .ofType(getJobClass()) .requestRecovery(requestsRecovery()) .storeDurably(isDurable()) .usingJobData(getJobDataMap()) .withDescription(getDescription()) .withIdentity(getKey()); return b; }
Example #21
Source File: SchedulerManager.java From sunbird-lms-service with MIT License | 5 votes |
private void scheduleUpdateUserCountJob(String identifier) { // add another job for updating user count to Location Table. // 1- create a job and bind with class which is implementing Job // interface. JobDetail updateUserCountJob = JobBuilder.newJob(UpdateUserCountScheduler.class) .requestRecovery(true) .withDescription("Scheduler for updating user count for each geo location") .withIdentity("updateUserCountScheduler", identifier) .build(); // 2- Create a trigger object that will define frequency of run. // This will run every day 2:00 AM Trigger updateUserCountTrigger = TriggerBuilder.newTrigger() .withIdentity("updateUserCountTrigger", identifier) .withSchedule( CronScheduleBuilder.cronSchedule( PropertiesCache.getInstance().getProperty("quartz_update_user_count_timer"))) .build(); try { if (scheduler.checkExists(updateUserCountJob.getKey())) { scheduler.deleteJob(updateUserCountJob.getKey()); } scheduler.scheduleJob(updateUserCountJob, updateUserCountTrigger); scheduler.start(); ProjectLogger.log( "SchedulerManager:scheduleUpdateUserCountJob: UpdateUserCount schedular started", LoggerEnum.INFO.name()); } catch (Exception e) { ProjectLogger.log(e.getMessage(), e); } }
Example #22
Source File: SakaiJob.java From sakai with Educational Community License v2.0 | 5 votes |
private JobDetail createJobDetail(JobBeanWrapper job, String jobName) { JobDetail jd = JobBuilder.newJob(job.getJobClass()).withIdentity(new JobKey(jobName, Scheduler.DEFAULT_GROUP)).storeDurably().requestRecovery().build(); JobDataMap map = jd.getJobDataMap(); map.put(JobBeanWrapper.SPRING_BEAN_NAME, job.getBeanId()); map.put(JobBeanWrapper.JOB_NAME, job.getJobName()); return jd; }
Example #23
Source File: Context.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public <T extends AbstractJob> void scheduleLocal(Class<T> cls, Integer delay) throws Exception { /* 需要单独生成一个独立任务,保证group和预约的任务不重复 */ JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put("context", this); JobDetail jobDetail = JobBuilder.newJob(cls).withIdentity(cls.getName(), clazz.getName()) .usingJobData(jobDataMap).withDescription(Config.node()).build(); /* 经过测试0代表不重复,仅运行一次 */ Trigger trigger = TriggerBuilder.newTrigger().withIdentity(cls.getName(), clazz.getName()) .withDescription("scheduleLocal").startAt(DateBuilder.futureDate(delay, IntervalUnit.SECOND)) .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(1).withRepeatCount(0)) .build(); scheduler.scheduleJob(jobDetail, trigger); }
Example #24
Source File: AbstractQuartzTaskManager.java From micro-integrator with Apache License 2.0 | 5 votes |
private synchronized void scheduleLocalTask(String taskName, boolean paused) throws TaskException { TaskInfo taskInfo = this.getTaskRepository().getTask(taskName); String taskGroup = this.getTenantTaskGroup(); if (taskInfo == null) { throw new TaskException("Non-existing task for scheduling with name: " + taskName, TaskException.Code.NO_TASK_EXISTS); } if (this.isPreviouslyScheduled(taskName, taskGroup)) { /* to make the scheduleLocalTask operation idempotent */ return; } Class<? extends Job> jobClass = taskInfo.getTriggerInfo().isDisallowConcurrentExecution() ? NonConcurrentTaskQuartzJobAdapter.class : TaskQuartzJobAdapter.class; JobDetail job = JobBuilder.newJob(jobClass).withIdentity(taskName, taskGroup).usingJobData( this.getJobDataMapFromTaskInfo(taskInfo)).build(); Trigger trigger = this.getTriggerFromInfo(taskName, taskGroup, taskInfo.getTriggerInfo()); try { this.getScheduler().scheduleJob(job, trigger); if (paused) { this.getScheduler().pauseJob(job.getKey()); } log.info("Task scheduled: [" + this.getTaskType() + "][" + taskName + "]" + (paused ? " [Paused]." : ".")); } catch (SchedulerException e) { throw new TaskException("Error in scheduling task with name: " + taskName, TaskException.Code.UNKNOWN, e); } }
Example #25
Source File: DaemonTaskScheduler.java From shardingsphere-elasticjob-cloud with Apache License 2.0 | 5 votes |
/** * Init the job. */ public void init() { JobDetail jobDetail = JobBuilder.newJob(DaemonJob.class).withIdentity(jobRootConfig.getTypeConfig().getCoreConfig().getJobName()).build(); jobDetail.getJobDataMap().put(ELASTIC_JOB_DATA_MAP_KEY, elasticJob); jobDetail.getJobDataMap().put(JOB_FACADE_DATA_MAP_KEY, jobFacade); jobDetail.getJobDataMap().put(EXECUTOR_DRIVER_DATA_MAP_KEY, executorDriver); jobDetail.getJobDataMap().put(TASK_ID_DATA_MAP_KEY, taskId); try { scheduleJob(initializeScheduler(), jobDetail, taskId.getValue(), jobRootConfig.getTypeConfig().getCoreConfig().getCron()); } catch (final SchedulerException ex) { throw new JobSystemException(ex); } }
Example #26
Source File: Context.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public <T extends AbstractJob> void fireScheduleOnLocal(Class<T> cls, Integer delay) throws Exception { /* 需要单独生成一个独立任务,保证group和预约的任务不重复 */ JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put("context", this); JobDetail jobDetail = JobBuilder.newJob(cls).withIdentity(cls.getName(), clazz.getName()) .usingJobData(jobDataMap).withDescription(Config.node()).build(); /* 经过测试0代表不重复,仅运行一次 */ Trigger trigger = TriggerBuilder.newTrigger().withIdentity(cls.getName(), clazz.getName()) .withDescription("schedule").startAt(DateBuilder.futureDate(delay, IntervalUnit.SECOND)) .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(1).withRepeatCount(0)) .build(); scheduler.scheduleJob(jobDetail, trigger); }
Example #27
Source File: FoxbpmJobDetail.java From FoxBPM with Apache License 2.0 | 5 votes |
public FoxbpmJobDetail(T foxbpmJob) { this.foxbpmJob = foxbpmJob; if (foxbpmJob instanceof FoxbpmScheduleJob) { this.jobDetail = JobBuilder.newJob(foxbpmJob.getClass()).withIdentity(((FoxbpmScheduleJob) foxbpmJob).getName(), ((FoxbpmScheduleJob) foxbpmJob).getGroupName()).build(); } else { throw new FoxBPMException("非 FoxbpmScheduleJob ,无法创建FoxbpmJobDetail!"); } }
Example #28
Source File: Context.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public <T extends AbstractJob> void scheduleLocal(Class<T> cls, String cron) throws Exception { JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put("context", this); JobDetail jobDetail = JobBuilder.newJob(cls).withIdentity(cls.getName(), clazz.getName()) .usingJobData(jobDataMap).withDescription(Config.node()).build(); Trigger trigger = TriggerBuilder.newTrigger().withIdentity(cls.getName(), clazz.getName()) .withDescription("scheduleLocal").withSchedule(CronScheduleBuilder.cronSchedule(cron)).build(); scheduler.scheduleJob(jobDetail, trigger); this.scheduleLocalRequestList.add(new ScheduleLocalRequest(jobDetail, cron, null, null)); }
Example #29
Source File: QuartzManager.java From quartz-web with Apache License 2.0 | 5 votes |
public JobDetail updateMethodInovkeJob(String schedulerName, String jobName, String jobGroup, String description, MethodInvoker methodInvoker) throws SchedulerException { Assert.notNull(methodInvoker, "methodInvoker can not be null"); Assert.notEmpty(schedulerName, "schedulerName can not be empty"); Assert.notEmpty(jobName, "jobName can not be empty"); Assert.notEmpty(jobGroup, "jobGroup can not be empty"); JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put("methodInvoker", methodInvoker); JobDetail jobDetail = JobBuilder.newJob(MethodInvokeJob.class).withIdentity(jobName, jobGroup) .withDescription(description).setJobData(jobDataMap).storeDurably().build(); updateJob(schedulerName, jobDetail); return jobDetail; }
Example #30
Source File: QuartzManager.java From quartz-web with Apache License 2.0 | 5 votes |
public JobDetail addStatefulMethodJob(String schedulerName, String jobName, String jobGroup, String description, MethodInvoker methodInvoker) throws SchedulerException { Assert.notNull(methodInvoker, "methodInvoker can not be null"); JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put("methodInvoker", methodInvoker); JobDetail jobDetail = JobBuilder.newJob(StatefulMethodInvokeJob.class).withIdentity(jobName, jobGroup) .withDescription(description).setJobData(jobDataMap).storeDurably().build(); addJob(schedulerName, jobDetail); return jobDetail; }