Hello everyone, is there any code to help with mon...
# prefect-community
d
Hello everyone, is there any code to help with monitoring the state of a flow from code running within the flow? I know how to do it if you have a flow run id already, but I’m not sure how to get this from within that flow. Thanks.
k
I think that requires GraphQL queries, can you tell me the use case?
d
Yes that is what I figured, I’m just not sure how to craft the query. I don’t have any info on the flow run except that it’s the one that the code is being executed in. Some of the code are executing needs to be explicitly cancelled during some error conditions, otherwise it will run forever. We can cancel the task, but this doesn’t actually stop the processes we’ve kicked off. What I thought I’d do is monitor the task or flow state and when it is cancelled and then use that to stop and cleanup after the subprocesses.
z
The flow run id is available in the context
prefect.context.get("flow_run_id")
d
Great this is just what I needed.
k
Oh I misread the first question. Yes just use Michael’s suggestion inside a task or state handler