3 Replies Latest reply on Nov 17, 2014 1:47 AM by swiderski.maciej

    How to restart asynchronous WorkItem

    tgrat

      Hello,

       

      We have own WorkItem which is written like in example from "Chapter 24. Concurrency and asynchronous execution" and based on jbpm/WebServiceWorkItemHandler.java at 6.1.x · droolsjbpm/jbpm · GitHub

      In our example we try to connect to external WS. We try connect a few times, because we want to protect situation when external WS is not available. When we stop JBPM embedded engine during connection process performed in asynchronous WorkItem and restart JBPM engine our asynchronous WokrItem doesn't start again. We use JPA. The engine correctly continue our process when we restart JBPM engine and the BPM process executes other WokrItems.

      1) What should we do to restart not finished asynchronous work item after or during JBPM engine restart?

      2) Is it possible to restart manually not finished asynchronous work item (find them and execute again after some external action) when engine still working?

       

      Best regards,

      Tomek

        • 1. Re: How to restart asynchronous WorkItem
          swiderski.maciej

          have 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

          1 of 1 people found this helpful
          • 2. Re: Re: How to restart asynchronous WorkItem
            tgrat

            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

              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?