/** * Check that all properties are properly set */ public void init() throws SchedulerException { PropertyCheck.mandatory(this, "scheduler", scheduler); PropertyCheck.mandatory(this, "transactionService", transactionService); PropertyCheck.mandatory(this, "repoUsageComponent", repoUsageComponent); PropertyCheck.mandatory(this, "jobLockService", jobLockService); // Trigger the scheduled updates final JobDetail jobDetail = new JobDetail("rmj", Scheduler.DEFAULT_GROUP, RepoUsageMonitorJob.class); jobDetail.getJobDataMap().put("RepoUsageMonitor", this); final Trigger trigger = TriggerUtils.makeHourlyTrigger(12); // every 12 hours trigger.setStartTime(new Date(System.currentTimeMillis() + 60L * 60L * 1000L)); // one hour from now trigger.setName("rmt"); trigger.setGroup(Scheduler.DEFAULT_GROUP); repoUsageComponent.observeRestrictions(this); // Unschedule in case it was scheduled in an earlier retry of the transaction scheduler.unscheduleJob("rmt", Scheduler.DEFAULT_GROUP); scheduler.scheduleJob(jobDetail, trigger); }
private static final Trigger makeIntervalTrigger(String type, String interval, String repititions) throws ParseException { try { final int i = Integer.parseInt(interval); int r = SimpleTrigger.REPEAT_INDEFINITELY; if (!repititions.trim().equals("")) { r = Integer.parseInt(repititions); } if (type.equals(FREQUENCY_SECONDLY)) { return TriggerUtils.makeSecondlyTrigger(i, r); } else if (type.equals(FREQUENCY_MINUTELY)) { return TriggerUtils.makeMinutelyTrigger(i, r); } else if (type.equals(FREQUENCY_HOURLY)) { return TriggerUtils.makeHourlyTrigger(i, r); } return null; } catch (final NumberFormatException e) { throw new ParseException("Invalid interval or repitition value.", -1); } }
@Override public void immediately(Job job) { logger.debug("Scheduling immediate job: " + job.getName()); String jobId = "Schedule-" + job.getName() + "-" + job.getId() + "-" + Calendar.getInstance().getTimeInMillis(); JobDetail jobDetail = new JobDetail( jobId, JobExecutor.class); logger.debug("Configuring Scheduler Job with id: "+jobId); //Trigger fires as quick as possible //first argument 0 : no repeats //second argument is the interval between repeats, but irrelevant here Trigger trigger = TriggerUtils.makeImmediateTrigger(0, 1000); trigger.setName("Immediate trigger - " + jobId); trigger.setGroup("JobScheduleGroup"); JobDataMap jobData = createJobDataMap(job.getId()); trigger.setJobDataMap(jobData); try { scheduler.scheduleJob(jobDetail, trigger); logger.debug("Trigger for immediate run fired!"); } catch (SchedulerException e) { logger.error("Scheduling immediate job \"" + job.getName() + "\" failed"); e.printStackTrace(); } }
public String execute() throws Exception { log.debug("re index users called"); //create the job detail JobDetail jobDetail = new JobDetail("reIndexUsersJob", Scheduler.DEFAULT_GROUP, edu.ur.ir.user.service.DefaultReIndexUsersJob.class); jobDetail.getJobDataMap().put("batchSize", Integer.valueOf(batchSize)); //create a trigger that fires once right away Trigger trigger = TriggerUtils.makeImmediateTrigger(0,0); trigger.setName("SingleReIndexUsersJobFireNow"); quartzScheduler.scheduleJob(jobDetail, trigger); return SUCCESS; }
public String execute() throws Exception { log.debug("re index users called"); //create the job detail JobDetail jobDetail = new JobDetail("reIndexUserGroupsJob", Scheduler.DEFAULT_GROUP, edu.ur.ir.user.service.DefaultReIndexUserGroupsJob.class); jobDetail.getJobDataMap().put("batchSize", Integer.valueOf(batchSize)); //create a trigger that fires once right away Trigger trigger = TriggerUtils.makeImmediateTrigger(0,0); trigger.setName("SingleReIndexUserGroupsJobFireNow"); quartzScheduler.scheduleJob(jobDetail, trigger); return SUCCESS; }
public String execute() throws Exception { log.debug("re index users called"); //create the job detail JobDetail jobDetail = new JobDetail("reIndexResearchersJob", Scheduler.DEFAULT_GROUP, edu.ur.ir.researcher.service.DefaultReIndexResearchersJob.class); jobDetail.getJobDataMap().put("batchSize", Integer.valueOf(batchSize)); //create a trigger that fires once right away Trigger trigger = TriggerUtils.makeImmediateTrigger(0,0); trigger.setName("SingleReIndexResearchersJobFireNow"); quartzScheduler.scheduleJob(jobDetail, trigger); return SUCCESS; }
/** * Sets the re * @return * @throws SchedulerException */ public String runFileDownloadUpdateProcessing() throws SchedulerException { log.debug("Setting up job to be fired for updateing stats"); //create the job detail JobDetail jobDetail = new JobDetail("reCountFileDownloadsJob", Scheduler.DEFAULT_GROUP, edu.ur.ir.statistics.service.DefaultFileDownloadStatsUpdateJob.class); jobDetail.getJobDataMap().put("batchSize", new Integer(1000)); //create a trigger that fires once right away Trigger trigger = TriggerUtils.makeImmediateTrigger(0,0); trigger.setName("singleReCountDownlodsJobFireNow"); quartzScheduler.scheduleJob(jobDetail, trigger); return SUCCESS; }
public String execute() throws Exception { log.debug("re index person names called"); //create the job detail JobDetail jobDetail = new JobDetail("reIndexPersonNameAuthoritiesJob", Scheduler.DEFAULT_GROUP, edu.ur.ir.person.service.DefaultReIndexPersonNameAuthoritiesJob.class); jobDetail.getJobDataMap().put("batchSize", Integer.valueOf(batchSize)); //create a trigger that fires once right away Trigger trigger = TriggerUtils.makeImmediateTrigger(0,0); trigger.setName("SingleReIndexPersonNameAuthoritiesJobFireNow"); quartzScheduler.scheduleJob(jobDetail, trigger); return SUCCESS; }
@Override public List<DateTime> getScheduledJobTimingsWithPrefix( String subject, String externalJobIdPrefix, DateTime startDate, DateTime endDate) { JobId jobId = new CronJobId(subject, externalJobIdPrefix); List<Date> messageTimings = new ArrayList<>(); try { List<TriggerKey> triggerKeys = new ArrayList<TriggerKey>( scheduler.getTriggerKeys(GroupMatcher.triggerGroupContains(JOB_GROUP_NAME))); for (TriggerKey triggerKey : triggerKeys) { if (StringUtils.isNotEmpty(externalJobIdPrefix) && triggerKey.getName().contains(jobId.value())) { Trigger trigger = scheduler.getTrigger(triggerKey); messageTimings.addAll(TriggerUtils.computeFireTimesBetween( (OperableTrigger) trigger, new BaseCalendar(), DateUtil.toDate(startDate), DateUtil.toDate(endDate))); } } } catch (SchedulerException e) { throw new MotechSchedulerException(String.format( "Can not get scheduled job timings given subject and externalJobIdPrefix for dates : %s %s %s %s %s", subject, externalJobIdPrefix, startDate.toString(), endDate.toString(), e.getMessage()), e); } return DateUtil.datesToDateTimes(messageTimings); }
/** * Runs the passed Task immediately, regardless of any schedule settings. * * @param task Task to run. */ public void runTaskNow(Task task) { JobDetail jobDetail = createJobDetail(task); // modify group name otherwise this has potential to clash with other scheduled run of this job jobDetail.setGroup(jobDetail.getGroup() + SUFFIX_IMMEDIATE); Trigger trigger = TriggerUtils.makeImmediateTrigger(String.valueOf(task.getId()), 0, 1); log.info("Scheduling task with id " + task.getId() + " to run now"); try { scheduler.scheduleJob(jobDetail, trigger); } catch (SchedulerException e) { throw new ScheduleException("Error scheduling task with id " + task.getId(), e); } }
public String execute() throws Exception { log.debug("re index users called"); //create the job detail JobDetail jobDetail = new JobDetail("fixPublisherInfoJob", Scheduler.DEFAULT_GROUP, edu.ur.ir.util.service.PublisherToLocationCorrectorJob.class); //create a trigger that fires once right away Trigger trigger = TriggerUtils.makeImmediateTrigger(0,0); trigger.setName("SingleFixPublisherInfoJobFireNow"); quartzScheduler.scheduleJob(jobDetail, trigger); return SUCCESS; }
public String execute() throws Exception { log.debug("re institutional collections called"); //create the job detail JobDetail jobDetail = new JobDetail("reIndexInstitutionalCollectionsJob", Scheduler.DEFAULT_GROUP, edu.ur.ir.institution.service.InstitutionalCollectionIndexProcessingJob.class); //create a trigger that fires once right away Trigger trigger = TriggerUtils.makeImmediateTrigger(0,0); trigger.setName("SingleReIndexPersonNameAuthoritiesJobFireNow"); quartzScheduler.scheduleJob(jobDetail, trigger); return SUCCESS; }
@Override public List<DateTime> getScheduledJobTimings(String subject, String externalJobId, DateTime startDate, DateTime endDate) { JobId jobId = new CronJobId(subject, externalJobId); Trigger trigger; try { trigger = scheduler.getTrigger(triggerKey(jobId.value(), JOB_GROUP_NAME)); return DateUtil.datesToDateTimes(TriggerUtils.computeFireTimesBetween( (OperableTrigger) trigger, new BaseCalendar(), DateUtil.toDate(startDate), DateUtil.toDate(endDate))); } catch (SchedulerException e) { throw new MotechSchedulerException(String.format( "Can not get scheduled job timings given subject and externalJobId for dates : %s %s %s %s %s", subject, externalJobId, startDate.toString(), endDate.toString(), e.getMessage()), e); } }
private Trigger buildJobDetail(SchedulableJob schedulableJob, Date jobStartTime, Date jobEndTime, JobId jobId, JobDetail jobDetail, ScheduleBuilder scheduleBuilder) { Trigger trigger = newTrigger() .withIdentity(triggerKey(jobId.value(), JOB_GROUP_NAME)) .forJob(jobDetail) .withSchedule(scheduleBuilder) .startAt(jobStartTime) .endAt(jobEndTime) .build(); DateTime now = now(); if (schedulableJob.isIgnorePastFiresAtStart() && newDateTime(jobStartTime).isBefore(now)) { List<Date> pastTriggers = TriggerUtils.computeFireTimesBetween((OperableTrigger) trigger, null, jobStartTime, now.toDate()); if (pastTriggers.size() > 0) { if (scheduleBuilder instanceof SimpleScheduleBuilder && ((RepeatingSchedulableJob) schedulableJob).getRepeatCount() != null) { ((SimpleScheduleBuilder) scheduleBuilder) .withRepeatCount(((RepeatingSchedulableJob) schedulableJob).getRepeatCount() - pastTriggers.size()); } Date newStartTime = getFirstTriggerInFuture(trigger, now); trigger = newTrigger() .withIdentity(triggerKey(jobId.value(), JOB_GROUP_NAME)) .forJob(jobDetail) .withSchedule(scheduleBuilder) .startAt(newStartTime) .endAt(jobEndTime) .build(); } } return trigger; }
private String getJobInfo(Trigger trigger, String jobType) throws SchedulerException { if (jobType.equals(JobBasicInfo.JOBTYPE_REPEATING)) { Integer timesTriggered = 0; String repeatMaxCount = "-"; if (trigger instanceof CalendarIntervalTrigger) { CalendarIntervalTrigger calendarIntervalTrigger = (CalendarIntervalTrigger) trigger; timesTriggered = calendarIntervalTrigger.getTimesTriggered(); } else if (trigger instanceof SimpleTrigger) { SimpleTrigger simpleTrigger = (SimpleTrigger) trigger; timesTriggered = simpleTrigger.getTimesTriggered(); } if (trigger.getEndTime() != null) { repeatMaxCount = Integer.toString(TriggerUtils.computeFireTimesBetween( (OperableTrigger) trigger, null, trigger.getStartTime(), trigger.getEndTime() ).size() + timesTriggered); } return String.format("%d/%s", timesTriggered, repeatMaxCount); } else if (jobType.equals(JobBasicInfo.JOBTYPE_CRON)) { CronScheduleBuilder cronScheduleBuilder = (CronScheduleBuilder) trigger.getScheduleBuilder(); CronTrigger cronTrigger = (CronTrigger) cronScheduleBuilder.build(); return cronTrigger.getCronExpression(); } else { return "-"; } }
private void generateJob() throws SchedulerException{ //request.setAttribute("queryName",RembrandtConstants.PREVIEW_RESULTS); // Figure out the state of the form Date now = new Date(); // Schedule the job for immediate execution and only once JobDetail jobDetail = null; Trigger trigger = TriggerUtils.makeImmediateTrigger(0, 0); if (email != null && taskId != null && sessionId != null){ // If the query was association then setup the association job if (email != null && email.length()>0) { jobDetail = new JobDetail("generateReportJob" + email + now, null, GenerateReportJob.class); // Trigger name must be unique so include type and email trigger.setName("immediateTriggerReportJob" + email + now); } // Add the form and email address to the job details if (jobDetail != null) { jobDetail.getJobDataMap().put("email", email); /*if(userName == null || userName.equals("RBTuser")){ //if its a guest user than use the email user name String [] temp = email.split("@"); userName = temp[0]; }*/ jobDetail.getJobDataMap().put("taskId", taskId); jobDetail.getJobDataMap().put("userName", userName); jobDetail.getJobDataMap().put("sessionId", sessionId); } if (jobDetail != null) StatisticsInfoPlugIn.scheduleWork(jobDetail, trigger); } }
/** * The scheduleWork task is called within the application to actually * schedule a job for later execution. * <P> * @param jobDetail The details of the job to schedule * @param trigger The trigger conditions to use for scheduling * @throws SchedulerException */ //public static void scheduleWork(JobDetail jobDetail, Trigger trigger) public static void scheduleWork(int schedulerType, ServletContext context) throws SchedulerException { if (sm_scheduler == null){ StatisticsInfoPlugIn.startScheduler(context); Trigger trigger = null; if (schedulerType == 1) trigger = TriggerUtils.makeDailyTrigger("rembrandtDailyTrigger", 0, 0); else if (schedulerType == 2) trigger = TriggerUtils.makeWeeklyTrigger("rembrandtWeeklyTrigger", 1, 0, 0); JobDetail rembrandtstatisticsInfoJob = new JobDetail("rembrandtstatisticsInfoJob", null, StatisticsInfoJob.class); JobDetail deleteOldResultsFilesJob = new JobDetail("DeleteOldResultsFilesJob", null, DeleteOldFilesJob.class); // Trigger name must be unique so include type and email // Add the form and email address to the job details if (deleteOldResultsFilesJob != null) { String dirPath = System.getProperty("gov.nih.nci.rembrandt.data_directory"); String fileRetentionPeriodInDays = MailConfig.getInstance(ApplicationContext.GOV_NIH_NCI_REMBRANDT_PROPERTIES).getFileRetentionPeriodInDays(); if(fileRetentionPeriodInDays == null){ fileRetentionPeriodInDays = "5"; } deleteOldResultsFilesJob.getJobDataMap().put("dirPath", dirPath); deleteOldResultsFilesJob.getJobDataMap().put("fileRetentionPeriodInDays", fileRetentionPeriodInDays); } sm_scheduler.scheduleJob(rembrandtstatisticsInfoJob, trigger); sm_scheduler.scheduleJob(deleteOldResultsFilesJob, TriggerUtils.makeDailyTrigger("DeleteOldResultsFilesJob", 0, 0)); //run it daily at midnight logger.info("Scheduler started......"); } }
@Inject public GlobalExportJobActivator(final QuartzScheduler quartz, Provider<EntityManager> entityManagerProvider, final Injector injector) { LOG.debug("**************** STARTING JOBS *****************"); this.entityManagerProvider = entityManagerProvider; try { /** * Schedule auto exports */ final JobDetail exportJobDetail = new JobDetail("autoExportJob", null, AutoExportJob.class); exportJobDetail.getJobDataMap().put("em", this.entityManagerProvider.get()); exportJobDetail.getJobDataMap().put("injector", injector); // Trigger exportTrigger = TriggerUtils.makeSecondlyTrigger(120); // test fire every 5sec Trigger exportTrigger = TriggerUtils.makeDailyTrigger(0, 0); // Fire every day at midnight exportTrigger.setName("autoExportTrigger"); // start next day at midnight final Calendar exportCalendar = Calendar.getInstance(); exportCalendar.add(Calendar.DAY_OF_MONTH, 1); exportTrigger.setStartTime(AutoExportJob.getZeroTimeDate(exportCalendar.getTime())); quartz.getScheduler().scheduleJob(exportJobDetail, exportTrigger); LOG.info("AutoExportJob job scheduled for EVERY DAY at MIDNIGHT "); /** * Schedule auto delete */ final JobDetail deleteJobDetail = new JobDetail("autoDeleteJob", null, AutoDeleteJob.class); deleteJobDetail.getJobDataMap().put("em", this.entityManagerProvider.get()); deleteJobDetail.getJobDataMap().put("injector", injector); // Trigger deleteTrigger = TriggerUtils.makeSecondlyTrigger(60, 0); // test // fire every 25th of the month at 01:00 Trigger deleteTrigger = TriggerUtils.makeMonthlyTrigger(25, 1, 0); deleteTrigger.setName("autoDeleteTrigger"); // start next day at 01:00 final Calendar deleteCalendar = Calendar.getInstance(); deleteCalendar.add(Calendar.DAY_OF_MONTH, 1); deleteCalendar.setTime(AutoExportJob.getZeroTimeDate(deleteCalendar.getTime())); deleteCalendar.add(Calendar.HOUR_OF_DAY, 1); deleteTrigger.setStartTime(deleteCalendar.getTime()); quartz.getScheduler().scheduleJob(deleteJobDetail, deleteTrigger); LOG.info("AutoDeleteJob job scheduled for EVERY 25th day of the MONTH at 01:00 "); } catch (Exception e) { LOG.error("Scheduling failed"); e.printStackTrace(); } }
public static Trigger createImmediateTrigger(String name){ return TriggerUtils.makeImmediateTrigger(name, 0, 1); }
public void run() throws Exception { Logger log = Logger.getLogger(SimpleExample.class); log.info("------- Initializing ----------------------"); // First we must get a reference to a scheduler SchedulerFactory sf = new StdSchedulerFactory(); Scheduler sched = sf.getScheduler(); log.info("------- Initialization Complete -----------"); log.info("------- Scheduling Jobs -------------------"); // computer a time that is on the next round minute Date runTime = TriggerUtils.getEvenMinuteDate(new Date()); // define the job and tie it to our HelloJob class JobDetail job = new JobDetail("job1", "group1", HelloJob.class); JobDetail job1 = new JobDetail("job2", "group1", HelloJob.class); // Trigger the job to run on the next round minute Trigger trigger = TriggerUtils.makeSecondlyTrigger(); trigger.setName("trigger"); Trigger trigger1 = TriggerUtils.makeSecondlyTrigger(); trigger1.setName("trigger1"); // new SimpleTrigger("trigger1", "group1", runTime); // Tell quartz to schedule the job using our trigger sched.scheduleJob(job, trigger); sched.scheduleJob(job1,trigger1); log.info(job.getFullName() + " will run at: " + runTime); // Start up the scheduler (nothing can actually run until the // scheduler has been started) sched.start(); log.info("------- Started Scheduler -----------------"); // wait long enough so that the scheduler as an opportunity to // run the job! log.info("------- Waiting 90 seconds... -------------"); try { // wait 90 seconds to show jobs Thread.sleep(90L * 1000L); // executing... } catch (Exception e) { } // shut down the scheduler log.info("------- Shutting Down ---------------------"); sched.shutdown(true); log.info("------- Shutdown Complete -----------------"); }