diff --git a/docs/news.rst b/docs/news.rst index af92ef9d..4754d7cf 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -11,6 +11,7 @@ This release contains the most changes in a decade. Therefore, a beta release is Added ~~~~~ +- Add ``version`` (egg version), ``settings`` (Scrapy settings) and ``args`` (spider arguments) to the pending jobs in the response from the :ref:`listjobs.json` webservice. - Add a :ref:`status.json` webservice, to get the status of a job. - Add a :ref:`unix_socket_path` setting, to listen on a Unix socket. - Add a :ref:`poller` setting. @@ -172,7 +173,7 @@ Fixed Added ~~~~~ -- Add ``log_url`` and ``items_url`` to the response from the :ref:`listjobs.json` webservice. (@mxdev88) +- Add ``log_url`` and ``items_url`` to the finished jobs in the response from the :ref:`listjobs.json` webservice. (@mxdev88) - Scrapy 2.8 support. Scrapyd sets ``LOG_FILE`` and ``FEEDS`` command-line arguments, instead of ``SCRAPY_LOG_FILE`` and ``SCRAPY_FEED_URI`` environment variables. - Python 3.11 support. - Python 3.12 support. Use ``packaging.version.Version`` instead of ``distutils.LooseVersion``. (@pawelmhm) @@ -213,6 +214,7 @@ Added - Add :ref:`username` and :ref:`password` settings, for HTTP authentication. - Add :ref:`jobstorage` and :ref:`eggstorage` settings. - Add a ``priority`` argument to the :ref:`schedule.json` webservice. +- Add ``project`` to all jobs in the response from the :ref:`listjobs.json` webservice. - Add shortcut to jobs page to cancel a job using the :ref:`cancel.json` webservice. - Python 3.7, 3.8, 3.9, 3.10 support. @@ -262,7 +264,7 @@ Added - Add the :ref:`daemonstatus.json` webservice. - Add a ``_version`` argument to the :ref:`schedule.json` and :ref:`listspiders.json` webservices. - Add a ``jobid`` argument to the :ref:`schedule.json` webservice. - - Add the run's PID to the response of the :ref:`listjobs.json` webservice. + - Add ``pid`` to the running jobs in the response from the :ref:`listjobs.json` webservice. - Include full tracebacks from Scrapy when failing to get spider list. This makes debugging deployment problems easier, but webservice output noisier. @@ -329,7 +331,7 @@ Added ~~~~~ - Add ``node_name`` (hostname) to webservice responses. (:commit:`fac3a5c`, :commit:`4aebe1c`) -- Add ``start_time`` to the response from the :ref:`listjobs.json` webservice. (:commit:`6712af9`, :commit:`acd460b`) +- Add ``start_time`` to the running jobs in the response from the :ref:`listjobs.json` webservice. (:commit:`6712af9`, :commit:`acd460b`) Changed ~~~~~~~ diff --git a/scrapyd/webservice.py b/scrapyd/webservice.py index 9d8282f8..2e60f887 100644 --- a/scrapyd/webservice.py +++ b/scrapyd/webservice.py @@ -339,6 +339,8 @@ class ListJobs(WsResource): The ``project`` parameter is optional. Add ``project`` to all jobs in the response. .. versionchanged:: 1.4.0 Add ``log_url`` and ``items_url`` to finished jobs in the response. + .. versionchanged:: 1.5.0 + Add ``version``, ``settings`` and ``args`` to pending jobs in the response. """ @param("project", required=False) @@ -351,7 +353,14 @@ def render_GET(self, txrequest, project): "node_name": self.root.nodename, "status": "ok", "pending": [ - {"project": queue_name, "spider": message["name"], "id": message["_job"]} + { + "project": queue_name, + "spider": message["name"], + "id": message["_job"], + "version": message.get("_version"), + "settings": message.get("settings", {}), + "args": {k: v for k, v in message.items() if k not in ("name", "_job", "_version", "settings")}, + } for queue_name in (queues if project is None else [project]) for message in queues[queue_name].list() ], diff --git a/tests/test_webservice.py b/tests/test_webservice.py index d3e80b71..74312921 100644 --- a/tests/test_webservice.py +++ b/tests/test_webservice.py @@ -312,13 +312,23 @@ def test_list_jobs(txrequest, root, scrapy_process, args): ) assert_content(txrequest, root, "GET", "listjobs", args, expected) - root.poller.queues["p1"].add("s1", _job="j1") + root.poller.queues["p1"].add( + "s1", + priority=5, + _job="j1", + _version="0.1", + settings={"DOWNLOAD_DELAY=2": "TRACK=Cause = Time"}, + other="one", + ) expected["pending"].append( { "id": "j1", "project": "p1", "spider": "s1", + "version": "0.1", + "settings": {"DOWNLOAD_DELAY=2": "TRACK=Cause = Time"}, + "args": {"other": "one"}, }, ) assert_content(txrequest, root, "GET", "listjobs", args, expected)