Skip to content

Commit

Permalink
Merge pull request #371 from sartography/bugfix/cycle-timer-bugs
Browse files Browse the repository at this point in the history
Bugfix/cycle timer bugs
  • Loading branch information
essweine authored Nov 30, 2023
2 parents a0d6b1e + 99cfaec commit 80f85be
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
6 changes: 3 additions & 3 deletions SpiffWorkflow/bpmn/specs/event_definitions/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions SpiffWorkflow/bpmn/specs/mixins/events/event_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion tests/SpiffWorkflow/bpmn/events/TimerCycleStartTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
13 changes: 7 additions & 6 deletions tests/SpiffWorkflow/bpmn/events/TimerCycleTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)

0 comments on commit 80f85be

Please sign in to comment.