Hi I have a use case where I want to run two tasks...
# ask-community
p
Hi I have a use case where I want to run two tasks in parallel which is ok but 1. I want to know the status of the first task in the second task because 2. If the second task is completed, but the first one is still going on then I want the second task to sleep for some time and then retry itself again.
and yeah we're using prefect 1
m
you can use the graphql API to query for the state of a task_run something like this
Copy code
client.graphql("""
    query{
        task_run(
            where: {
              task: {
                name: {_eq: "my-task"}
            	} ,
              flow_run: { _eq: "my_flow_run_id" }
            }
            ){
              state,
               state_message,
            }
    }
""")
then add inspect the state and state_message
p
I thought that if I can grab id of the first task and pass it to the second task then in second task somehow I can find state of the first task (using graphql api as you mentioned). But now I have three questions 1. How to find id of the task and flow in my code? 2. In case the first task fails and restarted then will it create a new id for the new run, if yes then how will I handle this? 3. Is there any other alternative other than graphql api, like how do you guys check for upstream task state in the backend?
m
use the prefect context - it contains the flow run id
p
ok and task_id ?
ultimately task_id will be required right?
m
is task name not enough to find your task ?
šŸ¤” 1
1. Is there any other alternative other than graphql api, like how do you guys check for upstream task state in the backend?
I thought ā€œfirst taskā€ and ā€œsecond taskā€ are running concurrently, if you set ā€œfirst taskā€ as upstream to ā€œsecond taskā€ then one approach is you can set a trigger on the ā€œsecond taskā€ to always run, and then you can inspect the return value of ā€˜first task’
p
nah tasks are running concurrenly I just asked about how the things work at backend for the upstream, thought may be I can use some good strategy
m
ok
p
I will try the things, will get back here if faced any problems
m
goodluck, not much sure what the prefect team does on their backend, I am another prefect user like you
p
ohhh
thanks for the help
m
šŸ‘