Lee-W commented on code in PR #74784:
URL: https://github.com/apache/airflow/pull/74784#discussion_r4344271048


##########
providers/edge3/src/airflow/providers/edge3/worker_api/routes/logs.py:
##########
@@ -74,13 +81,39 @@ def _logfile_path(task: TaskInstanceKey, task_instance_id: 
UUID | None = None, *
     return FileTaskHandler(".")._render_filename(ti, task.try_number)
 
 
+def _callback_logfile_path(task: TaskInstanceKey, *, session: Session) -> str:

Review Comment:
   ```suggestion
   def _get_callback_logfile_path(task: TaskInstanceKey, *, session: Session) 
-> str:
   ```



##########
providers/edge3/src/airflow/providers/edge3/worker_api/routes/logs.py:
##########
@@ -74,13 +81,39 @@ def _logfile_path(task: TaskInstanceKey, task_instance_id: 
UUID | None = None, *
     return FileTaskHandler(".")._render_filename(ti, task.try_number)
 
 
+def _callback_logfile_path(task: TaskInstanceKey, *, session: Session) -> str:
+    """
+    Return a callback's ``log_path`` from the workload JSON in the callback's 
``edge_job`` row.
+
+    Executor callbacks have no task instance row, so their log path cannot be 
rendered from a task
+    instance. When queuing this callback, the scheduler stored the workload 
JSON in the ``command``
+    column of the callback's ``edge_job`` row. The ``log_path`` in that JSON 
is a path relative to the
+    log folder, and the callback supervisor process writes the callback log at 
that path on the Edge
+    worker. Raise HTTP 404 if the ``edge_job`` row is missing or the JSON has 
no ``log_path``.
+    """
+    command = session.scalar(
+        select(EdgeJobModel.command).where(
+            EdgeJobModel.dag_id == task.dag_id,
+            EdgeJobModel.task_id == task.task_id,
+            EdgeJobModel.run_id == task.run_id,
+            EdgeJobModel.map_index == task.map_index,
+            EdgeJobModel.try_number == task.try_number,
+        )
+    )
+    log_path = json.loads(command).get("log_path") if command else None
+    if not log_path:
+        raise HTTPException(status.HTTP_404_NOT_FOUND, f"No log path found for 
callback {task.task_id}")
+    return log_path
+

Review Comment:
   ```suggestion
       if command and (log_path := json.loads(command).get("log_path")):
           return log_path
       raise HTTPException(status.HTTP_404_NOT_FOUND, f"No log path found for 
callback {task.task_id}")
   ```



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