Skip to content

Commit

Permalink
feat: Add version, settings, args to pending jobs in listjobs.json, c…
Browse files Browse the repository at this point in the history
…loses #205
  • Loading branch information
jpmckinney committed Jul 24, 2024
1 parent aa40ad8 commit 7a2791a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
8 changes: 5 additions & 3 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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
~~~~~~~
Expand Down
11 changes: 10 additions & 1 deletion scrapyd/webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
],
Expand Down
12 changes: 11 additions & 1 deletion tests/test_webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7a2791a

Please sign in to comment.