Search in sources :

Example 26 with CronSchedulableJob

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

the class TestEventListener method shouldNotPauseJobIfItIsNotUiDefined.

@Test(expected = MotechSchedulerException.class)
public void shouldNotPauseJobIfItIsNotUiDefined() 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 * * ?"));
        assertEquals(NORMAL, scheduler.getTriggerState(triggerKey("test_event-job_id", "default")));
        schedulerService.pauseJob(info);
    } finally {
        assertEquals(NORMAL, scheduler.getTriggerState(triggerKey("test_event-job_id", "default")));
    }
}
Also used : CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) HashMap(java.util.HashMap) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 27 with CronSchedulableJob

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

the class MotechSchedulerDatabaseServiceImplBundleIT method shouldGetScheduledJobsBasicInfo.

@Test
public void shouldGetScheduledJobsBasicInfo() 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_2", params), "0 0 12 * * ?"));
        schedulerService.scheduleRunOnceJob(new RunOnceSchedulableJob(new MotechEvent("test_event_2", params), newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0)));
        schedulerService.scheduleRepeatingJob(new RepeatingSchedulableJob(new MotechEvent("test_event_2", params), DateTimeConstants.SECONDS_PER_DAY, newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0), newDateTime(CURRENT_YEAR + 6, 7, 18, 12, 0, 0), false));
        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));
        for (String groupName : scheduler.getJobGroupNames()) {
            for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) {
                if (jobKey.getName().equals("test_event_2-job_id")) {
                    scheduler.pauseJob(jobKey);
                }
            }
        }
        List<JobBasicInfo> expectedJobBasicInfos = new ArrayList<>();
        expectedJobBasicInfos.add(new JobBasicInfo(JobBasicInfo.ACTIVITY_NOTSTARTED, JobBasicInfo.STATUS_PAUSED, "test_event_2-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));
        expectedJobBasicInfos.add(new JobBasicInfo(JobBasicInfo.ACTIVITY_NOTSTARTED, JobBasicInfo.STATUS_OK, "test_event_2-job_id-runonce", 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-15 12:00:00", CURRENT_YEAR + 6), JobBasicInfo.JOBTYPE_RUNONCE, "", false));
        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, "", false));
        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));
        List<JobBasicInfo> jobBasicInfos;
        JobsSearchSettings jobsSearchSettings = getGridSettings(0, 10, "name", "asc");
        jobBasicInfos = databaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
        int testJobsCount = 0;
        for (JobBasicInfo job : jobBasicInfos) {
            for (JobBasicInfo expectedJob : expectedJobBasicInfos) {
                if (job.getName().equals(expectedJob.getName())) {
                    testJobsCount += 1;
                    assertEquals(expectedJob.getActivity(), job.getActivity());
                    assertEquals(expectedJob.getStatus(), job.getStatus());
                    assertEquals(expectedJob.getStartDate(), job.getStartDate());
                    assertEquals(expectedJob.getNextFireDate(), job.getNextFireDate());
                }
            }
        }
        assertEquals(4, testJobsCount);
    } finally {
        stopFakingTime();
    }
}
Also used : RepeatingSchedulableJob(org.motechproject.scheduler.contract.RepeatingSchedulableJob) CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Period(org.joda.time.Period) JobsSearchSettings(org.motechproject.scheduler.contract.JobsSearchSettings) RunOnceSchedulableJob(org.motechproject.scheduler.contract.RunOnceSchedulableJob) JobKey(org.quartz.JobKey) RepeatingPeriodSchedulableJob(org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 28 with CronSchedulableJob

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

the class SchedulableJobValidatorTest method shouldValidateCronSchedulableJob.

@Test
public void shouldValidateCronSchedulableJob() {
    CronSchedulableJob job = new CronSchedulableJob(motechEvent, "0 0 0 * * ? *", null, null, true, false);
    SchedulableJobValidator.validateCronSchedulableJob(job);
}
Also used : CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) Test(org.junit.Test)

Example 29 with CronSchedulableJob

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

the class SchedulerChannelProviderBundleIT method setUp.

@Before
public void setUp() {
    if (channelProvider == null) {
        channelProvider = (SchedulerChannelProvider) bundleContext.getService(bundleContext.getServiceReference("org.motechproject.tasks.service.DynamicChannelProvider"));
    }
    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 * * ?"));
    schedulerService.scheduleRunOnceJob(new RunOnceSchedulableJob(new MotechEvent(TEST_EVENT, params), DateTime.now().plusDays(1)));
    schedulerService.scheduleRepeatingJob(new RepeatingSchedulableJob(new MotechEvent(TEST_EVENT, params), DateTimeConstants.SECONDS_PER_DAY, DateTime.now().plusHours(1), DateTime.now().plusHours(3), false));
}
Also used : RepeatingSchedulableJob(org.motechproject.scheduler.contract.RepeatingSchedulableJob) CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) HashMap(java.util.HashMap) MotechEvent(org.motechproject.event.MotechEvent) RunOnceSchedulableJob(org.motechproject.scheduler.contract.RunOnceSchedulableJob) Before(org.junit.Before)

Example 30 with CronSchedulableJob

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

the class SchedulableJobBuilder method buildCronSchedulableJob.

private static SchedulableJob buildCronSchedulableJob(Trigger trigger, JobDataMap dataMap) {
    CronTrigger cronTrigger = (CronTrigger) trigger;
    CronSchedulableJob job = new CronSchedulableJob();
    job.setEndDate(getEndDate(cronTrigger));
    job.setCronExpression(cronTrigger.getCronExpression());
    job.setIgnorePastFiresAtStart(dataMap.getBoolean(IGNORE_PAST_FIRES_AT_START));
    return job;
}
Also used : CronTrigger(org.quartz.CronTrigger) CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob)

Aggregations

CronSchedulableJob (org.motechproject.scheduler.contract.CronSchedulableJob)33 MotechEvent (org.motechproject.event.MotechEvent)27 Test (org.junit.Test)25 HashMap (java.util.HashMap)24 DateTime (org.joda.time.DateTime)10 DateUtil.newDateTime (org.motechproject.commons.date.util.DateUtil.newDateTime)10 JobBasicInfo (org.motechproject.scheduler.contract.JobBasicInfo)8 RepeatingSchedulableJob (org.motechproject.scheduler.contract.RepeatingSchedulableJob)4 RunOnceSchedulableJob (org.motechproject.scheduler.contract.RunOnceSchedulableJob)4 JobKey (org.quartz.JobKey)3 Time (org.motechproject.commons.date.model.Time)2 CronJobId (org.motechproject.scheduler.contract.CronJobId)2 JobsSearchSettings (org.motechproject.scheduler.contract.JobsSearchSettings)2 ArrayList (java.util.ArrayList)1 Period (org.joda.time.Period)1 Before (org.junit.Before)1 DayOfWeekSchedulableJob (org.motechproject.scheduler.contract.DayOfWeekSchedulableJob)1 RepeatingPeriodSchedulableJob (org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob)1 SchedulableJobValidator.validateCronSchedulableJob (org.motechproject.scheduler.validation.SchedulableJobValidator.validateCronSchedulableJob)1 TimeFaker.stopFakingTime (org.motechproject.testing.utils.TimeFaker.stopFakingTime)1