Parallel Multi-instance is getting created user tasks with last employee details - camunda

I am developing a scenario on Camunda bpm Modeler 5 and bpm run 7.17.
Scenario:
using a service task to invoke an external rest-api using http-connector and that external rest api sends response as follows with multiple employees info in json format.
[
{"regId":"0XFY1FX00W","fname":"abc","lname":"def","email":"abc.def#gmail.com"},
{"regId":"0XFY1F000X","fname":"ghi","lname":"jklm","email":"ghi.jklm#ymail.com"},
{"regId":"0XFY1F000Y","fname":"nop","lname":"qrs","email":"nop.qrs#xmail.com"},
{"regId":"0XFY1F000Z","fname":"tuv","lname":"wxyz","email":"tuv.wxyz#zmail.com"}
]
I am trying to create 4 user tasks with those 4 employees and those user tasks should be populated with those employee first name and last names.
I have used parallel multi-instance and I succeeded with that 4 user tasks creation but all the user tasks contain last employee details i.e.
"fname":"tuv","lname":"wxyz".
Please let me know how to achieve that i.e. the user tasks should contain 4 different employee details?
Note: I have tested with sequence multi-task and it is working as expected and My requirement is to use user task and not any subprocess.

Related

Camunda Rest API: Cannot fetch and lock an External Task for a Tenant

I have a Process Instance that was started by the Tenant 949.
I tried to fetch and lock that Task, like described here: https://docs.camunda.org/manual/7.10/reference/rest/external-task/fetch/
Here is the Body of the Request:
{"workerId":"testUser","maxTasks":1,"usePriority":false,
"topics":[
{"topicName":"archive-document","tenantIdIn":["949"],"lockDuration":10000,"localVariables":true,"deserializeValues":false}
]}
I don't get any Task with it.
The same request works if the Process Instance is started without a Tenant and fetched accordingly.
Do I miss something, or is this a Bug of Camunda?
Have you attempted to simply do a query to first retrieve the task? (Rather than attempting to fetch it and lock it?) You could use this endpoint: https://docs.camunda.org/manual/7.10/reference/rest/external-task/get-query/.
You may also want to query the runtime database directly using SQL. Your External Task would be in the ACT_RU_EXT_TASK table and would have a TOPIC_NAME_ defined within it (as well as a TENANT_ID_).
The problem was the Authentication.
I had a different User to start the process and to fetch the Task.
And this User had no rights to fetch the Task for this Tenant.

Tenant ID setting in case of "startBeforeActivity"

ENV: Camunda 7.5
Approach: Single Process Engine With Tenant-Identifiers with Transparent Access Restrictions for Tenants
Given: foo is a process definition key which is deployed without tenant ID, i.e. shared process among all tenants. bar is the ID of a service task within foo.
The TenantIdProvider works well if one start process instances normally (startXXX or startXXXByMessage). For test cases which don't start process instances this way, rather with:
runtimeService.createProcessInstanceByKey('foo')
.startBeforeActivity('bar')
.execute()
the tenant ID doesn't get set. Maybe someone can point out why and how. Thanks!
Not implemented yet. See also: https://app.camunda.com/jira/browse/CAM-6218

User likes on django accumulation

I have a simple pinterest clone app built and have a basic activity stream setup.
The activity stream only records when a new image is created, when an image is liked, when a new user is created, or when a followed user follows another user.
What I would like to implement and do not know how is accumulation, for example if 2 or more user like a certain image, I would prefer the activity stream to say:
"User 1 and User 2 like image"
Can any one help me achieve this?
The Action models in django-activity-stream could be helpful.
For example, when an Actor performs an action, you could look up if there was recently a similar Verb and Target combination by a different Actor, and then replace that earlier instance with a new one that includes the most recent Actor.

How do I get user task list with its process variables in Camunda

I have a requirement where a user could be assigned thousands (1000 - 5000) tasks, belonging to different process instances (same user task from 1000 - 5000) instances at a given time. I have a custom task list screen where I need to load all the tasks with their basic info (id, name, process instance id etc) and some process variables for each.
First I used the filter/list REST service i.e. engine-rest/filter/{filter-id}/list to get the tasks with the process variables. (I created a filter in Camunda tasklist). But this REST service takes forever to return when there are more than 1000 process instances in question. It took 7-8 mins for about 2000 process instances. Maybe because this service returns a lot of information which I don't need.
So I decided to write my own REST service using Camunda Java api. This is what I did -
List<Task> tasks = taskService.createTaskQuery().processDefinitionKey(processDefinitionKey).taskAssignee(assignee).list();
if(tasks != null && !tasks.isEmpty()){
for(Task task : tasks){
.....
.....
Map<String, Object> variables = taskService.getVariables(task.getId(), variableNames);
.....
}}
This works and is much faster than the filter service. But for about 1000 instances it is taking around 25 secs. (My server is not production grade right now, Tomcat Xms -1gb Xmx - 2gb).
But my concern is that internally is this code hitting the DB 1000 times (for each tasks returned by taskquery) to get the variables? Worse still depending on the number of variables is it querying the DB that many times for each variable? I mean for 5 variables are we hitting the DB 5000 times?
1) If so, is there any way I can improve this service? Like can I write a NativeTaskQuery where I join the act_ru_task, act_ru_process & act_ru_variable tables to get the data I need? Is that the right way?
2) Isn't there any inbuilt caching in Camunda that can help here?
Thanks in advance for your help.
You can use a custom query for this. Write your native sql query and add a mybatis mapping. This example explains the concept : https://github.com/camunda-consulting/code/tree/master/snippets/custom-queries

Django: sending email x days later

In my Django project, users are allowed to register to a free trial, but if they do not complete a purchase within 15 days, their accounts are locked out until they do complete the purchase. After 13 days (ie within 48 hours or expiry) I wish to send an email the registered user reminding him/her to purchase.
Currently, I have a cron job set up to run daily and check all trial accounts if the registration date and current date are 2 days apart and if so, I send an email.
I was wondering if there is a more elegant solution to do this?
If you don't want to mess with your cron file you should check out Celery, an asynchronous task queue written in Python. It was originally created with Django in mind but has since been broken out into a separate package. What you want to do then is set up a Celerybeat schedule like this:
CELERYBEAT_SCHEDULE = {
"purchase-reminder": {
"task": "accounts.tasks.remind",
"schedule": timedelta(hours=24),
},
}
This will call the task (read: function) accounts.tasks.remind every 24 hours.