-
Notifications
You must be signed in to change notification settings - Fork 2
Dotenv dryrun fromuri #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AbbyGi
wants to merge
8
commits into
NSLS2:main
Choose a base branch
from
AbbyGi:dotenv-dryrun-fromuri
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+185
−109
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4ca02fd
Use dotenv to get tiled api key, switch to from_uri
AbbyGi 8da9aa5
Start adding dry_run and pass api_key through export flows
AbbyGi 3e9fe4d
fix pre-commit errors
JunAishima 67109fe
add h5py
JunAishima d961092
Remove tiled site profiles and add srv volume
AbbyGi 58f5eff
Log output when export is not performed due to scan abort status
JunAishima 66d4fd8
pre-commit lint - fix spacing
JunAishima 912db28
export and validation code cleanup
AbbyGi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,27 +2,27 @@ | |||||
|
|
||||||
| from prefect import flow, get_run_logger, task | ||||||
|
|
||||||
| from export_tools import initialize_tiled_client | ||||||
| from export_tools import get_run | ||||||
|
|
||||||
|
|
||||||
| @task(retries=2, retry_delay_seconds=10) | ||||||
| def read_all_streams(uid, beamline_acronym="haxpes"): | ||||||
| @task | ||||||
| def read_stream(run, stream): | ||||||
| stream_data = run[stream].read() | ||||||
| return stream_data | ||||||
|
|
||||||
|
|
||||||
| @flow(retries=2, retry_delay_seconds=10) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| def data_validation(uid, api_key=None): | ||||||
| logger = get_run_logger() | ||||||
| tiled_client = initialize_tiled_client(beamline_acronym) | ||||||
| run = tiled_client[uid] | ||||||
| logger.info(f"Validating uid {run.start['uid']}") | ||||||
| run = get_run(uid, api_key=api_key) | ||||||
| logger.info(f"Validating uid {uid}") | ||||||
| start_time = time.monotonic() | ||||||
| for stream in run: | ||||||
| logger.info(f"{stream}:") | ||||||
| stream_start_time = time.monotonic() | ||||||
| stream_data = run[stream].read() | ||||||
| stream_data = read_stream(run, stream) | ||||||
| stream_elapsed_time = time.monotonic() - stream_start_time | ||||||
| logger.info(f"{stream} elapsed_time = {stream_elapsed_time}") | ||||||
| logger.info(f"{stream} nbytes = {stream_data.nbytes:_}") | ||||||
| elapsed_time = time.monotonic() - start_time | ||||||
| logger.info(f"{elapsed_time = }") | ||||||
|
|
||||||
|
|
||||||
| @flow | ||||||
| def general_data_validation(uid, beamline_acronym="haxpes"): | ||||||
| read_all_streams(uid, beamline_acronym) | ||||||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,18 +1,30 @@ | ||
| import os | ||
|
|
||
| from dotenv import load_dotenv | ||
| from prefect import flow, get_run_logger, task | ||
|
|
||
| from data_validation import general_data_validation | ||
| from data_validation import data_validation | ||
| from general_exporter import export_switchboard | ||
|
|
||
|
|
||
| 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 log_completion(): | ||
| logger = get_run_logger() | ||
| logger.info("Complete") | ||
|
|
||
|
|
||
| @flow | ||
| def end_of_run_workflow(stop_doc): | ||
| def end_of_run_workflow(stop_doc, api_key=None, dry_run=False): | ||
| if api_key is None: | ||
| api_key = get_api_key_from_env() | ||
| uid = stop_doc["run_start"] | ||
| general_data_validation(uid, beamline_acronym="haxpes") | ||
| export_switchboard(uid, beamline_acronym="haxpes") | ||
| data_validation(uid, api_key=api_key) | ||
| export_switchboard(uid, api_key=api_key, dry_run=dry_run) | ||
| log_completion() |
This file contains hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.