Neil-YL commited on
Commit
14407fe
·
1 Parent(s): 9bebd76

update async trigger

Browse files
DB_utils.py CHANGED
@@ -5,6 +5,7 @@ from prefect_utils import trigger_maintenance_request
5
  from prefect import task
6
  import pandas as pd
7
  import os
 
8
 
9
  MONGODB_PASSWORD = os.getenv("MONGODB_PASSWORD")
10
 
@@ -81,9 +82,11 @@ def find_unused_wells():
81
  if len(empty_wells) == 1:
82
  maintenance_type = "wellplate_maintenance"
83
  if check_maintenance_status(maintenance_type) == 0:
84
- trigger_maintenance_request(maintenance_type)
85
  set_maintenance_status(maintenance_type,1)
86
-
 
 
87
  dbclient.close()
88
 
89
  # Check if there are any empty wells
 
5
  from prefect import task
6
  import pandas as pd
7
  import os
8
+ import asyncio
9
 
10
  MONGODB_PASSWORD = os.getenv("MONGODB_PASSWORD")
11
 
 
82
  if len(empty_wells) == 1:
83
  maintenance_type = "wellplate_maintenance"
84
  if check_maintenance_status(maintenance_type) == 0:
85
+ asyncio.run(trigger_maintenance_request_async(maintenance_type))
86
  set_maintenance_status(maintenance_type,1)
87
+ else:
88
+ print("[DEBUG] a maintenance request has been sent")
89
+
90
  dbclient.close()
91
 
92
  # Check if there are any empty wells
__pycache__/DB_utils.cpython-310.pyc ADDED
Binary file (4.84 kB). View file
 
__pycache__/maintenance_flow.cpython-310.pyc CHANGED
Binary files a/__pycache__/maintenance_flow.cpython-310.pyc and b/__pycache__/maintenance_flow.cpython-310.pyc differ
 
prefect_utils.py CHANGED
@@ -12,11 +12,11 @@ def start_prefect_worker(work_pool_name: str = "ot2-pool"):
12
  worker_thread.start()
13
  print("Prefect Worker started in background thread.")
14
 
15
- from prefect.deployments import run_deployment
16
 
17
- def trigger_maintenance_request(maintenance_type: str):
18
- deployment_name = "request-wells-maintenance/wells-maintenance"
19
- run_deployment(
20
- name=deployment_name,
21
- parameters={"maintenance_type": maintenance_type}
22
- )
 
12
  worker_thread.start()
13
  print("Prefect Worker started in background thread.")
14
 
15
+ from prefect.client import get_client
16
 
17
+ async def trigger_maintenance_request_async(maintenance_type: str):
18
+ async with get_client() as client:
19
+ await client.create_flow_run_from_deployment(
20
+ name="request-wells-maintenance/wells-maintenance",
21
+ parameters={"maintenance_type": maintenance_type}
22
+ )