sartography / SpiffWorkflow

A powerful workflow engine implemented in pure Python
GNU Lesser General Public License v3.0
1.69k stars 313 forks source link

Workflow Prematurely Ends After Timer Start Event in SpiffWorkflow v3.0.0rc2 #390

Closed vcodx closed 8 months ago

vcodx commented 8 months ago

Description:

I've encountered an issue in SpiffWorkflow version v3.0.0rc2 where workflows are unexpectedly ending following a Timer Start Event. This behavior diverges from the expected, where the workflow should proceed to the next tasks defined in the BPMN diagram.

Steps to Reproduce:

  1. Utilize the SpiffWorkflow version v3.0.0rc2.
  2. Use the code in gist links to reproduce.

Observed Behavior:

The workflow ends immediately after the Timer Start Event, without progressing to subsequent tasks.

Expected Behavior:

The workflow should continue beyond the Timer Start Event, executing subsequent tasks as defined in the BPMN diagram.

Task Tree Dump for Timer Start Event:

ff3f742d-5d7f-4974-9002-d672fe7a0d6a/0: Task of Start (BPMN Task) State: READY Children: 1
  794cdb15-ecc5-45c8-9385-257c81d6e8ed/0: Task of StartEvent_1 (Timer Start Event) State: FUTURE Children: 0

Link to reproduce https://gist.github.com/vcodx/f688a65a70f312a0b2e16a642842426d

Task Tree Dump for Default Start Event:

bf66f690-8183-4c43-a34b-667168746790/0: Task of Start (BPMN Task) State: READY Children: 1
  cdd047c7-6632-415b-88c3-1438f88d4613/0: Task of StartEvent_1 (Default Start Event) State: FUTURE Children: 1
    aac07adb-df96-415c-b507-2da07233eb8b/0: Task of Activity_1n1t0x1 (Manual Task) State: FUTURE Children: 1
      f9a7b630-8b92-4a3f-8a3b-ccd90abb743e/0: Task of Event_1e0ho54 (Default End Event) State: FUTURE Children: 1
        be676d0f-0ede-4e40-aee4-c7251a3eb910/0: Task of Process_YzA9iBf.EndJoin (BPMN Task) State: FUTURE Children: 1
          2b539bb1-bf6b-4d0a-8b1e-d27daa8eaad6/0: Task of End (BPMN Task) State: FUTURE Children: 0

Link to reproduce https://gist.github.com/vcodx/aec4aa51c9561322c5de93d0ef566507

essweine commented 8 months ago

Cycle timer children are not created until the timer actually fires, so that's why the tasks don't appear immediately as they would with normal start events. This a change from previous versions of spiff (it was reported as a bug in https://github.com/sartography/SpiffWorkflow/issues/370).

After you complete the placeholder start task, the BPMN start task enters a waiting state, and only after the first cycle passes will the remainder of the tasks be created. Once you start running the workflow, the tasks should appear and be runnable.

After running the first task workflow.get_next_task(state=TaskState.READY).run() you should see

92238ae1-92db-4c36-994d-c55b30838c97/0: Task of Start (BPMN Task) State: COMPLETED Children: 1
  5bca361b-15c6-4dab-b635-13b1cdc2a3cf/0: Task of StartEvent_1 (Timer Start Event) State: WAITING Children: 0

After 10 seconds, refresh the waiting tasks (workflow.refresh_waiting_tasks())

92238ae1-92db-4c36-994d-c55b30838c97/0: Task of Start (BPMN Task) State: COMPLETED Children: 1
  5bca361b-15c6-4dab-b635-13b1cdc2a3cf/0: Task of StartEvent_1 (Timer Start Event) State: WAITING Children: 1
    7b883521-0a0a-4568-872e-c84962b501ec/0: Task of Activity_1n1t0x1 (Manual Task) State: READY Children: 1
      a8ca6bdd-c4a1-473c-8f6e-469f9c9422fe/0: Task of Event_1e0ho54 (Default End Event) State: FUTURE Children: 1
        9363b60d-baad-454e-871f-7cbe2f51b597/0: Task of Process_YzA9iBf.EndJoin (BPMN Task) State: FUTURE Children: 1
          8c550ef8-d0eb-4056-a518-ea04ce6cc19a/0: Task of End (BPMN Task) State: FUTURE Children: 0

Arguably, it might be better to create one branch of tasks in a FUTURE state and mark them as READY when the timer completes, but I'm not sure how easy that would actually be (and what potential issues it could cause).

vcodx commented 8 months ago

Works for me, thank you for the clarification @essweine