dheerajturaga commented on code in PR #55301:
URL: https://github.com/apache/airflow/pull/55301#discussion_r2326207695


##########
providers/edge3/src/airflow/providers/edge3/worker_api/routes/ui.py:
##########
@@ -100,3 +105,57 @@ def jobs(
         jobs=result,
         total_entries=len(result),
     )
+
+
+class MaintenanceRequest(BaseModel):
+    """Request body for maintenance operations."""
+
+    maintenance_comment: Annotated[str, Field(description="Comment describing 
the maintenance reason.")]
+
+
+@ui_router.post(
+    "/worker/{worker_name}/maintenance",
+)
+def request_worker_maintenance(
+    worker_name: str,
+    maintenance_request: MaintenanceRequest,
+    session: SessionDep,
+) -> None:
+    """Put a worker into maintenance mode."""
+    # Check if worker exists first
+    worker_query = select(EdgeWorkerModel).where(EdgeWorkerModel.worker_name 
== worker_name)
+    worker = session.scalar(worker_query)
+    if not worker:
+        raise HTTPException(status_code=404, detail=f"Worker {worker_name} not 
found")
+
+    # Format the comment with timestamp and username (username will be added 
by plugin layer)
+    formatted_comment = f"[{datetime.now().strftime('%Y-%m-%d %H:%M')}] - UI 
user put node into maintenance mode\nComment: 
{maintenance_request.maintenance_comment}"
+
+    try:
+        request_maintenance(worker_name, formatted_comment, session=session)
+        session.commit()  # Explicitly commit the transaction

Review Comment:
   Done!



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to