Clean up processes that have been running too long

What options do I have to regularly cleanup processes that have been running too long?

My usecase is a process where a user is required to provide additional data upon a request. If he fails to do so within a certain time, the process sends a new request for user data. However, we also need to make sure processes do not hang forever in this kind of loop e.g. if a user simply ignores the process and does not come back- we do not want too many obsolete processes.

  1. Is session timeout (e.g. via web.xml) sufficient to also suspend still active processes in Camunda?

  2. Or is it common practice to model a global timeout around the main process in the model? (I have seen this before, but to me it seems to be a standard problem that not everyone should have to model on their own…)

  3. Or should I rather handle that via a timeout on every activity that could severely delay the process? (In my example, this would probably mean a timeout/counter on the loop request for userdata, but considering other things that could happen, we would probably need one more for network problems etc., so this does not seem too elegant either).

Thanks for your replies!

Hi @auringo,

I would go with 2 and add an event subprocess, starting with an interrupting timer event:

https://cawemo.com/shares/dc0b493c-f3e6-403b-ac90-217dfe0ca58e

Hope this helps,

Ingo

1 Like

Thank you, Ingo! Still, I think this is such a common case that it would be nice if it could be solved via configuration.

See the subprocess as a visible configuration to handle timed events.

If you prefer, you can program some listeners that add a job, create a job handler to handle the timeout and hide the functionality in your code.

But there is no default configuration as it is generally expected to run all process instances from a start event to an end event.

Hi @Ingo_Richtsmeier, from your link https://cawemo.com/shares/dc0b493c-f3e6-403b-ac90-217dfe0ca58e

How to set dynamically Date/Duration in TimerEvent(“Waited too long”) in subprocess. Lets say you have a date field in process variable and assign it to timerevent Date. How to achieve it?

Hi @aravindhrs,

just use the variable in the expression and pass the value at process start:

curl -X POST \
  http://localhost:8080/engine-rest/process-definition/key/DynamicTimerInEventSubprocess/start \
  -H 'Content-Type: application/json' \
  -d '{
  "variables": {
    "cleanUpTime" : {
        "value" : "2019-01-23T20:10:00.000+0100",
        "type": "Date"
    }
  }
}' 

The start event of the event based subprocess looks like:

  <bpmn:startEvent id="StartEvent_1yptb9z" name="timer due">
    <bpmn:outgoing>SequenceFlow_0bpmkj6</bpmn:outgoing>
    <bpmn:timerEventDefinition>
      <bpmn:timeDate xsi:type="bpmn:tFormalExpression">${cleanUpTime}</bpmn:timeDate>
    </bpmn:timerEventDefinition>
  </bpmn:startEvent>

Cheers, Ingo

"value" : "2019-01-23T20:10:00.000+0100" of that date field is String Type right?

@Ingo_Richtsmeier, it doesn’t worked. Getting error like cannot resolve identifier for ${resolveDate}

Hi @aravindhrs,

sorry, but this information is not enough to help you. BTW, it worked on my computer.

Please imagine that you get a question like “My Windows wont work, I get some could not connect error”. Are you able to help here?

So, could you please add your bpmn file, the complete call to start a process instance and the complete error message and the stack trace from the server console?

Thank you, Ingo

Here’s the data:

I was using camunda rest api, startProcessIntanceByKey with process variables

{
  "variables": {
    "taskResolveDate" : {
        "value" : "2019-01-23T20:10:00.000+0100",
        "type": "Date"
    }
  }
}

workflownew.bpmn (9.1 KB)

Hi @aravindhrs,

when I start your process with the request:

curl -X POST \
  http://localhost:8080/engine-rest/process-definition/key/availsworkflow/start \
  -H 'Content-Type: application/json' \
  -H 'Postman-Token: 158750c6-4699-44c5-8b8f-6c6a6ad6acb5' \
  -H 'cache-control: no-cache' \
  -d '{
  "variables": {
    "taskResolveDate" : {
        "value" : "2019-01-23T20:10:00.000+0100",
        "type": "Date"
    }
  }
}'

I get the response:

