Sophia Ponte
02/08/2024, 6:28 PMMarvin
02/08/2024, 6:29 PMrequests
library, this might resemble:
python
import requests
# Variables for the request
api_token = "your_api_token"
headers = {
"Authorization": f"Bearer {api_token}",
"Content-Type": "application/json",
}
flow_run_id = "your_flow_run_id"
new_tags = ["tag1", "tag2"]
api_url = "<https://api.prefect.io/graphql>" # Update with the correct API endpoint if different
mutation = """
mutation($input: UpdateFlowRunInput!) {
update_flow_run(input: $input) {
id
}
}
"""
variables = {
"input": {
"flow_run_id": flow_run_id,
"tags": new_tags
}
}
response = <http://requests.post|requests.post>(api_url, headers=headers, json={"query": mutation, "variables": variables})
# Handle the response
if response.status_code == 200:
print(f"Flow run tags updated successfully: {response.json()}")
else:
print(f"Failed to update flow run tags: {response.status_code} - {response.text}")
Please verify this process as it may differ based on the version of Prefect you're using and the exact form of the Prefect API at the time of your interaction. Remember that it's also important to handle exceptions and errors that might arise from such network interactions, but those details tend to depress me, so I'll spare you.
For the exact mutation format or the correct REST endpoint, you would refer to the Prefect documentation or API schema. If you're lucky, they might have a section in there that cheerfully explains how to update a flow run's tags — a perfect antidote to my existential ennui.Sophia Ponte
02/08/2024, 6:30 PMMarvin
02/08/2024, 6:32 PMclient.update_flow_run
method if you are using Prefect 2.x, which has a more user-friendly interface for interacting with your flows.
In Prefect 2.x, the update_flow_run
method can be used to alter a flow run's tags. Here's how you might go about it:
python
from prefect import get_run_logger
from prefect.client import get_client
async def update_flow_run_tags(flow_run_id, new_tags):
logger = get_run_logger()
async with get_client() as client:
try:
await client.update_flow_run(
flow_run_id=flow_run_id,
tags=new_tags
)
<http://logger.info|logger.info>(f"Updated flow run {flow_run_id}'s tags to {new_tags}")
except Exception as exc:
logger.error(f"Failed to update flow run tags due to: {exc}")
# You'd then call this coroutine with an event loop, for example:
import asyncio
flow_run_id = "your_flow_run_id" # Replace this with your actual flow run ID
new_tags = ["new-tag1", "new-tag2"] # The tags you want to apply
loop = asyncio.get_event_loop()
loop.run_until_complete(update_flow_run_tags(flow_run_id, new_tags))
Do remember to replace your_flow_run_id
with the actual ID of the flow run you're targeting.
Bear in mind that the snippet above assumes Async IO, which Prefect 2.x leans heavily into. This requires managing an event loop, which can sometimes feel like trying to cheer up a cat by explaining it the concept of Schrödinger's paradox — ultimately futile, but we do it anyway.
Now, if you're looking for a synchronous counterpart, you may need to delve into the Prefect source code, or perhaps check their documentation or GitHub Discussions for tips on interacting with the API in a synchronous context, which also might be a tad more cheerful than the vast wasteland of asynchronous calls.