Search in sources :

Example 1 with JobBasicInfo

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

the class MotechSchedulerDatabaseServiceImpl method getScheduledJobsBasicInfo.

@Override
public List<JobBasicInfo> getScheduledJobsBasicInfo(JobsSearchSettings jobsSearchSettings) throws MotechSchedulerJobRetrievalException {
    List<JobBasicInfo> jobBasicInfos = new LinkedList<>();
    String query = getQuery(jobsSearchSettings);
    if (query == null) {
        return jobBasicInfos;
    }
    LOGGER.debug("Executing {}", query);
    List<String> columnNames = new LinkedList<>();
    columnNames.add(TRIGGER_NAME);
    columnNames.add(TRIGGER_GROUP);
    columnNames.add(JOB_DATA);
    List<List<Object>> objects;
    try {
        objects = executeQuery(query, columnNames);
        for (List<Object> row : objects) {
            JobKey jobKey = new JobKey(row.get(0).toString(), row.get(1).toString());
            Trigger trigger = scheduler.getTriggersOfJob(jobKey).get(0);
            String jobName = jobKey.getName();
            String jobGroup = jobKey.getGroup();
            String jobType = getJobType(jobKey);
            String activity = getJobActivity(trigger);
            String info = getJobInfo(trigger, jobType);
            String status = getJobStatus(trigger.getKey());
            String startDate = getStartDate(trigger);
            String nextFireDate = "";
            if (trigger.getNextFireTime() != null) {
                nextFireDate = DateTimeFormat.forPattern(DATE_FORMAT_PATTERN).print(trigger.getNextFireTime().getTime());
            }
            String endDate = getEndDate(trigger, jobType);
            boolean uiDefined = getUiDefined((byte[]) row.get(2));
            jobBasicInfos.add(new JobBasicInfo(activity, status, jobName, jobGroup, startDate, nextFireDate, endDate, jobType, info, uiDefined));
        }
        return jobBasicInfos;
    } catch (SQLException | SchedulerException | ClassNotFoundException | IOException e) {
        throw new MotechSchedulerJobRetrievalException("Retrieval of scheduled jobs failed.", e);
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) SQLException(java.sql.SQLException) IOException(java.io.IOException) LinkedList(java.util.LinkedList) MotechSchedulerJobRetrievalException(org.motechproject.scheduler.exception.MotechSchedulerJobRetrievalException) JobKey(org.quartz.JobKey) CalendarIntervalTrigger(org.quartz.CalendarIntervalTrigger) CronTrigger(org.quartz.CronTrigger) OperableTrigger(org.quartz.spi.OperableTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 2 with JobBasicInfo

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

the class TestEventListener method shouldResumeJobIfItIsUiDefined.

@Test
public void shouldResumeJobIfItIsUiDefined() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
    JobBasicInfo info = new JobBasicInfo(JobBasicInfo.ACTIVITY_ACTIVE, JobBasicInfo.STATUS_PAUSED, "test_event-job_id", "default", "start-time", "nex-fire-time", "end-time", JobBasicInfo.JOBTYPE_CRON, "test-info", true);
    CronSchedulableJob job = new CronSchedulableJob(new MotechEvent("test_event", params), "0 0 12 * * ?");
    job.setUiDefined(true);
    schedulerService.scheduleJob(job);
    scheduler.pauseJob(new JobKey(info.getName(), info.getGroup()));
    assertEquals(PAUSED, scheduler.getTriggerState(triggerKey("test_event-job_id", "default")));
    schedulerService.resumeJob(info);
    assertEquals(NORMAL, scheduler.getTriggerState(triggerKey("test_event-job_id", "default")));
}
Also used : CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) JobKey(org.quartz.JobKey) HashMap(java.util.HashMap) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 3 with JobBasicInfo

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

the class TestEventListener method shouldNotDeleteJobIfJobDoesNotExist.

@Test(expected = MotechSchedulerException.class)
public void shouldNotDeleteJobIfJobDoesNotExist() throws Exception {
    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.deleteJob(info);
}
Also used : JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) Test(org.junit.Test)

Example 4 with JobBasicInfo

use of org.motechproject.scheduler.contract.JobBasicInfo 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")));
    }
}
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 5 with JobBasicInfo

use of org.motechproject.scheduler.contract.JobBasicInfo 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)

Aggregations

JobBasicInfo (org.motechproject.scheduler.contract.JobBasicInfo)24 Test (org.junit.Test)21 JobsSearchSettings (org.motechproject.scheduler.contract.JobsSearchSettings)11 HashMap (java.util.HashMap)10 MotechEvent (org.motechproject.event.MotechEvent)10 CronSchedulableJob (org.motechproject.scheduler.contract.CronSchedulableJob)8 JobKey (org.quartz.JobKey)4 ArrayList (java.util.ArrayList)3 RepeatingSchedulableJob (org.motechproject.scheduler.contract.RepeatingSchedulableJob)3 RunOnceSchedulableJob (org.motechproject.scheduler.contract.RunOnceSchedulableJob)3 JobsRecords (org.motechproject.scheduler.web.domain.JobsRecords)3 Period (org.joda.time.Period)2 RepeatingPeriodSchedulableJob (org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob)2 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Before (org.junit.Before)1 JobDetailedInfo (org.motechproject.scheduler.contract.JobDetailedInfo)1 MotechSchedulerJobRetrievalException (org.motechproject.scheduler.exception.MotechSchedulerJobRetrievalException)1