Hi all -
I am just getting started with C8 and am trying to make the jump from V7. I have installed a version of C8 and gotten a couple simple task workers to run. What I am trying to now if figure out the best way to accomplish some of the things we did in camunda 7. Specificically we used to write scripts that queried camunda about other processes running. Take for example checking to see if there is another instance running that has a variable with a particular value. So in version 7 we might have a script that did something like:
var count = execution.getProcessEngineServices()
.getTaskService()
.createTaskQuery()
.processInstanceBusinessKey(‘somebizkey’)
.processDefinitionKey(‘myprocesskeyhere’)
.taskDefinitionKey(‘mydefinitionkeyhere’)
.processVariableValueEquals(‘myvariable’, ‘myvariableValue’)
.active()
.count();
We would then check to see if the count was greater than zero to make various process decisions. This checked for active tasks in processes with a certain variable value. How would I do something like that in V8? I know the script implementation must be moved to a worker. Do I then embed a tasklist client into my worker to do the query? When I look at the community Node client for tasklist and the rest api I am not sure how I can do a search for active tasks in process instances that contain a particular variable value - Is there a recommended way of implementing something like that? If it makes a difference I should mention that we are group that is mostly nodejs based so I was looking at mostly the community node clients. Sorry if these are answered somewhere in the docs but I couldnt find it. Thanks in advance for any advice anyone has to offer.
UPDATE - I just found the operate connector (although I have not yet gone thru its functionality)- perhaps this is the route to go?
If I understand correctly, you want to drive a decision in a process (e.g. on a gateway) based on if instances of the same or other process are running for a specific variable?
You can of course run such a query in Camunda 8.
There are 2 ways to do so: ad-hoc queries or caching. Later is recommended for production.
For ad-hoc, be aware there is a limitation that you need to account to to build this reliably: the task search returns tasks approx 5 seconds after they are created. The search API works with eventual consistency, so it does not always show the most recent updates. Camunda 8 runs with a fundamental different approach than Camunda 7, as it is built in a event-driven way.
To achieve what you described, you can use a worker, or the REST connector.
In a worker, use the APIs directly, or the Java clients coming with the APIs, to run your queries. Use the Tasklist client to find if there are active tasks. Again, you need a delay of 5 seconds before running the query since tasks appear in the results 5 sec after the query.
Using the REST connector, you can use the Tasklist API directly to make this call in the process, and calculate the count using a following script task using a FEEL expression. You need a timer event before to wait the 5 secs.
We recommend using a cache. Camunda 8 is made to power event-driven architectures. That means that to get real-time results here, we recommend to add your own data aggregation layer (like a Redis cache) and implementing a custom exporter to listen to the event stream (Exporters | Camunda 8 Docs). That way, you can update the information you need in real time. In this example, it could be a simple key-value pair "tasksABCRunning": true/false that you update accordingly to reflect if tasks for the given query are still running or not.