-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Airflow operator - reattach to running jobs on retries (disabled by d…
…efault) (#286)
- Loading branch information
Martynas Asipauskas
authored and
GitHub Enterprise
committed
Nov 26, 2024
1 parent
7313fb8
commit a30c99e
Showing
10 changed files
with
270 additions
and
32 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from typing import Literal | ||
from airflow.utils.context import Context | ||
|
||
from armada_client.typings import JobState | ||
|
||
|
||
def external_job_uri(context: Context) -> str: | ||
task_id = context["ti"].task_id | ||
map_index = context["ti"].map_index | ||
run_id = context["run_id"] | ||
dag_id = context["dag"].dag_id | ||
|
||
return f"airflow://{dag_id}/{task_id}/{run_id}/{map_index}" | ||
|
||
|
||
def policy(policy_type: Literal["always", "never", "running_or_succeeded"]) -> callable: | ||
""" | ||
Returns the corresponding re-attach policy function based on the policy type. | ||
:param policy_type: The type of policy ('always', 'never', 'running_or_succeeded'). | ||
:type policy_type: Literal['always', 'never', 'running_or_succeeded'] | ||
:return: A function that determines whether to re-attach to an existing job. | ||
:rtype: Callable[[JobState, str], bool] | ||
""" | ||
policy_type = policy_type.lower() | ||
if policy_type == "always": | ||
return always_reattach | ||
elif policy_type == "never": | ||
return never_reattach | ||
elif policy_type == "running_or_succeeded": | ||
return running_or_succeeded_reattach | ||
else: | ||
raise ValueError(f"Unknown policy type: {policy_type}") | ||
|
||
|
||
def never_reattach(state: JobState, termination_reason: str) -> bool: | ||
""" | ||
Policy that never allows re-attaching a job. | ||
""" | ||
return False | ||
|
||
|
||
def always_reattach(state: JobState, termination_reason: str) -> bool: | ||
""" | ||
Policy that always re-attaches to a job. | ||
""" | ||
return True | ||
|
||
|
||
def running_or_succeeded_reattach(state: JobState, termination_reason: str) -> bool: | ||
""" | ||
Policy that allows re-attaching as long as it hasn't failed. | ||
""" | ||
return state not in {JobState.FAILED, JobState.REJECTED} |
Empty file.
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.