Skip to content

Commit

Permalink
Update task engine to increment run_count when entering running state
Browse files Browse the repository at this point in the history
  • Loading branch information
desertaxle committed Sep 19, 2024
1 parent 857727d commit d73a422
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/prefect/task_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,11 @@ async def wait_until_ready(self):
if scheduled_time := self.state.state_details.scheduled_time:
sleep_time = (scheduled_time - pendulum.now("utc")).total_seconds()
await anyio.sleep(sleep_time if sleep_time > 0 else 0)
new_state = Retrying() if self.state.name == "AwaitingRetry" else Running()
if self.state.name == "AwaitingRetry":
self.task_run.run_count += 1
self.set_state(
Retrying() if self.state.name == "AwaitingRetry" else Running(),
new_state,
force=True,
)

Expand Down Expand Up @@ -1199,8 +1202,11 @@ async def wait_until_ready(self):
if scheduled_time := self.state.state_details.scheduled_time:
sleep_time = (scheduled_time - pendulum.now("utc")).total_seconds()
await anyio.sleep(sleep_time if sleep_time > 0 else 0)
new_state = Retrying() if self.state.name == "AwaitingRetry" else Running()
if self.state.name == "AwaitingRetry":
self.task_run.run_count += 1
await self.set_state(
Retrying() if self.state.name == "AwaitingRetry" else Running(),
new_state,
force=True,
)

Expand Down
3 changes: 2 additions & 1 deletion tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,8 @@ async def test_task_retries_receive_latest_task_run_in_context(
run_counts = []
start_times = []

@task(retries=3)
# Added retry_delay_seconds as a regression check for https://github.com/PrefectHQ/prefect/issues/15422
@task(retries=3, retry_delay_seconds=1)
def flaky_function():
ctx = TaskRunContext.get()
state_names.append(ctx.task_run.state_name)
Expand Down

0 comments on commit d73a422

Please sign in to comment.