Search in sources :

Example 6 with RepeatingSchedulableJob

use of org.motechproject.scheduler.contract.RepeatingSchedulableJob in project motech by motech.

the class TestEventListener method shouldScheduleInterveningRepeatJob.

@Test
public void shouldScheduleInterveningRepeatJob() throws SchedulerException {
    try {
        fakeNow(newDateTime(2020, 7, 15, 10, 0, 0));
        Map<String, Object> params = new HashMap<>();
        params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
        schedulerService.scheduleRepeatingJob(new RepeatingSchedulableJob(new MotechEvent("test_event", params), DateTimeConstants.SECONDS_PER_DAY, newDateTime(2020, 7, 14, 12, 0, 0), newDateTime(2020, 7, 18, 12, 0, 0), true));
        List<DateTime> fireTimes = getFireTimes("test_event-job_id-repeat");
        assertEquals(asList(newDateTime(2020, 7, 15, 12, 0, 0), newDateTime(2020, 7, 16, 12, 0, 0), newDateTime(2020, 7, 17, 12, 0, 0)), fireTimes);
    } finally {
        stopFakingTime();
    }
}
Also used : RepeatingSchedulableJob(org.motechproject.scheduler.contract.RepeatingSchedulableJob) HashMap(java.util.HashMap) MotechEvent(org.motechproject.event.MotechEvent) DateUtil.newDateTime(org.motechproject.commons.date.util.DateUtil.newDateTime) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 7 with RepeatingSchedulableJob

use of org.motechproject.scheduler.contract.RepeatingSchedulableJob in project motech by motech.

the class TestEventListener method shouldScheduleRepeatJobBoundByCount.

@Test
public void shouldScheduleRepeatJobBoundByCount() throws SchedulerException {
    try {
        fakeNow(newDateTime(2020, 7, 15, 10, 0, 0));
        Map<String, Object> params = new HashMap<>();
        final String jobId = id("jobId");
        params.put(MotechSchedulerService.JOB_ID_KEY, jobId);
        schedulerService.scheduleRepeatingJob(new RepeatingSchedulableJob(new MotechEvent("test_event", params), 2, DateTimeConstants.SECONDS_PER_DAY, newDateTime(2020, 7, 15, 12, 0, 0), null, false));
        List<DateTime> fireTimes = getFireTimes("test_event-" + jobId + "-repeat");
        assertEquals(asList(newDateTime(2020, 7, 15, 12, 0, 0), newDateTime(2020, 7, 16, 12, 0, 0), newDateTime(2020, 7, 17, 12, 0, 0)), fireTimes);
    } finally {
        stopFakingTime();
    }
}
Also used : RepeatingSchedulableJob(org.motechproject.scheduler.contract.RepeatingSchedulableJob) HashMap(java.util.HashMap) MotechEvent(org.motechproject.event.MotechEvent) DateUtil.newDateTime(org.motechproject.commons.date.util.DateUtil.newDateTime) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 8 with RepeatingSchedulableJob

use of org.motechproject.scheduler.contract.RepeatingSchedulableJob 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));
}
Also used : RepeatingSchedulableJob(org.motechproject.scheduler.contract.RepeatingSchedulableJob) CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) HashMap(java.util.HashMap) DayOfWeekSchedulableJob(org.motechproject.scheduler.contract.DayOfWeekSchedulableJob) DateUtil.newDateTime(org.motechproject.commons.date.util.DateUtil.newDateTime) Time(org.motechproject.commons.date.model.Time) DateTime(org.joda.time.DateTime) TimeFaker.stopFakingTime(org.motechproject.testing.utils.TimeFaker.stopFakingTime) MotechEvent(org.motechproject.event.MotechEvent) DateUtil.newDateTime(org.motechproject.commons.date.util.DateUtil.newDateTime) DateTime(org.joda.time.DateTime) RunOnceSchedulableJob(org.motechproject.scheduler.contract.RunOnceSchedulableJob)

Example 9 with RepeatingSchedulableJob

use of org.motechproject.scheduler.contract.RepeatingSchedulableJob in project motech by motech.

the class MotechSchedulerDatabaseServiceImplBundleIT method shouldCheckIFJobIsUIDefined.

