Repository navigation
fix(scheduler): stop a running job before deleting it - #4040
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
DELETE /api/admin/scheduler/setting/{id}accepted a running job. The job was removed, its crawler process keptrunning, and
PUT /api/admin/scheduler/{id}/stopthen 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#stopIfRunningbefore deleting. It stops the job the way the stopendpoint 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_jobmessage (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 deletedwithout 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.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.).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.