use of org.kie.kogito.jobs.api.event.CancelJobRequestEvent 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.CancelJobRequestEvent in project kogito-apps by kiegroup.
the class ReactiveMessagingEventConsumerTest method prepareCancelJobWithExistingJob.
private void prepareCancelJobWithExistingJob(JobDetails existingJob) {
CancelJobRequestEvent event = CancelJobRequestEvent.builder().jobId(JOB_ID).build();
doReturn(event).when(message).getPayload();
CompletionStage<JobDetails> completionStage = CompletableFuture.completedFuture(existingJob);
doReturn(completionStage).when(scheduler).cancel(JOB_ID);
}
use of org.kie.kogito.jobs.api.event.CancelJobRequestEvent in project kogito-runtimes by kiegroup.
the class JobCloudEventSerializerTest method serializeCancelJobRequestEvent.
@Test
void serializeCancelJobRequestEvent() throws Exception {
CancelJobRequestEvent event = CancelJobRequestEvent.builder().id(ID).specVersion(SPEC_VERSION).source(SOURCE).time(TIME).subject(SUBJECT).processInstanceId(PROCESS_INSTANCE_ID).processId(PROCESS_ID).rootProcessInstanceId(ROOT_PROCESS_INSTANCE_ID).rootProcessId(ROOT_PROCESS_ID).kogitoAddons(KOGITO_ADDONS).jobId(JOB_ID).build();
String json = serializer.serialize(event);
assertThat(json).isNotNull();
JsonNode jsonNode = OBJECT_MAPPER.readTree(json);
assertHasTotalFields(jsonNode, 12);
assertHasFieldWithValue(jsonNode, "type", CANCEL_JOB_REQUEST);
assertHasBaseFields(jsonNode);
assertHasProcessContextFields(jsonNode);
JsonNode dataJsonNode = jsonNode.get("data");
assertThat(dataJsonNode).isNotNull();
assertHasTotalFields(dataJsonNode, 1);
assertHasFieldWithValue(dataJsonNode, "id", JOB_ID);
}
use of org.kie.kogito.jobs.api.event.CancelJobRequestEvent in project kogito-runtimes by kiegroup.
the class ReactiveMessagingJobsService method cancelJob.
@Override
public boolean cancelJob(String id) {
LOGGER.debug("cancelJob, id: {}", id);
CancelJobRequestEvent event = CancelJobRequestEvent.builder().source(serviceUrl).jobId(id).kogitoAddons(KOGITO_ADDON).build();
emitEvent(event);
return true;
}
use of org.kie.kogito.jobs.api.event.CancelJobRequestEvent in project kogito-apps by kiegroup.
the class ReactiveMessagingEventConsumerTest method onCancelJobWithError.
@Test
void onCancelJobWithError() {
CancelJobRequestEvent event = CancelJobRequestEvent.builder().jobId(JOB_ID).build();
doReturn(event).when(message).getPayload();
CompletionStage<JobDetails> completionStage = CompletableFuture.failedFuture(new Exception(INTERNAL_ERROR));
doReturn(completionStage).when(scheduler).cancel(JOB_ID);
executeFailedExecution(INTERNAL_ERROR);
verify(scheduler).cancel(JOB_ID);
}
Aggregations