-
Notifications
You must be signed in to change notification settings - Fork 74
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
FIX: Correctly log errors during job initialisation (fixes #316) #374
Conversation
Are there some steps I can follow to ensure a job breaks during initialisation in order to test this?
Maybe that should be extracted into its own method so we can reuse the same code? That way if the way we instantiate these changes, we can remain consistent. |
To recreate this you just need a job to throw an exception in its I don’t think this fix is complete after all because if the exception shown above (
That would allow us to handle the exception-during-initialisation flow differently, so no need to adjust method signatures and break BC |
c370b27
to
1f97a1c
Compare
Okay I’ve pushed an alternative solution |
1f97a1c
to
c2580f3
Compare
c2580f3
to
8e4ba4f
Compare
Looks good from a code perspective. Will try to make some time tomorrow to test it locally just to be sure it does catch those errors. |
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.
Gotta love when you see a comment from yourself a week later that says "tomorrow" on it.... sorry about that.
Looks good locally except:
Doesn't log the exception to the job's messages
This does catch and mark the exception and marks the job as broken which is a big improvement on the current state of things - but it doesn't add the exception information to the job's messages like exceptions later in the lifecycle do.
Looks like that's because addJobHandlersToLogger()
isn't called until later, which expects a QueuedJob
instance (which we obviously don't have at this stage) to pass to QueuedJobHandler
.
I don't think QueuedJobHandler
should explicitly require a QueuedJob
instance (messages are stored on the QueuedJobDescriptor
anyway which we do have) - but since it does, we can't just add that handler to the logger.
Next steps
I think we should create a new handler (to either be replaced by QueuedJobHandler
or else to be used for this specific situation - preferable the former with QueuedJobHandler
being deprecated) which doesn't require a QueuedJob
instance.
I don't know if that should be done as part of this PR (it could be considered part of "correctly" logging errors) or as a follow-up. If it's a follow-up, then I'm happy with this PR as-is. It is at least an improvement on the current state of things.
@kinglozzer do you have any thoughts about whether logging the message should be done with or after thIs PR? |
I think it’d need to be done separately - we can’t switch out |
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.
Works well locally. Doesn't log these errors in the message for the job, but that can be follow-up work as discussed.
At least it logs them correctly in the logger which is an improvement over the existing behaviour.
I have created #384 for the follow-up work of passing the error as a message into the job to be viewed in the CMS UI. |
Tagged as 4.10.1 |
The alternative to this is changing the the signature of
handleBrokenJobException()
to make the second param optional with= null
, which is technically a BC-break. This method of instantiating a job object is exactly whatinitialiseJob
does:silverstripe-queuedjobs/src/Services/QueuedJobService.php
Lines 676 to 683 in 84fc3e2