{
    "type": "RestException",
    "message": "Cannot instantiate process definition availsworkflow:2:b1ef679f-2075-11e9-a43b-185e0f710ea8: ENGINE-20011 Scope with specified activity Id Avails_Resolve_Event_SubProcess and execution b4fd9203-2075-11e9-a43b-185e0f710ea8 not found"
}

After deleting the start listener from the start event, I get the error:

{
    "type": "RestException",
    "message": "Cannot instantiate process definition availsworkflow:3:1c25319a-2076-11e9-a43b-185e0f710ea8: Unknown property used in expression: ${candidateUsers}. Cause: Cannot resolve identifier 'candidateUsers'"
}

And after using the service task to set the candiidateUsers and candidateGroups, I get the response:

{
    "links": [
        {
            "method": "GET",
            "href": "http://localhost:8080/engine-rest/process-instance/fd4de170-2076-11e9-a43b-185e0f710ea8",
            "rel": "self"
        }
    ],
    "id": "fd4de170-2076-11e9-a43b-185e0f710ea8",
    "definitionId": "availsworkflow:5:f8f9063c-2076-11e9-a43b-185e0f710ea8",
    "businessKey": null,
    "caseInstanceId": null,
    "ended": false,
    "suspended": false,
    "tenantId": null
}

So, it works as expected after removing the start listener.

The history shows a process instance with a invoked event subprocess.

Cheers, Ingo

1 Like

@Ingo_Richtsmeier Can you try with this attached bpmn and payload?

Still I was getting below error from Postman:

 {
    "type": "RestException",
    "message": "Cannot instantiate process definition workflowreview:1:2406674e-2081-11e9-bcba-507b9dc4ed46: Unknown property used in expression: ${taskResolveDate}. Cause: Cannot resolve identifier 'taskResolveDate'"
}

PayLoad:

{
  "businessKey": "5c432441778531931cd_5xAy5nkcuMw",
  "variables": {
    "submittedBy": {
      "type": "String",
      "value": "abc@abc.com"
    },
    "candidateUsers": {
      "type": "String",
      "value": "1,2,4,5,12,14,2072"
    },
    "candidateGroups": {
      "type": "String",
      "value": "Team1"
    },
    "userAssignmentFlag": {
      "type": "String",
      "value": "both"
    },
    "taskResolveDate": {
      "type": "Date",
      "value": "2019-02-24T20:10:00.000+0100"
    }
  }
}

Bpmn file: workflownew.bpmn (9.1 KB)

Error Log: PropertyNotFoundException.txt (31.9 KB)

Note: I have removed the listener from StartEvent

Processdefinition key: workflowreview

Hi @aravindhrs,

please doublecheck the processdefinition in cockpit.

I think the attached process model isn’t deployed correctly to your engine and you still start an older version.

Hope this helps, Ingo

yep. i also doubted the same. I was using H2 database with fileSystem storage. I removed db files and restarted the services and db files created newly. But facing same issue.

Note: Removing H2 db files, will delete everything.

its suspension state = 1, is that correct? And also in ACT_RU_PROCESSDEF_ table has also suspensionState=1

When I hard code the date value directly in BPMN file, its working. And i can see job definitions in cockpit for timer-start-event-subprocess

But if i use expression as ${taskresolveDate} for the same, it doesn’t working. Any insights? Am I missing something related to configurations?

I hope spin dependencies not required for this. I was using camunda spring boot rest starters.

Also observed below:

I have debugged for the issue:

[org.camunda.bpm.engine.context] [logError] @ 156 : ENGINE-16004 Exception while closing command context: Unknown property used in expression: ${taskResolve}. Cause: Cannot resolve identifier 'taskResolve' 
org.camunda.bpm.engine.ProcessEngineException: Unknown property used in expression: ${taskResolve}. Cause: Cannot resolve identifier 'taskResolve'
	at org.camunda.bpm.engine.impl.el.JuelExpression.getValue(JuelExpression.java:60)
	at org.camunda.bpm.engine.impl.el.JuelExpression.getValue(JuelExpression.java:48)
	at org.camunda.bpm.engine.impl.jobexecutor.TimerDeclarationImpl.initializeConfiguration(TimerDeclarationImpl.java:114)

From above snapshot during debug, found Variables are coming as empty.