File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -844,6 +844,11 @@ def instance() -> Any:
844844 return _Runtime .current ().workflow_instance ()
845845
846846
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+
847852def memo () -> Mapping [str , Any ]:
848853 """Current workflow's memo values, converted without type hints.
849854
Original file line number Diff line number Diff line change @@ -6981,6 +6981,27 @@ async def test_update_handler_semaphore_acquisition_respects_timeout(
69816981 )
69826982
69836983
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+
69847005deadlock_interruptible_completed = 0
69857006
69867007
You can’t perform that action at this time.
0 commit comments