-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7152 from PrefectHQ/flow-restarts
Manual flow retries
- Loading branch information
Showing
16 changed files
with
805 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from prefect import flow | ||
|
||
child_flow_run_count = 0 | ||
flow_run_count = 0 | ||
|
||
|
||
@flow | ||
def child_flow(): | ||
global child_flow_run_count | ||
child_flow_run_count += 1 | ||
|
||
# Fail on the first flow run but not the retry | ||
if flow_run_count < 2: | ||
raise ValueError() | ||
|
||
return "hello" | ||
|
||
|
||
@flow(retries=10) | ||
def parent_flow(): | ||
global flow_run_count | ||
flow_run_count += 1 | ||
|
||
result = child_flow() | ||
|
||
# It is important that the flow run fails after the child flow run is created | ||
if flow_run_count < 3: | ||
raise ValueError() | ||
|
||
return result | ||
|
||
|
||
if __name__ == "__main__": | ||
result = parent_flow() | ||
assert result == "hello", f"Got {result}" | ||
assert flow_run_count == 3, f"Got {flow_run_count}" | ||
assert child_flow_run_count == 2, f"Got {child_flow_run_count}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...e/migrations/versions/postgresql/2022_10_19_165110_8ea825da948d_track_retries_restarts.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""Add retry and restart metadata | ||
Revision ID: 8ea825da948d | ||
Revises: ad4b1b4d1e9d | ||
Create Date: 2022-10-19 16:51:10.239643 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "8ea825da948d" | ||
down_revision = "3ced59d8806b" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column( | ||
"task_run", | ||
sa.Column( | ||
"flow_run_run_count", sa.Integer(), server_default="0", nullable=False | ||
), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column("task_run", "flow_run_run_count") | ||
# ### end Alembic commands ### |
33 changes: 33 additions & 0 deletions
33
...abase/migrations/versions/sqlite/2022_10_19_155810_af52717cf201_track_retries_restarts.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Add retry and restart metadata | ||
Revision ID: af52717cf201 | ||
Revises: ad4b1b4d1e9d | ||
Create Date: 2022-10-19 15:58:10.016251 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "af52717cf201" | ||
down_revision = "3ced59d8806b" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
with op.batch_alter_table("task_run", schema=None) as batch_op: | ||
batch_op.add_column( | ||
sa.Column( | ||
"flow_run_run_count", sa.Integer(), server_default="0", nullable=False | ||
) | ||
) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
with op.batch_alter_table("task_run", schema=None) as batch_op: | ||
batch_op.drop_column("flow_run_run_count") | ||
|
||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.