@Test
public void shouldCheckIFJobIsUIDefined() {
    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.scheduleRepeatingJob(new RepeatingSchedulableJob(new MotechEvent("test_event_2", params), null, DateTimeConstants.SECONDS_PER_DAY, newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0), newDateTime(CURRENT_YEAR + 6, 7, 18, 12, 0, 0), false, false, true));
        schedulerService.scheduleRepeatingPeriodJob(new RepeatingPeriodSchedulableJob(new MotechEvent("test_event_2", params), newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0), newDateTime(CURRENT_YEAR + 6, 7, 18, 12, 0, 0), new Period(4, 0, 0, 0), false, false, false));
        List<JobBasicInfo> expectedJobBasicInfos = new ArrayList<>();
        expectedJobBasicInfos.add(new JobBasicInfo(JobBasicInfo.ACTIVITY_NOTSTARTED, JobBasicInfo.STATUS_OK, "test_event_2-job_id-repeat", DEFAULT_GROUP, format("%s-07-15 12:00:00", CURRENT_YEAR + 6), format("%s-07-15 12:00:00", CURRENT_YEAR + 6), format("%s-07-18 12:00:00", CURRENT_YEAR + 6), JobBasicInfo.JOBTYPE_REPEATING, "", true));
        expectedJobBasicInfos.add(new JobBasicInfo(JobBasicInfo.ACTIVITY_NOTSTARTED, JobBasicInfo.STATUS_OK, "test_event_2-job_id-period", DEFAULT_GROUP, format("%s-07-15 12:00:00", CURRENT_YEAR + 6), format("%s-07-15 12:00:00", CURRENT_YEAR + 6), format("%s-07-18 12:00:00", CURRENT_YEAR + 6), JobBasicInfo.JOBTYPE_PERIOD, "", false));
        int testJobsCount = 0;
        for (JobBasicInfo job : expectedJobBasicInfos) {
            for (JobBasicInfo expectedJob : expectedJobBasicInfos) {
                if (job.getName().equals(expectedJob.getName())) {
                    testJobsCount += 1;
                    assertEquals(expectedJob.isUiDefined(), job.isUiDefined());
                }
            }
        }
        assertEquals(2, testJobsCount);
    } finally {
        stopFakingTime();
    }
}
Also used : RepeatingSchedulableJob(org.motechproject.scheduler.contract.RepeatingSchedulableJob) RepeatingPeriodSchedulableJob(org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Period(org.joda.time.Period) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 10 with RepeatingSchedulableJob

use of org.motechproject.scheduler.contract.RepeatingSchedulableJob 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();
    }
}
Also used : RepeatingSchedulableJob(org.motechproject.scheduler.contract.RepeatingSchedulableJob) CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) HashMap(java.util.HashMap) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) MotechEvent(org.motechproject.event.MotechEvent) JobsSearchSettings(org.motechproject.scheduler.contract.JobsSearchSettings) RunOnceSchedulableJob(org.motechproject.scheduler.contract.RunOnceSchedulableJob) Test(org.junit.Test)

Aggregations

RepeatingSchedulableJob (org.motechproject.scheduler.contract.RepeatingSchedulableJob)20 Test (org.junit.Test)14 HashMap (java.util.HashMap)12 MotechEvent (org.motechproject.event.MotechEvent)12 DateTime (org.joda.time.DateTime)7 DateUtil.newDateTime (org.motechproject.commons.date.util.DateUtil.newDateTime)6 CronSchedulableJob (org.motechproject.scheduler.contract.CronSchedulableJob)4 RunOnceSchedulableJob (org.motechproject.scheduler.contract.RunOnceSchedulableJob)4 JobBasicInfo (org.motechproject.scheduler.contract.JobBasicInfo)3 ArrayList (java.util.ArrayList)2 Period (org.joda.time.Period)2 JobsSearchSettings (org.motechproject.scheduler.contract.JobsSearchSettings)2 RepeatingPeriodSchedulableJob (org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob)2 SimpleTrigger (org.quartz.SimpleTrigger)2 Date (java.util.Date)1 Before (org.junit.Before)1 NanoStopWatch (org.motechproject.commons.api.NanoStopWatch)1 Time (org.motechproject.commons.date.model.Time)1 DayOfWeekSchedulableJob (org.motechproject.scheduler.contract.DayOfWeekSchedulableJob)1 SchedulableJobValidator.validateRepeatingSchedulableJob (org.motechproject.scheduler.validation.SchedulableJobValidator.validateRepeatingSchedulableJob)1