-
1. Re: How to restart asynchronous WorkItem
swiderski.maciej Nov 14, 2014 2:03 AM (in response to tgrat)1 of 1 people found this helpfulhave you looked at use of jbpm executor for async jobs? That way you'll get automatically retries and error handling. Moreover if you use jbpm console then you will get additional view into what has been executed and options to operate on jobs - like auto restart of running jobs in case server went down while executing, option to cancel jobs, option to requeue job when it failed and all retries attempt were exceeded (note some of these options will be available in 6.2).
As to what you try to do, it can be done via API - there are options to retrigger given node instance, it was recently answered on this thread
HTH
-
2. Re: Re: How to restart asynchronous WorkItem
tgrat Nov 14, 2014 9:30 AM (in response to swiderski.maciej)Hello Maciej,
1) For question 2: We try to use example from thread . We still have version with multi-thread described in Chapter 24. Concurrency and asynchronous execution(Asynchronous handlers). Our source code:
ProcessInstance processInstance = ksession.getProcessInstance(processIpoConfNumber); // processInstance.signalEvent(type, event); WorkItem workItem = ksession.execute(new GenericCommand<WorkItem>() { @Override public WorkItem execute(Context context) { KieSession ksession = ((KnowledgeCommandContext) context).getKieSession(); WorkflowProcessInstance pi = (WorkflowProcessInstance) ksession.getProcessInstance(ipoEntity.getProcessIpoConfNumber()); if (pi != null) { Collection<NodeInstance> nodes = pi.getNodeInstances(); try { NodeInstance nodeInstance = nodes.iterator().next(); WorkItemNodeInstance workItemNodeInstance = (WorkItemNodeInstance) nodeInstance; WorkItem workItem = workItemNodeInstance.getWorkItem(); return workItem; } catch (NoSuchElementException nsee) { /** * this is about retrieving the currently active node. if it fails the process is probably * isn't working but the execution status remained active for some reason. This makes the * client to check for the currently active node constantly. */ } } return null; } }); if (workItem != null) { WorkItemManager wiManager = (WorkItemManager) ksession.getWorkItemManager(); // wiManager.internalExecuteWorkItem(workItem); WorkItemNodeInstance workItemNodeInstance = (WorkItemNodeInstance) getNodeInstance(workItem, (WorkflowProcessInstance) processInstance); switch (workItem.getState()) { case WorkItem.COMPLETED: workItemNodeInstance.workItemCompleted(workItem); break; case WorkItem.ABORTED: workItemNodeInstance.workItemAborted(workItem); break; default: workItemNodeInstance.retrigger(true); } }
Unfortunately we have got java.lang.NullPointerException. It's because our processInstance always has kruntime == null. Do we need set something else?
2) For question 1: Do you have any example how to use this new jbpm executor from your blog for embedded eclipse version like Domain-specific Processes? We have found discussion on the same subject but no one didn't respond .
Best regards,
Tomek
-
3. Re: How to restart asynchronous WorkItem
swiderski.maciej Nov 17, 2014 1:47 AM (in response to tgrat)How is that code invoked? Is it part of the work item handler? Would be good if you could provide stacktrace se we can see where the NPE is encountered. When it comes to kruntime being null it means that you try to work on process instance that is already disconnected - meaning outside of a transaction. When you move entire code into the command's execute method it should not throw any NPE.
When it comes to executor being used outside you can find some test cases here that might be helpful. So do you run within jbpm-console or you have it embedded in your own application?