Skip to content

Commit

Permalink
close up edge case for no_api in terminal state handler
Browse files Browse the repository at this point in the history
  • Loading branch information
philipmac committed Dec 19, 2022
1 parent c39d71a commit 8f40be3
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions em_workflows/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,12 +509,6 @@ def custom_terminal_state_handler(
for task_state in reference_task_states:
if task_state.is_successful():
success = True
callback_url = prefect.context.parameters.get("callback_url")
token = prefect.context.parameters.get("token")
headers = {
"Authorization": "Bearer " + token,
"Content-Type": "application/json",
}
if success:
message = "success"
ns = Success(
Expand All @@ -527,8 +521,14 @@ def custom_terminal_state_handler(
message = "error"
ns = state
if prefect.context.parameters.get("no_api"):
log(f"no_api flag used, terminal: {message}")
log(f"no_api flag used, terminal: success is {message}")
else:
callback_url = prefect.context.parameters.get("callback_url")
token = prefect.context.parameters.get("token")
headers = {
"Authorization": "Bearer " + token,
"Content-Type": "application/json",
}
response = requests.post(
callback_url, headers=headers, data=json.dumps({"status": message})
)
Expand Down Expand Up @@ -771,4 +771,4 @@ def send_callback_body(
log(msg=msg)
raise ValueError(msg)
else:
log(f"Invalid state - need callback_url and token, OR set no_api to True.")
raise signals.FAIL(f"Invalid state - need callback_url and token, OR set no_api to True.")

0 comments on commit 8f40be3

Please sign in to comment.