From 39bdd8072f678de20dd1858fe36f59761d9e6474 Mon Sep 17 00:00:00 2001 From: ajitmp Date: Wed, 31 Jul 2024 16:45:20 +0900 Subject: [PATCH] Trying to add support for new version of scrapyd1.5.0b1, updated wrapper and constants for new api support 'status'. However testing not done because of old python versions --- scrapyd_api/constants.py | 8 +++++++- scrapyd_api/wrapper.py | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/scrapyd_api/constants.py b/scrapyd_api/constants.py index 48c95fc..236b7c0 100644 --- a/scrapyd_api/constants.py +++ b/scrapyd_api/constants.py @@ -10,6 +10,9 @@ LIST_VERSIONS_ENDPOINT = 'list_versions' SCHEDULE_ENDPOINT = 'schedule' DAEMON_STATUS_ENDPOINT = 'daemonstatus' +# status.json endpoint added in 1.5.0 +# Get the status of a job +STATUS_ENDPOINT = 'status' DEFAULT_ENDPOINTS = { ADD_VERSION_ENDPOINT: '/addversion.json', @@ -21,7 +24,10 @@ LIST_SPIDERS_ENDPOINT: '/listspiders.json', LIST_VERSIONS_ENDPOINT: '/listversions.json', SCHEDULE_ENDPOINT: '/schedule.json', - DAEMON_STATUS_ENDPOINT: '/daemonstatus.json' + DAEMON_STATUS_ENDPOINT: '/daemonstatus.json', + # status.json endpoint added in 1.5.0 + # Get the status of a job + STATUS_ENDPOINT: 'status.json' } FINISHED = 'finished' diff --git a/scrapyd_api/wrapper.py b/scrapyd_api/wrapper.py index f6a2d67..fb473de 100644 --- a/scrapyd_api/wrapper.py +++ b/scrapyd_api/wrapper.py @@ -196,3 +196,15 @@ def daemon_status(self): url = self._build_url(constants.DAEMON_STATUS_ENDPOINT) json = self.client.get(url, timeout=self.timeout) return json + + def status(self, job): + """ + Added in Scrapyd version 1.5.0. + Get the status of a job. + First class, maps to Scrapyd's status job endpoint. + """ + url = self._build_url(constants.STATUS_ENDPOINT) + params = {'job': job} + json = self.client.get(url, params=params, timeout=self.timeout) + return json['currstate'] + \ No newline at end of file