MotechSchedulerService

public interface MotechSchedulerService

ingroup scheduler Motech Scheduler Service Interface provides methods to schedule reschedule and unschedule a job Set a global policy that determines trigger fire behaviour for misfired triggers. For details see quartz documentations for misfire policy do_nothing -> @see CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING fire_once_now -> @see CronTrigger.MISFIRE_INSTRUCTION_FIRE_ONCE_NOW ignore -> @see CronTrigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY fire_now -> @see SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW ignore -> @see SimpleTrigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY reschedule_next_with_existing_count -> @see SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT reschedule_next_with_remaining_count -> @see SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT reschedule_now_with_existing_count -> @see SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT reschedule_now_with_remaining_count -> @see SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT

Author:Igor (iopushnyev@2paths.com) Date: 16/02/11

Fields

JOB_ID_KEY

String JOB_ID_KEY

Methods

deleteJob

void deleteJob(JobBasicInfo info)

Deletes the job based on the given info.

Parameters:
  • info – the information about a job

getJob

SchedulableJob getJob(JobBasicInfo jobInfo)

Retrieves a job based on the given information.

Parameters:
  • jobInfo – the information about a job
Returns:

the job matching the given information

getNextFireDate

DateTime getNextFireDate(JobId jobId)

Returns next fire date of job with given ID.

Parameters:
  • jobId – the JobId of job, not null
Returns:

next fire date of job

getPreviousFireDate

DateTime getPreviousFireDate(JobId jobId)

Returns last fire date of job with given ID.

Parameters:
  • jobId – the JobId of job, not null
Returns:

last fire date of job

getScheduledJobTimings

List<DateTime> getScheduledJobTimings(String subject, String externalJobId, DateTime startDate, DateTime endDate)

Returns list of dates at which job will be triggered.

Parameters:
  • subject – the subject of job, not null
  • externalJobId – the external ID of job, not null
  • startDate – the Date after which dates should be added, not null
  • endDate – the Date before which dates should be added, not null
Returns:

the list of dates, null if exception was thrown

getScheduledJobTimingsWithPrefix

List<DateTime> getScheduledJobTimingsWithPrefix(String subject, String externalJobIdPrefix, DateTime startDate, DateTime endDate)

Returns list of dates at which jobs will be triggered.

Parameters:
  • subject – the subject of job, not null
  • externalJobIdPrefix – the prefix of jobs
  • startDate – the Date after which dates should be added, not null
  • endDate – the Date before which dates should be added, not null
Returns:

the list of dates

pauseJob

JobBasicInfo pauseJob(JobBasicInfo info)

Pauses the job based on the given info.

Parameters:
  • info – the information about a job
Returns:

the updated job

rescheduleJob

void rescheduleJob(String subject, String externalId, String cronExpression)

Reschedules a job with the given job ID to be fired according to the given Cron Expression Previous version of the configured Motech Scheduled Event that will be created when the job is fired remains as it was

Parameters:
  • subject – the subject of job, not null
  • externalId – the external ID of job, not null
  • cronExpression – cron expressions for job

resumeJob

JobBasicInfo resumeJob(JobBasicInfo info)

Resumes the job based on the given info.

Parameters:
  • info – the information about a job
Returns:

the updated job

safeScheduleJob

void safeScheduleJob(CronSchedulableJob cronSchedulableJob)

Same as scheduleJob, except that it would update existing job if one exists instead of creating a new one

Parameters:
  • cronSchedulableJob – a job that can be fired unlimited number of times

safeScheduleRepeatingJob

void safeScheduleRepeatingJob(RepeatingSchedulableJob repeatingSchedulableJob)

Same as safeScheduleRepeatingJob with intervening = true

Parameters:
  • repeatingSchedulableJob – a scheduled job that can be fired set number of times

safeScheduleRepeatingPeriodJob

void safeScheduleRepeatingPeriodJob(RepeatingPeriodSchedulableJob repeatingPeriodSchedulableJob)

Same as scheduleRepeatingPeriodJob, except that it would update existing job if one exists instead of creating a new one

Parameters:

safeScheduleRunOnceJob

void safeScheduleRunOnceJob(RunOnceSchedulableJob schedulableJob)

Same as scheduleRunOnceJob, except that it would update existing job if one exists instead of creating a new one

Parameters:
  • schedulableJob – ob scheduled in the future that can be fired only once

