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