Issue #3606795: Add an InstanceEndedEvent for reacting to a process instance reaching a terminal state
Issue #3606795: Add an InstanceEndedEvent for reacting to a process instance reaching a terminal state
Adds InstanceEndedEvent, the symmetric counterpart to InstanceStartedEvent: an @api lifecycle event dispatched once an instance reaches a terminal state, carrying the instance and the terminal status (completed, cancelled or failed) so a listener can tell them apart.
WorkflowEngine dispatches it at the three terminal transitions, after the status is saved and the teardown is done: completed in checkCompletion(), cancelled in cancelInstance(), failed in failInstance(). The cancelled and failed paths run in a database transaction, so the event documents that listeners must be side-effect-light and must not throw.
This gives consumers a typed hook to react to a run ending (release a resource, delete a stored credential, notify an external system) instead of hanging business logic off the OrchestraAuditableEvent audit feed.
Closes #3606795