use of org.motechproject.scheduler.contract.CronSchedulableJob in project motech by motech.
the class TestEventListener method shouldUnscheduleJob.
@Test
public void shouldUnscheduleJob() throws SchedulerException {
Map<String, Object> params = new HashMap<>();
final String jobId = id("jobId");
params.put(MotechSchedulerService.JOB_ID_KEY, jobId);
schedulerService.scheduleJob(new CronSchedulableJob(new MotechEvent("test_event", params), "0 0 12 * * ?"));
schedulerService.unscheduleJob("test_event", jobId);
assertNull(scheduler.getTrigger(triggerKey("test_event-" + jobId, "default")));
}
use of org.motechproject.scheduler.contract.CronSchedulableJob in project motech by motech.
the class TestEventListener method shouldNotDeleteJobIfItIsNotUiDefined.
@Test(expected = MotechSchedulerException.class)
public void shouldNotDeleteJobIfItIsNotUiDefined() throws Exception {
try {
Map<String, Object> params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
JobBasicInfo info = new JobBasicInfo(JobBasicInfo.ACTIVITY_ACTIVE, JobBasicInfo.STATUS_OK, "test_event-job_id", "default", "start-time", "nex-fire-time", "end-time", JobBasicInfo.JOBTYPE_CRON, "test-info", true);
schedulerService.scheduleJob(new CronSchedulableJob(new MotechEvent("test_event", params), "0 0 12 * * ?"));
schedulerService.deleteJob(info);
} finally {
assertNotNull(scheduler.getTrigger(triggerKey("test_event-job_id", "default")));
}
}
use of org.motechproject.scheduler.contract.CronSchedulableJob in project motech by motech.
the class MotechSchedulerDatabaseServiceImplBundleIT method addTestJobs.
private void addTestJobs() {
Map<String, Object> params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id1");
// this job should be active
schedulerService.scheduleDayOfWeekJob(new DayOfWeekSchedulableJob(new MotechEvent("test_event_1", params), new DateTime(CURRENT_YEAR - 1, 3, 10, 0, 0), new DateTime(CURRENT_YEAR + 2, 3, 22, 0, 0), Arrays.asList(DayOfWeek.Monday, DayOfWeek.Thursday), new Time(10, 10), false));
params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id2");
schedulerService.scheduleDayOfWeekJob(new DayOfWeekSchedulableJob(new MotechEvent("test_event_2", params), new DateTime(CURRENT_YEAR + 1, 7, 10, 0, 0), new DateTime(CURRENT_YEAR + 3, 7, 22, 0, 0), Arrays.asList(DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday), new Time(10, 10), false));
params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id3");
schedulerService.scheduleDayOfWeekJob(new DayOfWeekSchedulableJob(new MotechEvent("test_event_3", params), new DateTime(CURRENT_YEAR + 4, 7, 10, 0, 0), new DateTime(CURRENT_YEAR + 5, 7, 22, 0, 0), Arrays.asList(DayOfWeek.Monday, DayOfWeek.Thursday), new Time(10, 10), false));
params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id4");
schedulerService.scheduleJob(new CronSchedulableJob(new MotechEvent("test_event_4", params), "0 0 12 * * ?"));
params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id5");
schedulerService.scheduleRunOnceJob(new RunOnceSchedulableJob(new MotechEvent("test_event_5", params), newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0)));
params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id6");
schedulerService.scheduleRepeatingJob(new RepeatingSchedulableJob(new MotechEvent("test_event_6", params), DateTimeConstants.SECONDS_PER_DAY, newDateTime(CURRENT_YEAR + 4, 7, 15, 12, 0, 0), newDateTime(CURRENT_YEAR + 4, 7, 18, 12, 0, 0), false));
}
use of org.motechproject.scheduler.contract.CronSchedulableJob in project motech by motech.
the class MotechSchedulerDatabaseServiceImplBundleIT method shouldGetScheduledJobsBasicInfoWithSortingAndPagination.
@Test
public void shouldGetScheduledJobsBasicInfoWithSortingAndPagination() throws SchedulerException, SQLException {
try {
fakeNow(newDateTime(CURRENT_YEAR + 6, 7, 15, 10, 0, 0));
Map<String, Object> params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
schedulerService.scheduleJob(new CronSchedulableJob(new MotechEvent("test_event_2a", params), "0 0 12 * * ?"));
schedulerService.scheduleRunOnceJob(new RunOnceSchedulableJob(new MotechEvent("test_event_2b", params), newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0)));
schedulerService.scheduleRepeatingJob(new RepeatingSchedulableJob(new MotechEvent("test_event_2c", params), DateTimeConstants.SECONDS_PER_DAY, newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0), newDateTime(CURRENT_YEAR + 6, 7, 18, 12, 0, 0), false));
JobBasicInfo expected = new JobBasicInfo(JobBasicInfo.ACTIVITY_NOTSTARTED, JobBasicInfo.STATUS_OK, "test_event_2a-job_id", DEFAULT_GROUP, format("%s-07-15 10:00:00", CURRENT_YEAR + 6), format("%s-07-15 12:00:00", CURRENT_YEAR + 6), "-", JobBasicInfo.JOBTYPE_CRON, "", false);
List<JobBasicInfo> jobBasicInfos;
JobsSearchSettings jobsSearchSettings = getGridSettings(2, 2, "name", "desc");
jobBasicInfos = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
assertEquals(expected.getActivity(), jobBasicInfos.get(0).getActivity());
assertEquals(expected.getStatus(), jobBasicInfos.get(0).getStatus());
assertEquals(expected.getStartDate(), jobBasicInfos.get(0).getStartDate());
assertEquals(expected.getNextFireDate(), jobBasicInfos.get(0).getNextFireDate());
} finally {
stopFakingTime();
}
}
use of org.motechproject.scheduler.contract.CronSchedulableJob in project motech by motech.
the class MotechSchedulerDatabaseServiceImplBundleIT method shouldGetJobTimes.
@Test
public void shouldGetJobTimes() {
try {
fakeNow(newDateTime(CURRENT_YEAR + 6, 7, 15, 10, 0, 0));
Map<String, Object> params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
schedulerService.scheduleJob(new CronSchedulableJob(new MotechEvent("test_event", params), "0 0 12 * * ?"));
List<DateTime> eventTimes = schedulerService.getScheduledJobTimings("test_event", "job_id", newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0), newDateTime(CURRENT_YEAR + 6, 7, 17, 12, 0, 0));
assertEquals(asList(newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0), newDateTime(CURRENT_YEAR + 6, 7, 16, 12, 0, 0), newDateTime(CURRENT_YEAR + 6, 7, 17, 12, 0, 0)), eventTimes);
} finally {
stopFakingTime();
}
}
Aggregations