-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle error handling for deleted tasks #293
Conversation
@@ -90,7 +90,7 @@ def after_perform | |||
end | |||
|
|||
def on_error(error) | |||
@ticker.persist | |||
@ticker.persist if defined?(@ticker) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the variable would not be defined? Because before_perform
did run?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before_perform
runs but has an exception before @ticker
is set, on line 57:
maintenance_tasks/app/jobs/maintenance_tasks/task_job.rb
Lines 55 to 62 in 42fd4ee
def before_perform | |
@run = arguments.first | |
@task = Task.named(@run.task_name).new | |
@run.job_id = job_id | |
@run.running! unless @run.stopping? | |
@ticker = Ticker.new(MaintenanceTasks.ticker_delay) do |ticks, duration| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first I just used @ticker&.persist
but it didn't pass the test because we use verbose mode. We could also add a @ticker = nil
at the beginning of before_perform
too but I felt that would feel weird.
Worth noting that a similar exception could happen if there's a job for a run that is then removed, except the exception would be during deserialization, but then in This PR solves an issue that can happen with a simple rollback before the job starts running or while the job is still running (it will be interrupted, then would fail upon resuming). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice find Étienne! Changes LGTM, all was as expected on the tophat 👍
One small request, could we tweak:
# enqueued -> errored occurs when the task job fails to be enqueued. |
to add
# enqueued -> errored occurs when the task job fails to be enqueued,
or if the Task is deleted before is starts running.
42fd4ee
to
dbe3234
Compare
If a Task is enqueued and is then deleted before being performed, or if a Task is interrupted and deleted, it results in a crash.
To repro:
Start a server, visit http://localhost:3000/maintenance_tasks/tasks/Maintenance::UpdatePostsTask, start a run then:
This is fixed by the first commit.
This is fixed by the second commit: