Skip to content

fix(scheduler): stop a running job before deleting it - #4040

Merged
marevol merged 1 commit into
mainfrom
fix/delete-running-scheduled-job
Dec 4, 2026
Merged

marevol merged 1 commit into
mainfrom
fix/delete-running-scheduled-job

Conversation

@marevol

@marevol marevol commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Problem

DELETE /api/admin/scheduler/setting/{id} accepted a running job. The job was removed, its crawler process kept
running, and PUT /api/admin/scheduler/{id}/stop then answered 400, so the process could not be stopped any more.
The admin screen offers no Delete for a running job, but a page that was shown before the job started still does, and
that request had the same effect.

Change

Both delete paths call ScheduledJobService#stopIfRunning before deleting. It stops the job the way the stop
endpoint does and, because a stop only interrupts the job thread, waits up to 30 seconds for the job to end. If the
job cannot be stopped or is still running after that, the request fails with the existing errors.failed_to_stop_job
message (400 for the API) and the job is not deleted.

A script that ignores the interrupt therefore holds the delete request for 30 seconds before it fails; it can be
deleted once it has ended. The stop endpoint itself is unchanged. As for the stop endpoint, only a job running on the
node that serves the request is seen as running.

Tests

  • ApiAdminSchedulerActionTest: a running job is stopped and has ended before it is deleted; an idle job is deleted
    without a stop; a job that does not end is not deleted. The first and the last fail without the change.
  • ApiAdminSchedulerActionTest, ScriptExecutorJobTest, ScheduledJob*Test, JobHelperTest: 57 tests, 0 failures.
  • The admin screen path has no unit test; it was checked live only.
  • Checked live with a crawl that does not end, before and after, through the API and through the admin screen with a
    details page loaded before the job started. Before: the delete succeeded and the crawler kept requesting pages.
    After: the delete succeeded within a second, no crawler process was left, and the job log recorded the run as failed
    (Crawler Process terminated.).
  • Checked live with a script that ignores the interrupt. Before: an API delete succeeded and the script ran to its end.
    After: the delete failed after 30 seconds with the job still there, through the API and through the admin screen, and
    an API delete succeeded once the script had ended.

Deleting a running job through the admin API left its process running: the
crawler kept crawling, and the job could no longer be stopped. Stop the job
first and wait up to 30 seconds for it to end. If it does not end, report the
failure and keep the job. The admin screen does the same for a job that has
started since its page was shown.
@marevol marevol added this to the 15.10.0 milestone Dec 4, 2026
@marevol marevol added the bug label Dec 4, 2026
@marevol marevol self-assigned this Dec 4, 2026
@marevol
marevol merged commit 5f103e7 into main Dec 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant