Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix local retries in Cloud to always run in-process #1348

Merged
merged 2 commits into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ These changes are available in the [master branch](https://github.com/PrefectHQ/

### Fixes

- Fixes issue with Docker storage not respecting user-provided image names - [#1335](https://github.com/PrefectHQ/prefect/pull/1335)
- Fix issue with Docker storage not respecting user-provided image names - [#1335](https://github.com/PrefectHQ/prefect/pull/1335)
- Fix issue with local retries in Cloud not always running in-process - [#1348](https://github.com/PrefectHQ/prefect/pull/1348)

### Deprecations

Expand Down
9 changes: 9 additions & 0 deletions src/prefect/engine/cloud/task_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ def run(
Returns:
- `State` object representing the final post-run state of the Task
"""
context = context or {}
end_state = super().run(
state=state,
upstream_states=upstream_states,
Expand All @@ -253,6 +254,14 @@ def run(
(end_state.start_time - pendulum.now("utc")).total_seconds(), 0
)
time.sleep(naptime)

# currently required as context has reset to its original state
task_run_info = self.client.get_task_run_info(
flow_run_id=context.get("flow_run_id", ""),
task_id=context.get("task_id", ""),
map_index=context.get("map_index"),
)
context.update(task_run_version=task_run_info.version) # type: ignore
return self.run(
state=end_state,
upstream_states=upstream_states,
Expand Down
6 changes: 5 additions & 1 deletion tests/engine/cloud/test_cloud_task_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,15 +622,19 @@ def noop():
global_list.append(0)
raise ValueError("oops")

client.get_task_run_info.side_effect = [MagicMock(version=i) for i in range(4, 7)]
res = CloudTaskRunner(task=noop).run(
context={"task_run_version": 1},
state=None,
upstream_states={},
executor=prefect.engine.executors.LocalExecutor(),
)

## assertions
assert res.is_successful()
assert client.get_task_run_info.call_count == 0 # never called
assert client.get_task_run_info.call_count == 1 # called once on the retry
assert (
client.set_task_run_state.call_count == 5
) # Pending -> Running -> Failed -> Retrying -> Running -> Success
versions = [call[1]["version"] for call in client.set_task_run_state.call_args_list]
assert versions == [1, 2, 3, 4, 5]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously this test failed because versions = [1, 2, 3, 1, 2]