6 Replies Latest reply on Jul 26, 2010 2:38 PM by nechukin

    Recover async activities after jBPM4 restart

    nechukin

      Hi all,

       

      I have a workflow based on async activities and wait states. Now I'm investigating the jBPM failure scenario.

       

       

      As I see, if process instance was interrupted by system failure in some activity, it will recover in the previous saved state (expectable), but process execution will not be resumed automatically. My attempts to play with ExecutionImpl methods mostly lead to messages that "process state is not active: async" or NPE while accessing Environent instance.

       

      Is there a way to resume an async executions that were broken by system failure?

       

      (Same question is relevant for wait states, but I haven't tried failure in them yet).

       

       

      Thanks in advance.

        • 1. Re: Recover async activities after jBPM4 restart
          mwohlf

          Hi Georgy,

          my understanding is that async  executions are picked up by the job executor, so the following might  work and "restart" the excution for an async execution which was "lost".

           

          ManagementService managementService = processEngine.getManagementService();

          Job job = managementService.createJobQuery().processInstanceId(id).uniqueResult();

          managementService.executeJob(job.getId());

           

          ...it's just a guess

          • 2. Re: Recover async activities after jBPM4 restart
            nechukin

            Yes, this is exactly what I've tried, and it works, but it raises the next question: how to get the list of all process instance IDs?

             

            I guess I can get them directly from DB, but I don't think that it's the correct way to do this...

            • 3. Re: Recover async activities after jBPM4 restart
              mwohlf

              hmm... what about something like this:

               

              ManagementService managementService = processEngine.getManagementService();
              List<ProcessInstance> list = processEngine.getExecutionService().createProcessInstanceQuery().list();

              for (ProcessInstance processInstance : list) {
                Job job = managementService.createJobQuery().processInstanceId(processInstance.getId()).uniqueResult();

                managementService.executeJob(job.getId());

              }

               

              but what I don't understand is this:

              shouldn't the job executor pick up this anyways in its next cycle, why do we need to do this manually?

              • 4. Re: Recover async activities after jBPM4 restart
                nechukin

                Thanks a lot Michael, I will try this. Seems to be ok.

                 

                Regarding the question about job executor. On my understending it should... but it doesn't.

                • 5. Re: Recover async activities after jBPM4 restart
                  mwohlf

                  just an idea: maybe the reason why they are not picked up is because they ran out of retries?

                  the "findFirstAcquirableJob" query the jobExecutor uses on startup has a where clause: "... and job.retries > 0 ..."

                  guess this makes sense since it would probably pick up tons of old jobs?

                  • 6. Re: Recover async activities after jBPM4 restart
                    nechukin

                    Solution found. The reason why jobs were not recovered automatically is the too long lock timeout in job executor settings:

                     

                         <process-engine-context>
                             <job-executor threads="4" idle="1000" idle-max="120000" lock="3600000"/>
                         </process-engine-context>
                    

                     

                    I changed the lock to 10000 (10 seconds) and now it's recovering normally.