From 01e473d63195524fd87abe6c5ae5f0ea1f14c6be Mon Sep 17 00:00:00 2001 From: Valeriia Klestova <123654509+vlerkin@users.noreply.github.com> Date: Wed, 18 Sep 2024 10:30:52 +0200 Subject: [PATCH] Finish daemonstatus endpoint (#23, PR #32) --- scrapyd_k8s/api.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scrapyd_k8s/api.py b/scrapyd_k8s/api.py index 90c50bc..24c7dd7 100644 --- a/scrapyd_k8s/api.py +++ b/scrapyd_k8s/api.py @@ -25,7 +25,14 @@ def healthz(): @app.get("/daemonstatus.json") def api_daemonstatus(): - return { "status": "ok", "spiders": 0 } + jobs = list(launcher.listjobs()) + return { + "node_name": config.scrapyd().get("node_name", launcher.get_node_name()), + "status": "ok", + "pending": len([j for j in jobs if j['state'] == 'pending']), + "running": len([j for j in jobs if j['state'] == 'running']), + "finished": len([j for j in jobs if j['state'] == 'finished']) + } @app.post("/schedule.json") def api_schedule():