4 Replies Latest reply on Jun 11, 2014 10:31 AM by b.r

    TaskDeadlineService unschedule problem

    b.r

      Hello,

       

      Recently we were trying to use jbpm deadline mechanism and run into problematic behaviour coused by unschedule implementation in TaskDeadlinesServiceImpl. We are using PerRequestSessionManager and quartz to persist notification jobs od db. To reproduce problem we fallow below steps:

      1. We start multiple instances of processes with notifications defined (all deadlines are persisted on db, each having single trigger on quartz schema)

      2. .complete is called on one of the tasks (before deadline) triggering unschedule on its deadlines

      3. unschedule deletes triggers for all active deadlines in all processes (escalated flag stays at 0 for deadlines not connected to triggering task)

      4. Now the only time those notifications are executed is when we are building session manager (in our case this is once per application restart)

       

      Is this unschedule behaviour intentional and if yes is there an easy way to use custom implementation of TaskDeadlinesService?

        • 1. Re: TaskDeadlineService unschedule problem
          swiderski.maciej

          do you mean that unschedule of a given task removes all other deadlines from timer service? If that's the case please file jira as it's certainly a bug.

          • 2. Re: Re: TaskDeadlineService unschedule problem
            b.r

            In our case yes, it removes all deadlines from timer service but I am not sure if it's a bug as those deadlines stay unescalated on jbpm schema.

             

            After debugging unschedule it turns out that our problem is coused by this piece of code in TaskDeadlinesServiceImpl.unschedule:

             

            if (timerService != null && timerService instanceof GlobalTimerService) {
                
                 if (type == DeadlineType.START) {
                      List<Deadline> startDeadlines = deadlines.getStartDeadlines();
                      List<DeadlineSummaryImpl> resultList = (List<DeadlineSummaryImpl>)persistenceContext.queryInTransaction("UnescalatedStartDeadlines", ClassUtil.<List<DeadlineSummaryImpl>>castClass(List.class));      
                      for (DeadlineSummaryImpl summary : resultList) {
                          TaskDeadlineJob deadlineJob = new TaskDeadlineJob(summary.getTaskId(), summary.getDeadlineId(), DeadlineType.START);
                          logger.debug("unscheduling timer job for deadline {} {} and task {}  using timer service {}", deadlineJob.getId(), summary.getDeadlineId(), taskId, timerService);
                          JobHandle jobHandle = jobHandles.remove(deadlineJob.getId());
                          if (jobHandle == null) {      
                               jobHandle = ((GlobalTimerService) timerService).buildJobHandleForContext(new TaskDeadlineJobContext(deadlineJob.getId()));
                          }
                          timerService.removeJob(jobHandle);
                          (...)
            
            
            
            

             

            resultList returns all deadlines for all active tasks and than in for loop there is .removeJob called on all of them.

             

            UnescalatedStartDeadlines query in our application looks like this:

            select
                 new org.jbpm.services.task.query.DeadlineSummaryImpl(
                 t.id,
                 d.id,
                 d.date)
            from
                TaskImpl t,
                DeadlineImpl d
            where
                t.archived = 0 and
                d in elements( t.deadlines.startDeadlines ) and
                d.escalated = 0
            order by
                d.date
            
            
            

            and from what i can see it's same in current master branch. Anyway I have filed the jira bug for this issue: [JBPM-4362] TaskDeadlinesServiceImpl unschedule method deletes triggers for all active deadlines in all tasks - JBoss Is…

            • 3. Re: TaskDeadlineService unschedule problem
              swiderski.maciej

              you're right, the main issue was that it did not filter out deadlines and unscheduled all of them, bug indeed. Already fixed on master. Thanks for reporting and detailed analysis.

              • 4. Re: TaskDeadlineService unschedule problem
                b.r

                Fix has solved the issue.