cancel
Showing results for 
Search instead for 
Did you mean: 

Activiti current task behaviour with asynchronous tasks

sdesbure
Champ in-the-making
Champ in-the-making
Hello,
I'm using activiti mostly with asynchronous services tasks. The issue is if I "simply" chain these tasks, the current task id (which seems to be relied to act_id_ column in act_ru_execution) is not updated.
In order to have this update, I've added a receive task for each asynch service task and now it's updated.
But I found this "solution" not good because :
  • it complexify a lot the process (I add a parallel gateway before and after each pair of tasks)
  • testability is worse because I didn't figured out how to simply test one service task (the service task "signal" the receive task but to know it, we have to start the full process…)
Is there a better way to do that (know the current task in a process from the REST interface with asynchronous tasks)?

thanks!
5 REPLIES 5

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

use http://activiti.org/userguide/index.html#_hooking_into_process_parsing to add automatic logging before each service task.

Regards
Martin

sdesbure
Champ in-the-making
Champ in-the-making
Hello Martin and thanks for answering.
What you propose is to add an automatic logging service that would for example automatically insert into the database where we are?
Is that right?

Regards,

Sylvain

yes.
You have to take into account transactions too. (That's the reason why HI tables update is not seen from outside.)

Regards
Martin

jbarrez
Star Contributor
Star Contributor
I'm not sure i'm following your use case:

"The issue is if I "simply" chain these tasks, the current task id"

What do you mean? When it's asynchronous, the current state can change _any time_, cause the processing will happen at a later point in the future.

sdesbure
Champ in-the-making
Champ in-the-making
Hello,
it wasn't clear I understand Smiley Wink
So, here's the issue : I'm using on the same workflow synchronous and asynchronous services tasks.
After passing the asynchronous tasks, the DB (act_id_ row on act_ru_execution table) is updated only on asynchronous tasks which lead to confusion. Here's an example (code can be found on github https://github.com/sdesbure/activiti-issue-asynch-task😞
<code>DEBUG MyUnitTest - starting test
DEBUG MyUnitTest - runtime service: org.activiti.engine.impl.RuntimeServiceImpl@7244001e
DEBUG SyncTask - entering SyncTask
DEBUG SyncTask - active_activiti:
DEBUG SyncTask -  * found per execution : firstTask
DEBUG SyncTask -  * found via SQL (same as REST request): none
DEBUG SyncTask - finished SyncTask
DEBUG MyUnitTest - processInstance ID: 4
DEBUG AsyncTask - entering AsyncTask
DEBUG AsyncTask -  * found per execution : secondTask
DEBUG AsyncTask -  * found via SQL (same as REST request): secondTask
DEBUG AsyncTask - finished AsyncTask
DEBUG AsyncTask - entering AsyncTask
DEBUG AsyncTask -  * found per execution : thirdTask
DEBUG AsyncTask -  * found via SQL (same as REST request): thirdTask
DEBUG AsyncTask - finished AsyncTask
DEBUG SyncTask - entering SyncTask
DEBUG SyncTask - active_activiti:
DEBUG SyncTask -  * found per execution : fourthTask
DEBUG SyncTask -  * found via SQL (same as REST request): thirdTask
DEBUG SyncTask - finished SyncTask
DEBUG SyncTask - entering SyncTask
DEBUG SyncTask - active_activiti:
DEBUG SyncTask -  * found per execution : fifthTask
DEBUG SyncTask -  * found via SQL (same as REST request): thirdTask
DEBUG SyncTask - finished SyncTask
DEBUG SyncTask - entering SyncTask
DEBUG SyncTask - active_activiti:
DEBUG SyncTask -  * found per execution : sixthTask
DEBUG SyncTask -  * found via SQL (same as REST request): thirdTask
DEBUG SyncTask - finished SyncTask
INFO  DefaultAsyncJobExecutor - Shutting down the default async job executor [org.activiti.engine.impl.asyncexecutor.DefaultAsyncJobExecutor].</code>

with the following bpmn:
<code><?xml version="1.0" encoding="UTF-8"?>

<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
             xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlnsSmiley Surprisedmgdc="http://www.omg.org/spec/DD/20100524/DC"
             xmlnsSmiley Surprisedmgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
             expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">

    <process id="my-process">

        <startEvent id="start" />
        <sequenceFlow id="flow1" sourceRef="start" targetRef="firstTask" />

        <serviceTask id="firstTask" name="Activiti is awesome! 1" activiti:delegateExpression="${syncTask}" />
        <sequenceFlow id="flow2" sourceRef="firstTask" targetRef="secondTask" />

        <serviceTask id="secondTask" name="Activiti is awesome! 2" activiti:async="true" activiti:delegateExpression="${asyncTask}" />
        <sequenceFlow id="flow3" sourceRef="secondTask" targetRef="thirdTask" />

        <serviceTask id="thirdTask" name="Activiti is awesome! 3" activiti:async="true" activiti:delegateExpression="${asyncTask}" />
        <sequenceFlow id="flow4" sourceRef="thirdTask" targetRef="fourthTask" />

   
        <serviceTask id="fourthTask" name="Activiti is awesome! 4" activiti:delegateExpression="${syncTask}" />
        <sequenceFlow id="flow5" sourceRef="fourthTask" targetRef="fifthTask" />

   
        <serviceTask id="fifthTask" name="Activiti is awesome! 5" activiti:delegateExpression="${syncTask}" />
        <sequenceFlow id="flow6" sourceRef="fifthTask" targetRef="sixthTask" />

        <serviceTask id="sixthTask" name="Activiti is awesome! 6" activiti:delegateExpression="${syncTask}" />
        <sequenceFlow id="flow7" sourceRef="sixthTask" targetRef="end" />
   

        <endEvent id="end" />
    </process>
</definitions>
</code>

the solution one of my colleague found was to add a receives task for each service task which allow the update of the DB but I find this solution very ugly.
I would just want to update the DB for every service task if the row exists and I would like to know what's can be done.

The result I would like to have would be:
<code>DEBUG MyUnitTest - starting test
DEBUG MyUnitTest - runtime service: org.activiti.engine.impl.RuntimeServiceImpl@7244001e
DEBUG SyncTask - entering SyncTask
DEBUG SyncTask - active_activiti:
DEBUG SyncTask -  * found per execution : firstTask
DEBUG SyncTask -  * found via SQL (same as REST request): none
DEBUG SyncTask - finished SyncTask
DEBUG MyUnitTest - processInstance ID: 4
DEBUG AsyncTask - entering AsyncTask
DEBUG AsyncTask -  * found per execution : secondTask
DEBUG AsyncTask -  * found via SQL (same as REST request): secondTask
DEBUG AsyncTask - finished AsyncTask
DEBUG AsyncTask - entering AsyncTask
DEBUG AsyncTask -  * found per execution : thirdTask
DEBUG AsyncTask -  * found via SQL (same as REST request): thirdTask
DEBUG AsyncTask - finished AsyncTask
DEBUG SyncTask - entering SyncTask
DEBUG SyncTask - active_activiti:
DEBUG SyncTask -  * found per execution : fourthTask
DEBUG SyncTask -  * found via SQL (same as REST request): fourthTask
DEBUG SyncTask - finished SyncTask
DEBUG SyncTask - entering SyncTask
DEBUG SyncTask - active_activiti:
DEBUG SyncTask -  * found per execution : fifthTask
DEBUG SyncTask -  * found via SQL (same as REST request): fifthTask
DEBUG SyncTask - finished SyncTask
DEBUG SyncTask - entering SyncTask
DEBUG SyncTask - active_activiti:
DEBUG SyncTask -  * found per execution : sixthTask
DEBUG SyncTask -  * found via SQL (same as REST request): sixthTask
DEBUG SyncTask - finished SyncTask
INFO  DefaultAsyncJobExecutor - Shutting down the default async job executor [org.activiti.engine.impl.asyncexecutor.DefaultAsyncJobExecutor].</code>