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);
}
}
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")));
}
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);
}
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")));
}
}
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();
}
}
Aggregations