File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -844,6 +844,11 @@ def instance() -> Any:
844
844
return _Runtime .current ().workflow_instance ()
845
845
846
846
847
+ def in_workflow () -> bool :
848
+ """Whether the code is currently running in a workflow."""
849
+ return _Runtime .maybe_current () is not None
850
+
851
+
847
852
def memo () -> Mapping [str , Any ]:
848
853
"""Current workflow's memo values, converted without type hints.
849
854
Original file line number Diff line number Diff line change @@ -6981,6 +6981,27 @@ async def test_update_handler_semaphore_acquisition_respects_timeout(
6981
6981
)
6982
6982
6983
6983
6984
+ def check_in_workflow () -> str :
6985
+ return "in workflow" if workflow .in_workflow () else "not in workflow"
6986
+
6987
+
6988
+ @workflow .defn
6989
+ class InWorkflowUtilWorkflow :
6990
+ @workflow .run
6991
+ async def run (self ) -> str :
6992
+ return check_in_workflow ()
6993
+
6994
+
6995
+ async def test_in_workflow_util (client : Client ):
6996
+ assert check_in_workflow () == "not in workflow"
6997
+ async with new_worker (client , InWorkflowUtilWorkflow ) as worker :
6998
+ assert "in workflow" == await client .execute_workflow (
6999
+ InWorkflowUtilWorkflow .run ,
7000
+ id = f"workflow-{ uuid .uuid4 ()} " ,
7001
+ task_queue = worker .task_queue ,
7002
+ )
7003
+
7004
+
6984
7005
deadlock_interruptible_completed = 0
6985
7006
6986
7007
You can’t perform that action at this time.
0 commit comments