use of org.motechproject.scheduler.contract.RunOnceSchedulableJob in project motech by motech.
the class MotechSchedulerDatabaseServiceImplBundleIT method shouldGetScheduledJobDetailedInfo.
@Test
public void shouldGetScheduledJobDetailedInfo() throws SchedulerException, SQLException {
try {
fakeNow(newDateTime(CURRENT_YEAR + 6, 7, 15, 10, 0, 0));
JobDetailedInfo jobDetailedInfo = null;
Map<String, Object> params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id_2");
params.put("param1", "value1");
params.put("param2", "value2");
schedulerService.scheduleRunOnceJob(new RunOnceSchedulableJob(new MotechEvent("test_event_2", params), newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0)));
JobsSearchSettings jobsSearchSettings = getGridSettings(0, 10, "name", "asc");
for (JobBasicInfo job : databaseService.getScheduledJobsBasicInfo(jobsSearchSettings)) {
if (job.getName().equals("test_event_2-job_id_2-runonce")) {
jobDetailedInfo = databaseService.getScheduledJobDetailedInfo(job);
}
}
assertNotNull(jobDetailedInfo);
assertEquals("test_event_2", jobDetailedInfo.getEventInfoList().get(0).getSubject());
assertEquals(4, jobDetailedInfo.getEventInfoList().get(0).getParameters().size());
} finally {
stopFakingTime();
}
}
use of org.motechproject.scheduler.contract.RunOnceSchedulableJob in project motech by motech.
the class SchedulerBundleIT method testRunOnceJob.
@Test
public void testRunOnceJob() throws InterruptedException {
waitForEventConsumerToStart();
final List<String> receivedEvents = new ArrayList<>();
eventRegistry.registerListener(new EventListener() {
@Override
public void handle(MotechEvent event) {
synchronized (receivedEvents) {
receivedEvents.add(event.getSubject());
receivedEvents.notify();
}
}
@Override
public String getIdentifier() {
return TEST_SUBJECT;
}
}, TEST_SUBJECT);
final MotechEvent motechEvent = new MotechEvent(TEST_SUBJECT);
motechEvent.getParameters().put(MotechSchedulerService.JOB_ID_KEY, "jobId");
schedulerService.unscheduleAllJobs("SchedulerBundleIT");
schedulerService.scheduleRunOnceJob(new RunOnceSchedulableJob(motechEvent, DateTime.now().plusSeconds(5)));
synchronized (receivedEvents) {
System.out.print("\nEvent waiting " + new Date() + "\n");
receivedEvents.wait(15000);
}
assertEquals(1, receivedEvents.size());
assertEquals(receivedEvents.get(0), TEST_SUBJECT);
}
use of org.motechproject.scheduler.contract.RunOnceSchedulableJob in project motech by motech.
the class SchedulableJobValidatorTest method shouldThrowMotechSchedulerExceptionIfStartDateIsInThePast.
@Test(expected = MotechSchedulerException.class)
public void shouldThrowMotechSchedulerExceptionIfStartDateIsInThePast() {
try {
fakeNow(newDateTime(2020, 7, 15, 10, 0, 0));
RunOnceSchedulableJob job = new RunOnceSchedulableJob(motechEvent, DateUtil.now().minusHours(1), false);
SchedulableJobValidator.validateRunOnceSchedulableJob(job);
} finally {
stopFakingTime();
}
}
use of org.motechproject.scheduler.contract.RunOnceSchedulableJob in project motech by motech.
the class SchedulableJobValidatorTest method shouldThrowIllegalArgumentExceptionIfMotechEventIsNullInRunOnceSchedulableJob.
@Test(expected = IllegalArgumentException.class)
public void shouldThrowIllegalArgumentExceptionIfMotechEventIsNullInRunOnceSchedulableJob() {
try {
fakeNow(newDateTime(2020, 7, 15, 10, 0, 0));
RunOnceSchedulableJob job = new RunOnceSchedulableJob(null, DateUtil.now().plusHours(1), false);
SchedulableJobValidator.validateRunOnceSchedulableJob(job);
} finally {
stopFakingTime();
}
}
use of org.motechproject.scheduler.contract.RunOnceSchedulableJob in project motech by motech.
the class MotechSchedulerListener method handleScheduleRepeatingJobEvent.
/**
* Handles the motech event scheduling a new repeating job.
*
* @param event the event to be handled
*/
@MotechListener(subjects = { SCHEDULE_REPEATING_JOB })
public void handleScheduleRepeatingJobEvent(MotechEvent event) {
Map<String, Object> parameters = event.getParameters();
Map<String, Object> metadata = event.getMetadata();
String jobSubject = (String) metadata.get(JOB_SUBJECT);
Integer jobStart = (Integer) metadata.get(JOB_START);
// Reset jobID that is appended with each retry and becomes too long
parameters.put(JOB_ID, null);
MotechEvent jobEvent = new MotechEvent(jobSubject, parameters, null, metadata);
RunOnceSchedulableJob runOnceJob = new RunOnceSchedulableJob(jobEvent, DateTime.now().plusSeconds(jobStart));
schedulerService.scheduleRunOnceJob(runOnceJob);
}
Aggregations