Search in sources :

Example 1 with TimerJobId

use of org.kie.kogito.jobs.TimerJobId in project kogito-runtimes by kiegroup.

the class StateBasedNodeInstance method internalTrigger.

@Override
public void internalTrigger(KogitoNodeInstance from, String type) {
    super.internalTrigger(from, type);
    // if node instance was cancelled, abort
    if (getNodeInstanceContainer().getNodeInstance(getStringId()) == null) {
        return;
    }
    // activate timers
    Map<Timer, DroolsAction> timers = getEventBasedNode().getTimers();
    if (timers != null) {
        addTimerListener();
        timerInstances = new ArrayList<>(timers.size());
        JobsService jobService = ((KogitoProcessRuntime.Provider) getProcessInstance().getKnowledgeRuntime().getProcessRuntime()).getKogitoProcessRuntime().getJobsService();
        for (Timer timer : timers.keySet()) {
            ProcessInstanceJobDescription jobDescription = ProcessInstanceJobDescription.of(new TimerJobId(timer.getId()), createTimerInstance(timer), getProcessInstance().getStringId(), getProcessInstance().getRootProcessInstanceId(), getProcessInstance().getProcessId(), getProcessInstance().getRootProcessId(), Optional.ofNullable(from).map(KogitoNodeInstance::getStringId).orElse(null));
            timerInstances.add(jobService.scheduleProcessInstanceJob(jobDescription));
        }
    }
    if (getEventBasedNode().getBoundaryEvents() != null) {
        for (String name : getEventBasedNode().getBoundaryEvents()) {
            boolean isActive = ((InternalAgenda) getProcessInstance().getKnowledgeRuntime().getAgenda()).isRuleActiveInRuleFlowGroup("DROOLS_SYSTEM", name, getProcessInstance().getId());
            if (isActive) {
                getProcessInstance().getKnowledgeRuntime().signalEvent(name, null);
            } else {
                addActivationListener();
            }
        }
    }
    ((WorkflowProcessInstanceImpl) getProcessInstance()).addActivatingNodeId((String) getNode().getMetaData().get("UniqueId"));
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) InternalAgenda(org.drools.core.common.InternalAgenda) Timer(org.jbpm.process.core.timer.Timer) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) JobsService(org.kie.kogito.jobs.JobsService) ProcessInstanceJobDescription(org.kie.kogito.jobs.ProcessInstanceJobDescription) TimerJobId(org.kie.kogito.jobs.TimerJobId)

Example 2 with TimerJobId

use of org.kie.kogito.jobs.TimerJobId in project kogito-runtimes by kiegroup.

the class TimerNodeInstance method internalTrigger.

@Override
public void internalTrigger(KogitoNodeInstance from, String type) {
    if (!Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
        throw new IllegalArgumentException("A TimerNode only accepts default incoming connections!");
    }
    triggerTime = new Date();
    ExpirationTime expirationTime = createTimerInstance(getTimerNode().getTimer());
    if (getTimerInstances() == null) {
        addTimerListener();
    }
    ProcessInstanceJobDescription jobDescription = ProcessInstanceJobDescription.of(new TimerJobId(getTimerNode().getTimer().getId()), expirationTime, getProcessInstance().getStringId(), getProcessInstance().getRootProcessInstanceId(), getProcessInstance().getProcessId(), getProcessInstance().getRootProcessId(), Optional.ofNullable(from).map(KogitoNodeInstance::getStringId).orElse(null));
    JobsService jobService = InternalProcessRuntime.asKogitoProcessRuntime(getProcessInstance().getKnowledgeRuntime().getProcessRuntime()).getJobsService();
    timerId = jobService.scheduleProcessInstanceJob(jobDescription);
}
Also used : KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) ProcessInstanceJobDescription(org.kie.kogito.jobs.ProcessInstanceJobDescription) JobsService(org.kie.kogito.jobs.JobsService) ExpirationTime(org.kie.kogito.jobs.ExpirationTime) TimerJobId(org.kie.kogito.jobs.TimerJobId) Date(java.util.Date)

Example 3 with TimerJobId

use of org.kie.kogito.jobs.TimerJobId in project kogito-runtimes by kiegroup.

the class SpringRestJobsServiceTest method testScheduleProcessInstanceJob.

