diff --git a/SpiffWorkflow/bpmn/specs/event_definitions/timer.py b/SpiffWorkflow/bpmn/specs/event_definitions/timer.py index 2ff623bd..dc48912f 100644 --- a/SpiffWorkflow/bpmn/specs/event_definitions/timer.py +++ b/SpiffWorkflow/bpmn/specs/event_definitions/timer.py @@ -125,9 +125,9 @@ def parse_iso_recurring_interval(expression): duration = TimerEventDefinition.get_timedelta_from_end(start_or_duration, end_or_duration) start = end_or_duration - duration elif end_or_duration is None: - # Just an interval duration, assume a start time of now - start = datetime.now(timezone.utc) - duration = TimeDateEventDefinition.get_timedelta_from_start(start_or_duration, start) + # Just an interval duration, assume a start time of now + duration + duration = TimeDateEventDefinition.get_timedelta_from_start(start_or_duration) + start = datetime.now(timezone.utc) + duration else: raise Exception("Invalid recurring interval") return cycles, start, duration diff --git a/SpiffWorkflow/bpmn/specs/mixins/events/event_types.py b/SpiffWorkflow/bpmn/specs/mixins/events/event_types.py index 48eef684..bda35cbd 100644 --- a/SpiffWorkflow/bpmn/specs/mixins/events/event_types.py +++ b/SpiffWorkflow/bpmn/specs/mixins/events/event_types.py @@ -57,16 +57,17 @@ def _update_hook(self, my_task): if self.event_definition.has_fired(my_task): return True - elif isinstance(self.event_definition, CycleTimerEventDefinition): - if self.event_definition.cycle_complete(my_task): - for output in self.outputs: - child = my_task._add_child(output, TaskState.READY) - child.task_spec._predict(child, mask=TaskState.READY|TaskState.PREDICTED_MASK) - if my_task.state != TaskState.WAITING: - my_task._set_state(TaskState.WAITING) elif my_task.state != TaskState.WAITING: my_task._set_state(TaskState.WAITING) + if isinstance(self.event_definition, CycleTimerEventDefinition): + if self.event_definition.cycle_complete(my_task): + for output in self.outputs: + child = my_task._add_child(output, TaskState.FUTURE) + child.task_spec._predict(child, mask=TaskState.NOT_FINISHED_MASK) + child.task_spec._update(child) + + def _run_hook(self, my_task): self.event_definition.update_task_data(my_task) diff --git a/tests/SpiffWorkflow/bpmn/events/TimerCycleStartTest.py b/tests/SpiffWorkflow/bpmn/events/TimerCycleStartTest.py index 5708081c..f2246346 100644 --- a/tests/SpiffWorkflow/bpmn/events/TimerCycleStartTest.py +++ b/tests/SpiffWorkflow/bpmn/events/TimerCycleStartTest.py @@ -54,7 +54,6 @@ def actual_test(self,save_restore = False): self.workflow.do_engine_steps() if save_restore: self.save_restore() - self.workflow.script_engine = CustomScriptEngine() time.sleep(0.1) self.workflow.refresh_waiting_tasks() diff --git a/tests/SpiffWorkflow/bpmn/events/TimerCycleTest.py b/tests/SpiffWorkflow/bpmn/events/TimerCycleTest.py index 1921390d..0a018593 100644 --- a/tests/SpiffWorkflow/bpmn/events/TimerCycleTest.py +++ b/tests/SpiffWorkflow/bpmn/events/TimerCycleTest.py @@ -44,20 +44,22 @@ def actual_test(self,save_restore = False): global counter counter = 0 # See comments in timer cycle test start for more context - for loopcount in range(5): + for loopcount in range(4): self.workflow.do_engine_steps() if save_restore: self.save_restore() - self.workflow.script_engine = CustomScriptEngine() - time.sleep(0.05) self.workflow.refresh_waiting_tasks() events = self.workflow.waiting_events() + refill = self.workflow.get_tasks(spec_name='Refill_Coffee') + # Wait time is 0.1s, with a limit of 2 children, so by the 3rd iteration, the event should be complete if loopcount < 2: - # Wait time is 0.1s, two child tasks are created self.assertEqual(len(events), 1) else: - # By the third iteration, the event should no longer be waiting self.assertEqual(len(events), 0) + # The first child should be created after one cycle has passed + if loopcount == 0: + self.assertEqual(len(refill), 0) + time.sleep(0.1) # Get coffee still ready coffee = self.workflow.get_next_task(spec_name='Get_Coffee') @@ -66,4 +68,3 @@ def actual_test(self,save_restore = False): timer = self.workflow.get_next_task(spec_name='CatchMessage') self.assertEqual(timer.state, TaskState.COMPLETED) self.assertEqual(counter, 2) -