jscheffl commented on PR #63677:
URL: https://github.com/apache/airflow/pull/63677#issuecomment-4071059546

   As I have the same demand, how about the following - just tried it and might 
be a good option w/o needing this PR:
   
   (1) Create a "pseudo Dag file", e.g. `__git_info__.py` in your Dags folder 
like:
   ```
   from __future__ import annotations
   
   from airflow.models.variable import Variable
   from airflow.sdk import DAG
   
   # assume we read the needed info from git here...
   GIT_INFO = {
       "branch": "main",
       "commit": "abc123",
       "date": "2024-06-01T12:00:00Z",
   }
   
   Variable.set("git_info", GIT_INFO, serialize_json=True)
   
   # Dummy something that Dag Parser will read this...
   if isinstance("test", DAG):
       pass
   ```
   (Some code to be added to read GIT info thoug... but you have this at your 
hands anyway...
   
   Then use the following `airflow_local_settings.py` on your API server:
   ```
   from __future__ import annotations
   
   from cachetools import TTLCache, cached
   
   from airflow.api_fastapi.common.types import UIAlert
   from airflow.models.variable import Variable
   
   
   @cached(cache=TTLCache(maxsize=1, ttl=60))
   def get_dashboard_ui_alerts() -> str:
       """Get the list of UI alerts to be shown on the dashboard."""
       git_info = Variable.get("git_info", default_var=None, 
deserialize_json=True)
       return f"Current Git branch: {git_info.get('branch')}, commit: 
{git_info.get('commit')}, date: {git_info.get('date')}" if git_info else "No 
Git info available."
   
   
   class DynamicAlerts(list):
       """Dynamically load the list of UI alerts to be shown on the 
dashboard."""
   
       def __iter__(self):
           yield UIAlert(text=get_dashboard_ui_alerts(), category="info")
   
   DASHBOARD_UIALERTS = DynamicAlerts()
   ```
   Yeah.. Variable might not be ideal but is cached for 60s at least... as long 
as there are no other state structures available... (There is still an ongoing 
discussion how to store e.g. state in triggerer.... but discussion is still 
ongoing)


-- 
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]

Reply via email to