Hello! I have a question. How to get result of `Re...
# ask-community
v
Hello! I have a question. How to get result of
Resume
state passed via
Client.set_task_run_state
method to paused task in task runtime? When i try to use
Client.get_task_run_state
in task i found that state in task runtime is
Running
(after
Resume
and after
Submitted
). So passed result to
Resume
state is not accessible. Have any ideas?
âś… 1
z
Hi @Vladimir Bolshakov -- could you explain a bit more about your use-case so I can best help you?
v
I need to resume task run from external process (consumer). For example, i produce some message to queue from task and pause it (message contains
task_run_id
). After some time, when consumer receive a reply message, it call
set_task_run_state
with state
Resume
and message reply result in it. After that task is resumed and at first step i try to get result from state via
get_task_run_state
. I expect state
Resume
, but actually i get
Running
This is a try to use Prefect tasks with RPCX communication pattern (RabbitMQ)
z
Ah yes well by the time a task is running again it will definitely be in a
Running
state 🙂 I'm not sure the Prefect API is the best place to be passing messages, but you can write a GraphQL query that pulls the most recent resume state for your task instead of the current state
v
Is history of all task run states stored in Postgres?
Also, when i think about another solution, i saw PIN-14 in docs (EventClock), but… it seems to this PIN more related to event-based runs of flow instead of tasks… Is it right?
z
Yeah all of the task run states are in the database
Copy code
query {
  task_run(where: {task_id: {_eq: "5d74935d-356b-4e3a-ab61-362f379699e4"}, state: {_eq: "Resume"}}, limit: 1, order_by: {created: desc}) {
    serialized_state
  }
}
would be roughly what you're looking for
v
Awesome! Thank you, Michael!
z
I'd recommend using the interactive API in the UI to try a query out! You can just
query { task_run { ... } }
to start taking a look at the data
(And yes you are correct about the EventClock)