Search in sources :

Example 1 with CreateProcessInstanceJobRequestEvent

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);
}
Also used : CreateProcessInstanceJobRequestEvent(org.kie.kogito.jobs.api.event.CreateProcessInstanceJobRequestEvent) ZonedDateTime(java.time.ZonedDateTime) CancelJobRequestEvent(org.kie.kogito.jobs.api.event.CancelJobRequestEvent) Job(org.kie.kogito.jobs.api.Job) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 2 with CreateProcessInstanceJobRequestEvent

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());
}
Also used : CreateProcessInstanceJobRequestEvent(org.kie.kogito.jobs.api.event.CreateProcessInstanceJobRequestEvent) Job(org.kie.kogito.jobs.api.Job) JobDetails(org.kie.kogito.jobs.service.model.job.JobDetails) JobServiceException(org.kie.kogito.jobs.service.exception.JobServiceException) Test(org.junit.jupiter.api.Test)

Example 3 with CreateProcessInstanceJobRequestEvent

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());
}
Also used : CreateProcessInstanceJobRequestEvent(org.kie.kogito.jobs.api.event.CreateProcessInstanceJobRequestEvent) Job(org.kie.kogito.jobs.api.Job) JobDetails(org.kie.kogito.jobs.service.model.job.JobDetails)

Example 4 with CreateProcessInstanceJobRequestEvent

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();
}
Also used : CreateProcessInstanceJobRequestEvent(org.kie.kogito.jobs.api.event.CreateProcessInstanceJobRequestEvent) Job(org.kie.kogito.jobs.api.Job) JobCallbackResourceDef.buildCallbackPatternJob(org.kie.kogito.jobs.api.JobCallbackResourceDef.buildCallbackPatternJob)

Example 5 with CreateProcessInstanceJobRequestEvent

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);
}
Also used : CreateProcessInstanceJobRequestEvent(org.kie.kogito.jobs.api.event.CreateProcessInstanceJobRequestEvent) ZonedDateTime(java.time.ZonedDateTime) Job(org.kie.kogito.jobs.api.Job) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Aggregations

Job (org.kie.kogito.jobs.api.Job)8 CreateProcessInstanceJobRequestEvent (org.kie.kogito.jobs.api.event.CreateProcessInstanceJobRequestEvent)8 Test (org.junit.jupiter.api.Test)6 JobDetails (org.kie.kogito.jobs.service.model.job.JobDetails)3 ZonedDateTime (java.time.ZonedDateTime)2 Timeout (org.junit.jupiter.api.Timeout)2 JobServiceException (org.kie.kogito.jobs.service.exception.JobServiceException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 JobCallbackResourceDef.buildCallbackPatternJob (org.kie.kogito.jobs.api.JobCallbackResourceDef.buildCallbackPatternJob)1 CancelJobRequestEvent (org.kie.kogito.jobs.api.event.CancelJobRequestEvent)1