@Test
void testScheduleProcessInstanceJob() {
    when(restTemplate.postForEntity(any(URI.class), any(Job.class), eq(String.class))).thenReturn(ResponseEntity.ok().build());
    ProcessInstanceJobDescription processInstanceJobDescription = ProcessInstanceJobDescription.of(new TimerJobId(123l), ExactExpirationTime.now(), "processInstanceId", "processId");
    tested.scheduleProcessInstanceJob(processInstanceJobDescription);
    ArgumentCaptor<Job> jobArgumentCaptor = forClass(Job.class);
    verify(restTemplate).postForEntity(eq(tested.getJobsServiceUri()), jobArgumentCaptor.capture(), eq(String.class));
    Job job = jobArgumentCaptor.getValue();
    assertThat(job.getId()).isEqualTo(processInstanceJobDescription.id());
}
Also used : ProcessInstanceJobDescription(org.kie.kogito.jobs.ProcessInstanceJobDescription) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Job(org.kie.kogito.jobs.api.Job) TimerJobId(org.kie.kogito.jobs.TimerJobId) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 4 with TimerJobId

use of org.kie.kogito.jobs.TimerJobId in project kogito-runtimes by kiegroup.

the class RestJobsServiceTest method testGetCallbackEndpoint.

@Test
void testGetCallbackEndpoint() {
    ProcessInstanceJobDescription description = ProcessInstanceJobDescription.of(new TimerJobId(), ExactExpirationTime.now(), "processInstanceId", "processId");
    String callbackEndpoint = tested.getCallbackEndpoint(description);
    assertThat(callbackEndpoint).isEqualTo("http://localhost:80/management/jobs/processId/instances/processInstanceId/timers/" + description.id());
}
Also used : ProcessInstanceJobDescription(org.kie.kogito.jobs.ProcessInstanceJobDescription) TimerJobId(org.kie.kogito.jobs.TimerJobId) Test(org.junit.jupiter.api.Test)

Example 5 with TimerJobId

use of org.kie.kogito.jobs.TimerJobId in project kogito-runtimes by kiegroup.

the class VertxJobsServiceTest method testScheduleProcessInstanceJob.

@Test
void testScheduleProcessInstanceJob(@Mock HttpRequest<Buffer> request) {
    when(webClient.post(anyString())).thenReturn(request);
    ProcessInstanceJobDescription processInstanceJobDescription = ProcessInstanceJobDescription.of(new TimerJobId(123l), ExactExpirationTime.now(), "processInstanceId", "processId");
    tested.scheduleProcessInstanceJob(processInstanceJobDescription);
    verify(webClient).post("/jobs");
    ArgumentCaptor<Job> jobArgumentCaptor = forClass(Job.class);
    verify(request).sendJson(jobArgumentCaptor.capture(), any(Handler.class));
    Job job = jobArgumentCaptor.getValue();
    assertThat(job.getId()).isEqualTo(processInstanceJobDescription.id());
    assertThat(job.getExpirationTime()).isEqualTo(processInstanceJobDescription.expirationTime().get());
    assertThat(job.getProcessInstanceId()).isEqualTo(processInstanceJobDescription.processInstanceId());
    assertThat(job.getProcessId()).isEqualTo(processInstanceJobDescription.processId());
}
Also used : ProcessInstanceJobDescription(org.kie.kogito.jobs.ProcessInstanceJobDescription) Handler(io.vertx.core.Handler) TimerJobId(org.kie.kogito.jobs.TimerJobId) Job(org.kie.kogito.jobs.api.Job) Test(org.junit.jupiter.api.Test)

Aggregations

ProcessInstanceJobDescription (org.kie.kogito.jobs.ProcessInstanceJobDescription)6 TimerJobId (org.kie.kogito.jobs.TimerJobId)6 Test (org.junit.jupiter.api.Test)3 KogitoNodeInstance (org.kie.kogito.internal.process.runtime.KogitoNodeInstance)2 JobsService (org.kie.kogito.jobs.JobsService)2 Job (org.kie.kogito.jobs.api.Job)2 Handler (io.vertx.core.Handler)1 URI (java.net.URI)1 Date (java.util.Date)1 InternalAgenda (org.drools.core.common.InternalAgenda)1 InternalKnowledgeRuntime (org.drools.core.common.InternalKnowledgeRuntime)1 BusinessCalendar (org.jbpm.process.core.timer.BusinessCalendar)1 Timer (org.jbpm.process.core.timer.Timer)1 DroolsAction (org.jbpm.workflow.core.DroolsAction)1 WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)1 KogitoProcessRuntime (org.kie.kogito.internal.process.runtime.KogitoProcessRuntime)1 ExpirationTime (org.kie.kogito.jobs.ExpirationTime)1 TimerInstance (org.kie.kogito.timer.TimerInstance)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1