ashb commented on issue #54527:
URL: https://github.com/apache/airflow/issues/54527#issuecomment-3200640012
> But I believe in Airflow 3 all such extra links are resolved and
serialized on the worker side - and their serialized form are only used in
api_server to rended the links for the UI.
The way it works in Airflow 3 now is the URL is calculated on the worker
side (calling `link.resolve()` I think. Something like that) and then the
generated URL is stored in XCom -- meaning that the URLs generated must be
static now (now generating a signed URL at the time the link is requested in
the API server. If you want that create an API plugin and make the URL be to
that endpoint).
So yes, doing this in Airflow 3 is now possible to achieve safely.
Now it's just the question of API design. I think putting ✨ something ✨ into
the Context object would be the way to go, in a similar vein to how we have the
var and conn objects (though those are mostly used in templates, not directly)
meaning the DAG code would look something like this:
```python
@task
def get_api_resource(id_: str, extra_links: SOMETHING):
"""
Example of setting extra link w/a separate decorator with link name `API
Resource`.
"""
rsp = requests.get(f"https://localhost/v2/api/fakeresource/{id_}")
extra_link["API Resource"] = rsp.url
# or:
# extra_link.set("API Resource", rsp.url)
# I'm okay with it looking like a dict/mapping. What do others thing
return rsp.json()
```
I don't think we even need to pre-declare that new link name. We could if we
wanted, but I _think_ that this form could work just as well.
https://github.com/apache/airflow/blob/4e6fa29117255b7c231672ca643ff21ff91f833b/task-sdk/src/airflow/sdk/execution_time/task_runner.py#L1360-L1369
is where the links are currently sent to the API server to be stored in the
DB. We could just as easily loop over `context.extra_links` as well.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]