safeUnscheduleAllJobs

void safeUnscheduleAllJobs(String jobIdPrefix)

Unschedules all jobs with given prefix. Logs all exceptions instead of throwing them.

Parameters:
  • jobIdPrefix – the jobs prefix

safeUnscheduleJob

void safeUnscheduleJob(String subject, String externalId)

Same as unscheduleJob except that it would not throw an exception if the job doesn’t exist

Parameters:
  • subject – the subject of job, not null
  • externalId – the external ID of job, not null

safeUnscheduleRepeatingJob

void safeUnscheduleRepeatingJob(String subject, String externalId)

Same as unscheduleRepeatingJob except that it would not throw an exception if the job doesn’t exist

Parameters:
  • subject – the subject of job, not null
  • externalId – the external ID of job, not null

safeUnscheduleRunOnceJob

void safeUnscheduleRunOnceJob(String subject, String externalId)

Same as unscheduleRunOnceJob except that it would not throw an exception if the job doesn’t exist

Parameters:
  • subject – the subject of job, not null
  • externalId – the external ID of job, not null

scheduleDayOfWeekJob

void scheduleDayOfWeekJob(DayOfWeekSchedulableJob dayOfWeekSchedulableJob)

Same as safeScheduleDayOfWeekJob with intervening = true

Parameters:
  • dayOfWeekSchedulableJob – a job that is scheduled on particular days of week

scheduleJob

void scheduleJob(SchedulableJob job)

Schedules the given schedulable job.

Parameters:
  • job – the SchedulableJob

scheduleJob

void scheduleJob(CronSchedulableJob cronSchedulableJob)

Schedules the given cron schedulable job. The Job ID by which the job will be referencing in the future should be provided in an Instance of MotechEvent in SchedulableJob If a job with the same JobID as the given exists, this job will be unscheduled and the given schedulable job will be scheduled

Parameters:
  • cronSchedulableJob – a job that can be fired unlimited number of times

scheduleRepeatingJob

void scheduleRepeatingJob(RepeatingSchedulableJob repeatingSchedulableJob)

Schedules the given schedulable job. The Job ID by which the job will be referencing in the future should be provided in an Instance of MotechEvent in SchedulableJob (see JobID in MotechEvent parameters map ) If a job with the same job ID as the given exists, this job will be unscheduled and the given schedulable job will be scheduled

Parameters:
  • repeatingSchedulableJob – a scheduled job that can be fired set number of times

scheduleRepeatingPeriodJob

void scheduleRepeatingPeriodJob(RepeatingPeriodSchedulableJob repeatingPeriodSchedulableJob)

Same as scheduleRepeatingJob but schedules RepeatingPeriodSchedulableJob

Parameters:

scheduleRunOnceJob

void scheduleRunOnceJob(RunOnceSchedulableJob schedulableJob)

Schedules RunOnceSchedulableJob.

Parameters:
  • schedulableJob – the RunOnceSchedulableJob to be scheduled, not null

unscheduleAllJobs

void unscheduleAllJobs(String jobIdPrefix)

Unschedules all jobs with given prefix.

Parameters:
  • jobIdPrefix – the jobs prefix

unscheduleJob

void unscheduleJob(String subject, String externalId)

Unschedules a job with the given job ID

Parameters:
  • subject – String representing domain operation eg. “pill-reminder”, “outbox-call” or motechEvent.getSubject()
  • externalId – domain specific id as String.

unscheduleJob

void unscheduleJob(JobId job)

Unschedules job with given job ID.

Parameters:
  • job – the JobId of job which should be unscheduled, not null

unscheduleRepeatingJob

void unscheduleRepeatingJob(String subject, String externalId)

Unschedules RepeatingSchedulableJob with given subject and external ID.

Parameters:
  • subject – the subject of job, not null
  • externalId – the external ID of job, not null

unscheduleRunOnceJob

void unscheduleRunOnceJob(String subject, String externalId)

Unschedules a run once job with the given job ID

Parameters:
  • subject – String representing domain operation eg. “pill-reminder”, “outbox-call” or motechEvent.getSubject()
  • externalId – domain specific id as String.

updateJob

void updateJob(SchedulableJob job)

Updates the job with jobID matching the key of the given JobID in MotechEvent.parameters map.

Parameters:
  • job – the updated job