Receive variable updated event before process started

When starting a process instance with variables the ActivitiEventListener receives a callback for an event of type VARIABLE_UPDATED before an event of type PROCESS_STARTED. Is this intended? From a client perspective it seems out of order.


I think the original intent for the PROCESS_STARTED event was that the instance was in a ‘ready’ state, meaning everything including the variables have been initialised and the instance can be used asis.

However, follow your argument that it would make sense to introduce another event type that is fired before anything other is created, that reallty demarcates the start of a new instance. The hard part here will be naming, as you’d actually want to use PROCESS_STARTED here and for the second one something like PROCESS_INSTANCE_STARTED_AND_READY. However that would break backwards compatibility. So if you have a suggestion for a suitable naming … I’m all ears :wink:

Given the backwards compatibility concern, would it make sense to introduce a PROCESS_CREATED event that is sent prior to variables being set instead? The PROCESS_CREATED would be similar to the TASK_CREATED event in terms of lifecycle and would allow a client to receive a process event before VARIABLE_UPDATED events. In our use case the issue really is the client is receiving VARIABLE_UPDATED events for a process that it is unaware of due to the order of the events.

Yes, that makes sense.

The TASK_CREATED event is fired when all its properties are set. So this is event should also be fired when the base properties are set, but before the variables are added.
Looking at the code, the right place seems to be just after the recordProcessInstance start:


That sounds reasonable. Correct me if I am wrong, but I think we also need to send the PROCESS_CREATED event from within the CallActivitiyBehavior right after the recordSubProcessInstanceStart call:

Once you confirm, I’ll start putting a PR together for this change. Thanks!

Indeed, correct. Thanks already for the work on the PR!