use of org.kie.kogito.jobs.api.event.CreateProcessInstanceJobRequestEvent in project kogito-apps by kiegroup.
the class BaseMessagingApiIT method cancelJob.
@Test
@Timeout(value = 10, unit = TimeUnit.MINUTES)
protected void cancelJob() {
assertCallbackResource();
// create a job service request event and send it to the jobs service.
ZonedDateTime expiration = ZonedDateTime.now().plusDays(1);
String callback = buildCallbackEndpoint(getCallbackResourceURL(), PROCESS_ID, PROCESS_INSTANCE_ID, NODE_INSTANCE_ID_2);
CreateProcessInstanceJobRequestEvent createJobEvent = CreateProcessInstanceJobRequestEvent.builder().source(URI.create(TEST_SOURCE)).job(new Job(JOB_ID_2, expiration, PRIORITY, callback, PROCESS_INSTANCE_ID, ROOT_PROCESS_INSTANCE_ID, PROCESS_ID, ROOT_PROCESS_ID, REPEAT_INTERVAL, REPEAT_LIMIT, NODE_INSTANCE_ID_2)).processInstanceId(PROCESS_INSTANCE_ID).processId(PROCESS_ID).rootProcessInstanceId(ROOT_PROCESS_INSTANCE_ID).rootProcessId(ROOT_PROCESS_ID).kogitoAddons(KOGITO_ADDONS).build();
String createJobEventJson = serializer.serialize(createJobEvent);
jobEventsEmitter.send(createJobEventJson);
// wait until the job is created or fail if the CALLBACK_EXECUTIONS_QUERY_TIMOUT_IN_SECONDS elapsed.
String jobUrl = "/jobs/" + JOB_ID_2;
waitUntilResult(() -> getJob(jobUrl), response -> expectedJobExists(JOB_ID_2, response), CALLBACK_EXECUTIONS_QUERY_TIMOUT_IN_SECONDS, CALLBACK_EXECUTIONS_QUERY_POLL_INTERVAL_IN_MILLISECONDS);
// create a job service cancel event and send it to the jobs service.
CancelJobRequestEvent cancelJobEvent = CancelJobRequestEvent.builder().source(URI.create(TEST_SOURCE)).jobId(JOB_ID_2).build();
String cancelJobEventJson = serializer.serialize(cancelJobEvent);
jobEventsEmitter.send(cancelJobEventJson);
// wait until the job was canceled or fail if CALLBACK_EXECUTIONS_QUERY_TIMOUT_IN_SECONDS elapsed.
waitUntilResult(() -> getJob(jobUrl), response -> expectedJobDontExists(JOB_ID_2, response), CALLBACK_EXECUTIONS_QUERY_TIMOUT_IN_SECONDS, CALLBACK_EXECUTIONS_QUERY_POLL_INTERVAL_IN_MILLISECONDS);
}
use of org.kie.kogito.jobs.api.event.CreateProcessInstanceJobRequestEvent in project kogito-apps by kiegroup.
the class ReactiveMessagingEventConsumerTest method onCreateProcessInstanceJobWithJobQueryError.
@Test
void onCreateProcessInstanceJobWithJobQueryError() {
Job job = new Job();
job.setId(JOB_ID);
CreateProcessInstanceJobRequestEvent event = CreateProcessInstanceJobRequestEvent.builder().job(job).build();
doReturn(event).when(message).getPayload();
CompletionStage<JobDetails> queryJobStage = CompletableFuture.failedFuture(new Exception(JOB_QUERY_ERROR));
doReturn(queryJobStage).when(jobRepository).get(JOB_ID);
executeFailedExecution(JOB_QUERY_ERROR);
verify(scheduler, never()).schedule(any());
}
use of org.kie.kogito.jobs.api.event.CreateProcessInstanceJobRequestEvent in project kogito-apps by kiegroup.
the class ReactiveMessagingEventConsumerTest method prepareCreateProcessInstanceJobWithExistingJobResult.
private void prepareCreateProcessInstanceJobWithExistingJobResult(JobDetails existingJobResult) {
Job job = new Job();
job.setId(JOB_ID);
CreateProcessInstanceJobRequestEvent event = CreateProcessInstanceJobRequestEvent.builder().job(job).build();
doReturn(event).when(message).getPayload();
CompletionStage<JobDetails> queryJobStage = CompletableFuture.completedFuture(existingJobResult);
doReturn(queryJobStage).when(jobRepository).get(JOB_ID);
JobDetails createdJob = JobDetails.builder().build();
Publisher<JobDetails> schedulePublisher = ReactiveStreams.of(createdJob).buildRs();
lenient().doReturn(schedulePublisher).when(scheduler).schedule(any());
}
use of org.kie.kogito.jobs.api.event.CreateProcessInstanceJobRequestEvent in project kogito-runtimes by kiegroup.
the class ReactiveMessagingJobsService method scheduleProcessInstanceJob.
@Override
public String scheduleProcessInstanceJob(ProcessInstanceJobDescription description) {
Job job = buildCallbackPatternJob(description, buildCallbackURI(description, serviceUrl.toString()));
LOGGER.debug("scheduleProcessInstanceJob job: {}", job);
CreateProcessInstanceJobRequestEvent event = CreateProcessInstanceJobRequestEvent.builder().source(serviceUrl).job(job).processInstanceId(description.processInstanceId()).processId(description.processId()).rootProcessInstanceId(description.rootProcessInstanceId()).rootProcessId(description.rootProcessId()).kogitoAddons(KOGITO_ADDON).build();
emitEvent(event);
return job.getId();
}
use of org.kie.kogito.jobs.api.event.CreateProcessInstanceJobRequestEvent in project kogito-apps by kiegroup.
the class BaseMessagingApiIT method createJob.
@Test
@Timeout(value = 10, unit = TimeUnit.MINUTES)
protected void createJob() {
assertCallbackResource();
// create a job service request event and send it to the jobs service.
ZonedDateTime expiration = ZonedDateTime.now().plusSeconds(10);
String callback = buildCallbackEndpoint(getCallbackResourceURL(), PROCESS_ID, PROCESS_INSTANCE_ID, NODE_INSTANCE_ID_1);
CreateProcessInstanceJobRequestEvent event = CreateProcessInstanceJobRequestEvent.builder().source(URI.create(TEST_SOURCE)).job(new Job(JOB_ID_1, expiration, PRIORITY, callback, PROCESS_INSTANCE_ID, ROOT_PROCESS_INSTANCE_ID, PROCESS_ID, ROOT_PROCESS_ID, REPEAT_INTERVAL, REPEAT_LIMIT, NODE_INSTANCE_ID_1)).processInstanceId(PROCESS_INSTANCE_ID).processId(PROCESS_ID).rootProcessInstanceId(ROOT_PROCESS_INSTANCE_ID).rootProcessId(ROOT_PROCESS_ID).kogitoAddons(KOGITO_ADDONS).build();
String jsonEvent = serializer.serialize(event);
jobEventsEmitter.send(jsonEvent);
// wait until we can verify that the job was executed or fail if the CALLBACK_EXECUTIONS_QUERY_TIMOUT_IN_SECONDS
// elapsed.
waitUntilResult(() -> getJobCallbackExecutions(NODE_INSTANCE_ID_1), executions -> Objects.equals(executions, "2"), CALLBACK_EXECUTIONS_QUERY_TIMOUT_IN_SECONDS, CALLBACK_EXECUTIONS_QUERY_POLL_INTERVAL_IN_MILLISECONDS);
}
Aggregations