-
Notifications
You must be signed in to change notification settings - Fork 4
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 #782 from hubmapconsortium/phillips/status_changer
StatusChanger
- Loading branch information
Showing
13 changed files
with
1,369 additions
and
1,192 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 |
---|---|---|
|
@@ -9,6 +9,7 @@ __pycache__ | |
db.sqlite3 | ||
media/* | ||
media | ||
.envrc | ||
|
||
docker/dev-local | ||
|
||
|
164 changes: 0 additions & 164 deletions
164
src/ingest-pipeline/airflow/dags/error_catching/failure_callback.py
This file was deleted.
Oops, something went wrong.
54 changes: 0 additions & 54 deletions
54
src/ingest-pipeline/airflow/dags/error_catching/validate_upload_failure_callback.py
This file was deleted.
Oops, something went wrong.
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
66 changes: 66 additions & 0 deletions
66
src/ingest-pipeline/airflow/dags/status_change/failure_callback.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,66 @@ | ||
import logging | ||
from pprint import pprint | ||
|
||
from status_change.status_manager import StatusChanger | ||
from status_change.status_utils import formatted_exception | ||
from utils import get_auth_tok | ||
|
||
|
||
class FailureCallbackException(Exception): | ||
pass | ||
|
||
|
||
class FailureCallback: | ||
""" | ||
List should be overridden by each subclass with appropriate values. | ||
""" | ||
|
||
def __init__(self, context): | ||
self.context = context | ||
self.uuid = self.context.get("task_instance").xcom_pull(key="uuid") | ||
self.context["uuid"] = self.uuid | ||
self.auth_tok = get_auth_tok(**context) | ||
self.dag_run = self.context.get("dag_run") | ||
self.task = self.context.get("task") | ||
exception = self.context.get("exception") | ||
self.formatted_exception = formatted_exception(exception) | ||
|
||
self.pre_set_status() | ||
|
||
def get_extra_fields(self): | ||
""" | ||
Error message might need to be overwritten when | ||
subclassed for various DAGs. | ||
'Error' is the default for FailureCallback, which indicates a pipeline has failed. | ||
""" | ||
return { | ||
"validation_message": f""" | ||
Process {self.dag_run.dag_id} started {self.dag_run.execution_date} | ||
failed at task {self.task.task_id}. | ||
{f'Error: {self.formatted_exception}' if self.formatted_exception else ""} | ||
""", | ||
} | ||
|
||
def pre_set_status(self): | ||
# Allows for alterations to props, before calling StatusChanger | ||
# This was added to support some email functions and is perhaps | ||
# at the moment over-engineered. | ||
self.set_status() | ||
|
||
def set_status(self): | ||
""" | ||
The failure callback needs to set the dataset status, | ||
otherwise it will remain in the "Processing" state | ||
""" | ||
data = self.get_extra_fields() | ||
logging.info("data: ") | ||
logging.info(pprint(data)) | ||
StatusChanger( | ||
self.uuid, | ||
self.auth_tok, | ||
"error", | ||
{ | ||
"extra_fields": self.get_extra_fields(), | ||
"extra_options": {}, | ||
}, | ||
).on_status_change() |
Oops, something went wrong.