From adefaf990ca7e78ce04d62d1cdde337b05edce18 Mon Sep 17 00:00:00 2001 From: Dylan McReynolds Date: Thu, 18 Jan 2024 13:44:05 -0800 Subject: [PATCH 1/4] upgrade prefect to 2.14 --- requirements.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index cb47a36..9dc69e4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,8 +4,7 @@ httpx>=0.22.0 numpy pillow python-dotenv -prefect==2.7.9 -pydantic<2.0.0 +prefect==2.14 pyscicat @ git+https://github.com/dylanmcreynolds/pyscicat@fix_auth pyyaml authlib \ No newline at end of file From 164aecb5b7d4a8d64897993023cf9ac73c3bdb37 Mon Sep 17 00:00:00 2001 From: Dylan McReynolds Date: Thu, 18 Jan 2024 13:44:26 -0800 Subject: [PATCH 2/4] add example python script --- examples/launch_ptycho.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 examples/launch_ptycho.py diff --git a/examples/launch_ptycho.py b/examples/launch_ptycho.py new file mode 100644 index 0000000..e1baf8b --- /dev/null +++ b/examples/launch_ptycho.py @@ -0,0 +1,39 @@ +# Note that you must have prefect in your environment. Recommend going up one directory and +# running `pip install -r requirements.txt` +# +import asyncio +import os +import prefect + + +def get_prefect_client(httpx_settings=None): + # This prefect client uses prefect settings to set the the api url and api key. This + # can be set in a number of ways. This script ASSUMES that you have set environment variables + # PREFECT_API_URL = https://servername/api + # PREFECT_API_KEY = the api key given to you + # httpx_settings allows you to affect the http client that the prefect client uses + return prefect.get_client(httpx_settings=httpx_settings) + + +def get_prefect_client_2(prefect_api_url, prefect_api_key, httpx_settings=None): + # Same prefect client, but if you know the url and api_key + # httpx_settings allows you to affect the http client that the prefect client uses + return prefect.PrefectClient( + prefect_api_url, + api_key=prefect_api_key, + httpx_settings=httpx_settings) + + +async def prefect_start_flow(prefect_client, deployment_name, file_path): + + deployment = await prefect_client.read_deployment_by_name(deployment_name) + flow_run = await prefect_client.create_flow_run_from_deployment( + deployment.id, + name=os.path.basename(file_path), + parameters={"file_path": file_path}, + ) + return flow_run + + +client = get_prefect_client() +asyncio.run(prefect_start_flow(client, "transfer_auto_recon/transfer_auto_recon", "/a/file/path")) From f5afdfa9923312751ed4dd3dfcc233f280a70075 Mon Sep 17 00:00:00 2001 From: Dylan McReynolds Date: Thu, 18 Jan 2024 13:46:00 -0800 Subject: [PATCH 3/4] prefect to 2.14.3 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 9dc69e4..27d4f1b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ httpx>=0.22.0 numpy pillow python-dotenv -prefect==2.14 +prefect==2.14.3 pyscicat @ git+https://github.com/dylanmcreynolds/pyscicat@fix_auth pyyaml authlib \ No newline at end of file From 6016ef1a85f4eba420546f006c34b16fe7c90c1e Mon Sep 17 00:00:00 2001 From: Dylan McReynolds Date: Thu, 18 Jan 2024 14:38:49 -0800 Subject: [PATCH 4/4] removed outdated prefect class --- orchestration/prefect.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/orchestration/prefect.py b/orchestration/prefect.py index a01c2ed..c6e4f0f 100644 --- a/orchestration/prefect.py +++ b/orchestration/prefect.py @@ -3,9 +3,9 @@ import logging from prefect import get_run_logger, task -from prefect.client import get_client -from prefect.orion.utilities.schemas import DateTimeTZ -from prefect.orion.schemas.states import Scheduled +from prefect import get_client + +from prefect.states import Scheduled logger = logging.getLogger("orchestration.prefect") @@ -23,7 +23,7 @@ async def schedule( assert ( deployment ), f"No deployment found in config for deploymnent_name {deploymnent_name}" - date_time_tz = DateTimeTZ.now() + duration_from_now + date_time_tz = datetime.datetime.now() + duration_from_now await client.create_flow_run_from_deployment( deployment.id, state=Scheduled(scheduled_time=date_time_tz),