Skip to content

Commit fe1113a

Browse files
committed
reset task status on retry
1 parent d2f7f02 commit fe1113a

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

functions-python/helpers/task_execution/task_execution_tracker.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ def start_run(
113113
set_={
114114
"total_count": total_count,
115115
"params": params,
116+
"status": STATUS_IN_PROGRESS,
117+
"completed_at": None,
116118
},
117119
)
118120
.returning(TaskRun.id)

functions-python/helpers/tests/test_task_execution_tracker.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ def test_start_run_caches_task_run_id(self):
6464

6565
self.assertEqual(tracker.task_run_id, run_uuid)
6666

67+
def test_start_run_resets_status_to_in_progress_on_rerun(self):
68+
"""Re-running the same task_name/run_id must reset status and completed_at on conflict."""
69+
tracker, session = _make_tracker()
70+
run_uuid = uuid.uuid4()
71+
execute_result = MagicMock()
72+
execute_result.scalar_one.return_value = run_uuid
73+
session.execute.return_value = execute_result
74+
75+
tracker.start_run(total_count=5)
76+
77+
stmt_compiled = str(session.execute.call_args[0][0])
78+
# The ON CONFLICT DO UPDATE clause must include status and completed_at
79+
self.assertIn("DO UPDATE SET", stmt_compiled)
80+
self.assertIn("status", stmt_compiled)
81+
self.assertIn("completed_at", stmt_compiled)
82+
6783

6884
class TestTaskExecutionTrackerIsTriggered(unittest.TestCase):
6985
def test_returns_true_when_triggered_row_exists(self):

0 commit comments

Comments
 (0)