Skip to content
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
14 changes: 13 additions & 1 deletion data_validation.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
from prefect import task, flow, get_run_logger
import os
import time as ttime

from prefect import task, flow, get_run_logger
from tiled.client import from_uri
from dotenv import load_dotenv


def get_api_key_from_env():
with open("/srv/container.secret", "r") as secrets:
load_dotenv(stream=secrets)
api_key = os.environ["TILED_API_KEY"]
return api_key


@task
def get_run(uid, api_key=None):
if not api_key:
api_key = get_api_key_from_env()
tiled_client = from_uri("https://tiled.nsls2.bnl.gov", api_key=api_key)
run = tiled_client["srx/raw"][uid]
return run
Expand Down
15 changes: 1 addition & 14 deletions end_of_run_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,11 @@
from xrf_hdf5_exporter import xrf_hdf5_exporter
from vlm_snapshot_exporter import vlm_image_exporter
from logscan import logscan
from dotenv import load_dotenv
import os
from data_validation import get_run

CATALOG_NAME = "srx"


def get_api_key_from_env():
with open("/srv/container.secret", "r") as secrets:
load_dotenv(stream=secrets)
api_key = os.environ["TILED_API_KEY"]
return api_key


def slack(func):
"""
Send a message to mon-prefect and mon-prefect-im slack channels if the flow-run failed.
Expand All @@ -46,10 +37,6 @@ def end_of_run_workflow(stop_doc, api_key=None, dry_run=False):
# Get the uid.
uid = stop_doc["run_start"]

# Get Tiled API key, if not set already
if not api_key:
api_key = get_api_key_from_env()

# Get the scan_id.
run = get_run(uid, api_key=api_key)
scan_id = run.start["scan_id"]
Expand Down Expand Up @@ -77,7 +64,7 @@ def end_of_run_workflow(stop_doc, api_key=None, dry_run=False):
flow_run = FlowRunContext.get().flow_run
# Add link to flow-run for the message to mon-prefect-im.
program_message = (
f":bangbang: {CATALOG_NAME} flow-run failed. <https://{PREFECT_UI_URL.value()}/flow-runs/"
f":bangbang: {CATALOG_NAME} flow-run failed. <{PREFECT_UI_URL.value()}/flow-runs/"
+ f"flow-run/{flow_run.id}|the flow run link> (*{flow_run_name}*)\n ```run_start: {uid}\nscan_id: {scan_id}``` ```{tb[-1]}```"
)
mon_prefect_im.notify(program_message)
Expand Down
Loading
Loading