cancel
Showing results for 
Search instead for 
Did you mean: 

Activiti REST start process instance is -not- asynch?

dmill
Champ in-the-making
Champ in-the-making
Hey guys.

I'm using activiti-rest to handle our workflow needs. One of my issues is that when I start a process instance with "runtime/process-instances" this works without problem but it will only send a response back to the client once all the tasks that can be executed are done running.
This is a huge issue as some of the tasks take a long time to complete (video encoding, etc..) and it just makes the client hang forever.
Is there a reason for this?

For full disclosure here's the process definition:


  <process id="node-pre-process" name="Generates node information">
    <startEvent id="theStart" />
    <sequenceFlow id="flow1" sourceRef="theStart" targetRef="consoleMeta"></sequenceFlow>
    <serviceTask id="consoleMeta" name="Retrieve Meta Data" activiti:type="shell" >
     <extensionElements>
      <activiti:field name="command">
          <activiti:expression>${yiiCommand}</activiti:expression>
      </activiti:field>
     <activiti:field name="arg1" stringValue="node/add-meta" />
     <activiti:field name="arg2">
          <activiti:expression>${nodeKey}</activiti:expression>
      </activiti:field>
     </extensionElements>
   </serviceTask>          
    <sequenceFlow id="flow2" sourceRef="consoleMeta" targetRef="consoleBase"></sequenceFlow>
    <serviceTask id="consoleBase" name="Generate Base Image"  activiti:type="shell" >
     <extensionElements>
      <activiti:field name="command">
          <activiti:expression>${yiiCommand}</activiti:expression>
      </activiti:field>
     <activiti:field name="arg1" stringValue="node/generate-base" />
     <activiti:field name="arg2">
          <activiti:expression>${nodeKey}</activiti:expression>
      </activiti:field>
     </extensionElements>
   </serviceTask>          
    <endEvent id="theEnd"/>
    <sequenceFlow id="flow3" sourceRef="consoleBase" targetRef="theEnd"></sequenceFlow>
  </process>

I essentially don't get a response back from activiti-rest until both of these commands are executed and done running. Weird or normal?
4 REPLIES 4

trademak
Star Contributor
Star Contributor
Hi,

That's normal with this process definition, because tasks run synchronously by default.
You can add an async attribute to a service task to make it asynchronous and then the REST service will send a response quickly.

Best regards,

dmill
Champ in-the-making
Champ in-the-making
Great thanks for the info!! Do you know if this works with shell tasks? As the following doesn't seem to work (I added an async tag to the second Service task):


<process id="node-pre-process" name="Generates node information">
    <startEvent id="theStart" />
    <sequenceFlow id="flow1" sourceRef="theStart" targetRef="consoleMeta"></sequenceFlow>
    <serviceTask id="consoleMeta" name="Retrieve Meta Data" activiti:type="shell" >
        <extensionElements>
            <activiti:field name="command">
                <activiti:expression>${yiiCommand}</activiti:expression>
            </activiti:field>
     <activiti:field name="arg1" stringValue="node/add-meta" />
     <activiti:field name="arg2">
                <activiti:expression>${nodeKey}</activiti:expression>
            </activiti:field>
        </extensionElements>
    </serviceTask>
    <sequenceFlow id="flow2" sourceRef="consoleMeta" targetRef="consoleBase"></sequenceFlow>
    <serviceTask id="consoleBase" name="Generate Base Image"  activiti:type="shell" activiti:async="true"  >
        <extensionElements>
            <activiti:field name="command">
                <activiti:expression>${yiiCommand}</activiti:expression>
            </activiti:field>
            <activiti:field name="arg1" stringValue="node/generate-base" />
            <activiti:field name="arg2">
                <activiti:expression>${nodeKey}</activiti:expression>
            </activiti:field>
        </extensionElements>
    </serviceTask>
    <endEvent id="theEnd"/>
    <sequenceFlow id="flow3" sourceRef="consoleBase" targetRef="theEnd"></sequenceFlow>
</process>

dmill
Champ in-the-making
Champ in-the-making
My bad it actually works as expected! thanks

dmill
Champ in-the-making
Champ in-the-making
I just realized that sync doesn't take expressions. This is a bit of an issue if you want to unit test your workflows. You can't programmatically set the async to false when running unit tests but keep it at true for production use. Smiley Sad