From d0d3769fd242bb3049b72cf43a13a14b99d3a911 Mon Sep 17 00:00:00 2001 From: James McKinney <26463+jpmckinney@users.noreply.github.com> Date: Mon, 15 Jul 2024 13:03:13 -0400 Subject: [PATCH] fix: Add try/except for jobs_to_keep deletions, closes #159 --- docs/news.rst | 1 + scrapyd/environ.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/news.rst b/docs/news.rst index 3f6068bc..eaaa829b 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -25,6 +25,7 @@ Fixed ~~~~~ - The :ref:`cancel.json` webservice now works on Windows. +- The :ref:`jobs_to_keep` setting no longer causes an error if a file to delete can't be deleted (for example, if the file is open on Windows). - When managing multiple projects, the next pending job for all but one project was unreported by the :ref:`daemonstatus.json` and :ref:`listjobs.json` webservices, and was not cancellable by the :ref:`cancel.json` webservice. 1.4.3 (2023-09-25) diff --git a/scrapyd/environ.py b/scrapyd/environ.py index 326d88b3..01d32ff4 100644 --- a/scrapyd/environ.py +++ b/scrapyd/environ.py @@ -70,5 +70,8 @@ def _get_file(self, message, dir, ext): key=os.path.getmtime, )[:-self.jobs_to_keep] for x in to_delete: - os.remove(x) + try: + os.remove(x) + except OSError: + pass return os.path.join(absdir, "%s.%s" % (message['_job'], ext))