Search in sources :

Example 1 with BaseWorkUnit

use of org.kie.kogito.services.uow.BaseWorkUnit in project kogito-runtimes by kiegroup.

the class AsyncEventNodeInstance method internalTrigger.

@Override
public void internalTrigger(KogitoNodeInstance from, String type) {
    addEventListeners();
    addAsyncStatus();
    final InternalProcessRuntime processRuntime = (InternalProcessRuntime) getProcessInstance().getKnowledgeRuntime().getProcessRuntime();
    // Deffer the timer scheduling to the end of current UnitOfWork execution chain
    processRuntime.getUnitOfWorkManager().currentUnitOfWork().intercept(new BaseWorkUnit<>(this, instance -> {
        ExpirationTime expirationTime = ExactExpirationTime.of(ZonedDateTime.now().plus(1, ChronoUnit.MILLIS));
        ProcessInstanceJobDescription jobDescription = ProcessInstanceJobDescription.of(new AsyncJobId(instance.getStringId()), expirationTime, instance.getProcessInstance().getStringId(), instance.getProcessInstance().getRootProcessInstanceId(), instance.getProcessInstance().getProcessId(), instance.getProcessInstance().getRootProcessId(), Optional.ofNullable(from).map(KogitoNodeInstance::getStringId).orElse(null));
        JobsService jobService = processRuntime.getJobsService();
        String jobId = jobService.scheduleProcessInstanceJob(jobDescription);
        setJobId(jobId);
    }, i -> {
    }, WorkUnit.LOW_PRIORITY));
}
Also used : JobsService(org.kie.kogito.jobs.JobsService) Logger(org.slf4j.Logger) ProcessInstanceJobDescription(org.kie.kogito.jobs.ProcessInstanceJobDescription) WorkUnit(org.kie.kogito.uow.WorkUnit) ZonedDateTime(java.time.ZonedDateTime) NodeInstance(org.kie.api.runtime.process.NodeInstance) AsyncJobId(org.kie.kogito.jobs.AsyncJobId) LoggerFactory(org.slf4j.LoggerFactory) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) BaseWorkUnit(org.kie.kogito.services.uow.BaseWorkUnit) Objects(java.util.Objects) ChronoUnit(java.time.temporal.ChronoUnit) ProcessInstance(org.kie.kogito.process.ProcessInstance) Node(org.kie.api.definition.process.Node) ASYNC_WAITING(org.jbpm.ruleflow.core.Metadata.ASYNC_WAITING) InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime) NodeInstanceContainer(org.jbpm.workflow.instance.NodeInstanceContainer) EventNodeInstance(org.jbpm.workflow.instance.node.EventNodeInstance) KogitoEventListener(org.kie.kogito.internal.process.event.KogitoEventListener) Optional(java.util.Optional) ExactExpirationTime(org.kie.kogito.jobs.ExactExpirationTime) ExpirationTime(org.kie.kogito.jobs.ExpirationTime) ProcessInstanceJobDescription(org.kie.kogito.jobs.ProcessInstanceJobDescription) JobsService(org.kie.kogito.jobs.JobsService) AsyncJobId(org.kie.kogito.jobs.AsyncJobId) InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime) ExactExpirationTime(org.kie.kogito.jobs.ExactExpirationTime) ExpirationTime(org.kie.kogito.jobs.ExpirationTime)

Aggregations

ZonedDateTime (java.time.ZonedDateTime)1 ChronoUnit (java.time.temporal.ChronoUnit)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 InternalProcessRuntime (org.jbpm.process.instance.InternalProcessRuntime)1 ASYNC_WAITING (org.jbpm.ruleflow.core.Metadata.ASYNC_WAITING)1 NodeImpl (org.jbpm.workflow.core.impl.NodeImpl)1 NodeInstanceContainer (org.jbpm.workflow.instance.NodeInstanceContainer)1 EventNodeInstance (org.jbpm.workflow.instance.node.EventNodeInstance)1 Node (org.kie.api.definition.process.Node)1 NodeInstance (org.kie.api.runtime.process.NodeInstance)1 KogitoEventListener (org.kie.kogito.internal.process.event.KogitoEventListener)1 KogitoNodeInstance (org.kie.kogito.internal.process.runtime.KogitoNodeInstance)1 AsyncJobId (org.kie.kogito.jobs.AsyncJobId)1 ExactExpirationTime (org.kie.kogito.jobs.ExactExpirationTime)1 ExpirationTime (org.kie.kogito.jobs.ExpirationTime)1 JobsService (org.kie.kogito.jobs.JobsService)1 ProcessInstanceJobDescription (org.kie.kogito.jobs.ProcessInstanceJobDescription)1 ProcessInstance (org.kie.kogito.process.ProcessInstance)1 BaseWorkUnit (org.kie.kogito.services.uow.BaseWorkUnit)1