Dead Letter - Retrieve dead jobs associated to a specific task

Hello,

I try to find the best way to retrieve a sub-set of jobs in the dead letter using the Java API.
My use-case is:

  • An asynchronous service task (Service Task Id: MY_SERVICE_TASK) is in charge of communicating with an external system
  • This external system is down.
  • After max retries, all MY_SERVICE_TASK jobs will be moved to the dead letter
  • When the system is up (out of scope), I want to retry only the jobs associated to this failed MY_SERVICE_TASK task

I have used the ManagementService API to retrieve all jobs, some filterings may be done using its createDeadLetterJobQuery() method, but I haven’t found a way to filter by Service Task Id (or name).

What is the best way to do this filtering?

Thanks in advance for your help :slight_smile:
Best Regards
William

Hi William,

Activity id is stored in the execution. You can use execution query to get all executions which wait on the service task. It is a set of all execution for jobs which are active, suspended, failed.
After that you can use DeadLetterJobQuery.
Another way is to create your own command to query for failed jobs with activityId.

Regards
Martin

Wow, quick answer, thanks Martin :slight_smile:
Thanks for the info, I didn’t understand that Task Id is the ActivityId.
I have tried what you suggest, but I’m not able to retrieve this list. Here’s what I did:

  • retrieve all executions:
    List<Execution> allExecutions = runtimeService.createExecutionQuery().list();
    Yes, in this list, I’m able to retrieve some ActivityIds = “MY_SERVICE_TASK”.
  • try to retrieve all executions with the corresponding ActivityId:
    List<Execution> myServiceExecutions = runtimeService.createExecutionQuery().activityId("MY_SERVICE_TASK").list();
    Unfortunately, this list is empty…

I do certainly something wrong, but I don’t understand what. :frowning:

And another point: I can see isEnded() or isSuspended() methods in the execution, but no way to find any info about the fact that this execution is failed or dead. I believed it was isEnded(), but it isn’t the case.

Thanks again for your help
Best Regards
William

I’m able to retrieve my tasks using a native query:
List<Execution> myServiceExecutionsQuery = runtimeService.createNativeExecutionQuery().sql("Select * from ACT_RU_EXECUTION where ACT_ID_ = 'MY_SERVICE_TASK'").list();
Using this query, I retrieve the 2 jobs returned in the previous allExecutions list.

This query should be equivalent to the previous command:
List<Execution> myServiceExecutions = runtimeService.createExecutionQuery().activityId("MY_SERVICE_TASK").list();
So why is myServiceExecutions empty??

But I have the same question: even with this list, I’m unable to know if an execution has failed or not, except if I compare one by one this list with the list present in the dead letter, but it isn’t really optimized :slight_smile:
Or perhaps should I add in my Query a test on the DEADLETTER_JOB_COUNT_ field also?
Something like that
runtimeService.createNativeExecutionQuery().sql("Select * from ACT_RU_EXECUTION where ACT_ID_ = 'MY_SERVICE_TASK' and DEADLETTER_JOB_COUNT_ > 0").list();

In all cases, I would prefer to avoid a Native Query if possible to be independent from SQL but also from possible future DB Schema changes, to avoid potential SQL injection threat, and also to benefit from pagination.

Thanks

1 Like

BTW
How can I do a verification of the Query parameters to avoid SQL injection (in my ActivityId String mainly) considering that I haven’t access to your Connection (so no way to use the PrepareStatement)?
Thanks

Hi William.

The “problem” with

is that it adds isActive=true condition to the select.

WHERE RES.ACT_ID_ = ? and RES.IS_ACTIVE_ = ?

Native query can work fine. Or you can just select failed jobs, get executionId from them and select execution according to these ids (and check activityId).
→ But I do not like any of the proposals.
The best option could be to create a pull request with dead letter job query extension.

Regards
Martin

Thanks Martin.
I agree with you that none of the solutions is optimised.
I will create a pull request to extend the dead letter query in order to retrieve a list of jobs for a specific activity Id.
Without loop and with pagination if possible (considering that a lot of jobs may be in the dead letter if an external system was down).
Best Regards
William

Issue open here