dheerajturaga commented on code in PR #49915:
URL: https://github.com/apache/airflow/pull/49915#discussion_r2065360590
##########
providers/edge3/src/airflow/providers/edge3/cli/edge_command.py:
##########
@@ -619,6 +623,110 @@ def stop(args):
logger.info("Worker has been shut down.")
+@providers_configuration_loaded
+@provide_session
+def _fetch_edge_hosts_from_db(session: Session = NEW_SESSION) -> list:
+ from airflow.providers.edge3.models.edge_worker import EdgeWorkerModel
+
+ return
session.scalars(select(EdgeWorkerModel).order_by(EdgeWorkerModel.worker_name)).all()
+
+
+@cli_utils.action_cli
+@providers_configuration_loaded
+@provide_session
+def list_edge_workers(args, session: Session = NEW_SESSION) -> None:
+ """
+ Query the db to list all registered edge workers
+ """
+ all_hosts_iter = _fetch_edge_hosts_from_db(session)
+ # Format and print worker info on the screen
+ fields = [
+ "worker_name",
+ "state",
+ "queues",
+ "jobs_active",
+ "jobs_success",
+ "jobs_failed",
+ "jobs_taken",
+ "maintenance_comment",
+ ]
+ all_hosts = [{f: str(host.__getattribute__(f)) for f in fields} for host
in all_hosts_iter]
+ # Filter hosts by state
+ if args.state:
+ all_hosts = [host for host in all_hosts if host["state"] in args.state]
+ AirflowConsole().print_as(data=all_hosts, output=args.output)
+
+
+@providers_configuration_loaded
+@provide_session
+def _valid_host(hostname, session: Session = NEW_SESSION) -> bool:
+ """
+ Query the database to check if provided hostname exists
+ """
+ all_hosts_iter = _fetch_edge_hosts_from_db(session)
+ for host in all_hosts_iter:
+ if hostname == host.worker_name:
+ return True
+ return False
Review Comment:
I see what you are saying. Currently I updated to query the db directly. Let
me see if I can update the edge worker model
--
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]