Passing variables to Camunda subprocess - business-process-management

I'm trying to model a document workflow using Camunda 7.12. One of the requirements is that the user can define a due date for the whole process, and the system must send a remainder a couple of days before that deadline.
I was suggested to define a subprocess with a timer event that triggers when the date selected by the user in the start form is reached.
So, I defined the following subprocess in the model:
The timer event has the following properties:
The due_date variable is entered by the user in a form when the he starts the process, but I don't know how I can pass it (or if it's even possible) to the remainder subprocess.
Any ideas? Or alternatives on how it could be done?
Thanks in advance,

I found a solution that doesn't involve big changes in the model. Simply, I set the process start event as Asynchronous Before. Now, the timer start event can get the due date value and launch the remainder task as expected.
Cheers,

A related issue was fixed in
https://jira.camunda.com/browse/CAM-9303
and the related unit test
(https://github.com/camunda/camunda-bpm-platform/blob/33601f3026341882afae321611dfe4e8dfd31d2c/engine/src/test/java/org/camunda/bpm/engine/test/bpmn/event/timer/StartTimerEventTest.java#L1351-L1446)
passes on camunda 7.12 and also on the #SpringBootTest I created.
However, I saw the same issue when testing manually via tasklist using this process:
https://cawemo.com/share/6bf324bb-4002-490c-8739-7ca94803acc0
Tasklist uses an API which differs from the call used in the tests.
Possible workarounds I see:
a) Wrap API used in test runtimeService().createProcessInstanceByKey(...) with own REST service and start via this endpoint.
b) Change process model and move process into embedded sub process, then attach intermediated timer event to it. This creates the variable before the event is registered. Example here:
https://cawemo.com/share/870694cf-b704-42c2-b0d7-a2637406d356
A new JIRA ticket for this issue in the context of form variables has beenc reated here: https://jira.camunda.com/browse/CAM-11357

Related

Jira automation: access {{issue}} variable during issue creation

Is there a way to access {{issue}} variable inside a rule that creates an issue itself?
I create an automation rule that:
is triggered by incoming webhook;
creates new issue;
sends web request with some data of newly created issue to another external system.
The problem is that when it comes to the last step, {{issue}} variable is not initialized with data of newly created issue, it's empty. And I need to know at least the key of newly created issue at this moment.
Is there a way to implement this in the creation rule, or I need to create additional automation triggered by creation of new issue instead?
I'd like to keep everything in a single rule if possible.
Answering myself. I have solved this by creating another automation rule triggered by creation of a ticket by 1st rule. Later, however, I have found an information that an issue should be accessible in creation rule as {{createdIssue}} - did not check that though.

Is there a way to disable snapshots of flows?

