[jboss-user] [jBPM] - Re: saving state after workitem
Chris Melas
do-not-reply at jboss.com
Fri Jan 27 15:15:08 EST 2012
Chris Melas [https://community.jboss.org/people/melc] created the discussion
"Re: saving state after workitem"
To view the discussion, visit: https://community.jboss.org/message/649187#649187
--------------------------------------------------------------
Hello,
So for the following case,
start->workItem1->script1->workItem2->script2->end
a) Yes by reaching script2 the workitem1 is completed and its entry is deleted from the workiteminfo table. It also means that workitem2 has executed and by failing at script2 you can only examine the NodeInstanceLog table to figure out what has happened and maybe take some action. However i think the process instance at that stage will not resume since there will be no associated workitem persisted to execute/complete.
b) If workitem1 completes then it is deleted from the workiteminfo. But generally if you pickup a persisted work item (other than a work item associated with a human task....because a human task has an entry in the task table as well and needs a bit more care i.e. whether the task has completed or not etc) from the database you can either re execute it or complete it. These are achieved by quering the database table workiteminfo retrieving the object associated with the work item you want and calling either
YourWorkItemHandler yourWorkItemHandler = new YourWorkItemHandler();
yourWorkItemHandler.executeWorkItem(workItemFromDB, ksession.getWorkItemManager());
+to re execute the work item+
+or complete it+
ksession.getWorkItemManager().completeWorkItem(workItemFromDB, workItemFromDB.getParameters()/*or some other params etc*/);
The following bootstrap code can be used for non human task work items that have not completed (i.e. system crashed while running) and choosing to re execute them, as well as human task work items that have completed and the system crashed right after the human task completion but before entering the next wait point.
private void bootstrapForWorkItems() {
EntityManagerFactory emf = null;
EntityManager tempEntityManager = null;
List results = null;
try {
emf = (EntityManagerFactory) ksession.getEnvironment().get(EnvironmentName.ENTITY_MANAGER_FACTORY);
tempEntityManager = emf.createEntityManager();
results = tempEntityManager.createNativeQuery("SELECT w.* FROM WorkItemInfo w inner join Task t on t.workItemId=w.workItemId where t.status='Completed' union SELECT w.* FROM WorkItemInfo w where name <> 'Human Task'", WorkItemInfo.class).getResultList();
} finally {
if (tempEntityManager != null) {
tempEntityManager.close();
}
}
if (results != null) {
for (Object resultObject : results) {
WorkItemInfo workItemInfo = (WorkItemInfo) resultObject;
WorkItem workItem = workItemInfo.getWorkItem(ksession.getEnvironment());
if (workItem.getName().equals("YourWorkItem1")) {
YourWorkItem1WorkItemHandler yourWorkItem1WorkItemHandler = new YourWorkItem1WorkItemHandler(ksession);
yourWorkItem1WorkItemHandler.executeWorkItem(workItem, ksession.getWorkItemManager());
}
if (workItem.getName().equals("YourWorkItem2")) {
YourWorkItem2WorkItemHandler yourWorkItem1WorkItemHandler = new YourWorkItem2WorkItemHandler(ksession);
YourWorkItem2WorkItemHandler.executeWorkItem(workItem, ksession.getWorkItemManager());
} else if (workItem.getName().equals("Human Task")) {
/*i'm not sure about the workItem.getParameters() here, might be getting the params of the previous human task....might need a little fixing*/
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), workItem.getParameters());
//or
//call correct workitemhandler for this task and re execute
}
}//for - results
}//if - results
}//method
Of course in some cases you may choose to act differently i.e.instead of re executing a work item, complete it because you checked your business logic (i.e. checked your system's database) and realised that data has been commited or web service has been called but the jbpm engine system crashed right before erasing the workitem etc.
c) By quickly looking at your code and log i see that workitem1 executed then script1, followed by workitem2 and script2 .... so i think it went fine. I'm not sure i get the problem.
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/649187#649187]
Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120127/615e9019/attachment.html
More information about the jboss-user
mailing list