Nikhil Jain
02/15/2024, 7:13 PMtask_run_id
for a task that is started from a flow
run? My use case is this: I want to fetch the logs from a particular task after it was finished and upload it to a DB for access in another tool. e.g.
@task
def my_task():
// do something
// return something
@flow
def my_flow():
x = my_task()
my_task_run_id = ???
// now fetch the logs for this task
response = <http://requests.post|requests.post>(
f'<https://api.prefect.cloud/api/accounts/{account_id}/workspaces/{workspace_id}/logs/filter>',
headers={'Authorization': f"Bearer {os.environ.get('PREFECT_API_KEY')}"},
json={'logs': {'task_run_id': {'any_': [my_task_run_id]}}},
)
Nikhil Jain
02/15/2024, 7:14 PMJake Kaplan
02/15/2024, 8:23 PMfrom prefect import flow, task
@task
def my_task():
return "Task return val"
@flow(log_prints=True)
def my_flow():
res = my_task.submit()
# make sure to call result to get the return value
# and to ensure that submit is finished
return_value = res.result()
print(f"got return value: {return_value} from task_run_id {res.task_run.id}")
Nikhil Jain
02/15/2024, 8:54 PMJake Kaplan
02/15/2024, 9:00 PM