I am trying to build a flow which regularly gets every JIRA Ticket from my JIRA instance as input data. This works fine however only the first time the flow runs because it saves the retrieved tickets in its snapshot. When I run the flow the second time flowground will not retrieve any JIRA Tickets because they were already retrieved in the first execution. Is there a way to disable this behavior in flowground so that it will retrieve all of the tickets again in the subsequent runs?
just tested the idea to manipulate the snapshot before the connector is executed.
There is a API function for CRUD operations on snapshots. But you cannot edit a snapshot that is owned by a already started flow. You will get an error message in this case:
{"errors":[{"detail":"Can not edit snapshot in started flow","status":409,"code":409,"title":"Conflict",....
So you are able to reset the snapshot before you start the flow only...but this won't really help you...
I do not see another way beside changing the connectors behavior.

Timer on server side in Rails

What am trying to achieve is:
1. User pressess button and starts time-limited form.
2. Timer starts.
3. After X time when timer reaches 0 and user did not finish the form, rails create a record in database and do some session cleaning actions (Model.create and session.delete).
This timer will work like safety measure if user starts the form and then becomes unavailable (closes web brower or shuts PC).
Could you point to me to right direction? Where I should start? What language/framework should I use to do that?
You can use timestamps to record when something happened. Rails already has a great example of this in the updated_at and created_at fields.
You can re-use this concept to store when the user first started filling out the form, perhaps on the resource's new route, which usually coincides with the opening of the form.
As for performing the cleanup, you have two options that would could even both work together, depending on the situation:
If the cleanup isn't security-sensitive, you could have a timer kick off on the front-end and then send an AJAX request to the back-end when it expires.
If the cleanup isn't time-sensitive, you could run a task every few minutes or so, which performs the cleanup on any forms that haven't been cleaned up yet. It would look at the timestamps to determine this.
Aside from those suggestions, we'd have to know more about your use cases to answer more questions.
Is the cleanup time-sensitive?
Is the cleanup security-sensitive?
There are more options - you could run the task more granularly or more securely.
Tight timing
One option if your timing is very tight (down to seconds) is to implement both options above, and in addition the following functionality:
Use ActionCable to keep a web socket open with the user. Periodically have them ping the server to check their status.
In a before_filter, probably in ApplicationController, check first if they have permission to continue the action, i.e. the timestamp hasn't expired yet. If the timestamp has expired, and the cleanup hasn't been performed yet, then perform it now.
Limitations of this approach:
If the user closes the website entirely, the cleanup is not going to happen until the next cleanup task happens.
There are vulnerabilities on the front-end. The user can disable the front-end checks, and then avoid submitting the form, which will delay the cleanup in the same way as #1.

Write in the Database from within the database

Hopefully the title is clear, I couldn't find a better name but if someone can improve it please update it, thanks.
I would like the Firebase database to write on a node if a certain condition is met. For example, if one node receives an input from a client (say an angular app) then another node in the database should write certain data, something like a callback that is fired when a node receives some data.
I know there are 4 rule types (.read .write .validate .indexOn), what I am thinking of is some kind of .callback rule that is fired and writes on a node after some other node has received an input.
Obviously this can be achieved via a server side script but Firebase is about a server-less approach so I am trying to understand what are its current limits and what I can do with it.
Thanks for your responses
firebaser here
Running the multi-location update client-side or on a server-side process that you control are currently the only ways to accomplish this.
There is currently no way to trigger updates based on modifications to the database on Firebase servers. It is no big secret that we've been working on such functionality for a while now, but we have made no announcement as to when that will be available.
Also see Can I host a listener on Firebase?, which (I realize now) is probably a duplicate.

Monitor database table for external changes from within Rails application

I'm integrating some non-rails-model tables in my Rails application. Everything works out very nicely, the way I set up the model is:
class Change < ActiveRecord::Base
establish_connection(ActiveRecord::Base.configurations["otherdb_#{RAILS_ENV}"])
set_table_name "change"
end
This way I can use the Change model for all existing records with find etc.
Now I'd like to run some sort of notification, when a record is added to the table. Since the model never gets created via Change.new and Change.save using ActiveRecord::Observer is not an option.
Is there any way I can get some of my Rails code to be executed, whenever a new record is added? I looked at delayed_job but can't quite get my head around, how to set that up. I imagine it evolves around a cron-job, that selects all rows that where created since the job last ran and then calls the respective Rails code for each row.
Update Currently looking at Javan's Whenever, looks like it can solve the 'run rails code from cron part'.
Yeah, you'll either want some sort of background task processor (Delayed::Job is one of the popular ones, or you can fake your own with the Daemon library or similar) or to setup a cronjob that runs on some sort of schedule. If you want to check frequently (every minute, say) I'd recommend the Delayed::Job route, if it's longer (every hour or so) a cron job will do it just fine.
Going the DJ route, you'd need to create a job that would check for new records, process them if there are any, then requeue the job, as each job is marked "completed" when it's finished.
-jon
This is what I finally did: Use Whenever, because it integrates nicely with Capistrano and showed me how to run Rails code from within cron. My missing peace was basically
script/runner -e production 'ChangeObserver.recentchanges'
which is now run every 5 minutes. The recentchanges reads the last looked-at ID from a tmp-file, pulls all new Change records which have a higher ID than that and runs the normal observer code for each record (and saves the highest looked-at ID to the tmp-file, of course).
As usual with monitoring state changes, there are two approaches : polling and notification. You seem to have chose to go the polling way for now (having a cron job look at the state of the database on a regular basis and execute some code if that changed)
You can do the same thing using one of the rails schedulers, there are a few out there (google will find them readily, they have various feature sets, I'll let you choose the one which suits your need if you got that way)
You could also try to go the notification way depending on your database. Some database support both triggers and external process execution or specific notification protocols.
In this case you are notified by the database itself that the table changed. there are many such options for various DBMS in Getting events from a database

Resources