-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
CRM-21460 Add job execution hooks #11337
Conversation
@rthouvenin Thank you for this work! I had considered the same problem previously, and had wanted to change the database schema to allow monitoring of scheduled jobs. I can see the advantages of this approach though. My one concern about this approach is that in the past, I've had some jobs fail in such a way that the job never completes. I see a Some examples I recall are:
|
@MegaphoneJon Wouldn't this kind of situations (job starts but never finishes) be detectable when log entry is recorded for both preJob and postJob? You would just look for jobs that have odd number of entries in the log (and potentially something else, e.g. expected execution time is exceeded x 2). |
I'm not sure there is a way to catch when a process is killed/dies, never completes because it gets blocked, but I will say that is probably the highest priority. |
I'm comfortable with this approach. |
And this is where I get confused: A job is supposed to be a saved API call. If we're passing in the params on a per-request basis, then it's not a saved API call -- it's just a regular, plain old API call that's been hacked-up to look like a saved API call. Now if we really push through this question... there are differences:
These differences feel arbitrary to me -- they've conflated things that should be orthogonal:
If we wanted to translate this rant into some kind of change... we'd probably beef-up authentication options for But that's a bit of rant -- and probably outside the intended scope of this PR.
|
@totten Thanks for the feedback, and the rant too! Gives some insights and perspective :) @MegaphoneJon @JoeMurray I also think this is an important use case to catch. One solution is the one suggested by Michał: periodically check if there are jobs that started but haven't reported a result for too long. Monitoring tools such as Nagios or Sensu have built-in support of this: you can configure a check to emit an alert if no result was reported for a certain period of time. Of course this works only for periodic jobs. One-off jobs or jobs on events have to explicitely report the beginning or their execution, and another process emits an alert if no result was reported after a timeout. |
I haven't read this whole PR but I did notice that it appears to be adding two new hooks without any docs for those hooks. @rthouvenin can you add a PR to the Dev Guide with docs? Then we can merge that Dev Guide PR when this Core PR is merged. If you need help figuring out how to add the docs, ping me in Mattermost. |
@seanmadsen Thanks for reminding. I did think about it, but wanted to have confirmation the change will be merged before spending time on documenting it. |
Just revisting this - the recap was "Recap: @rthouvenin, take a look at the generic API events. If you still think that job-specific hooks are necessary, then I'm OK with this. The implementation looks clean (r-code) and generally safe (r-user and r-tech), and the existence of https://github.com/WeMoveEU/sencivity implies that you are r-running it." And I feel that @rthouvenin has done as asked so I'm going with " then I'm OK with this" merging |
Overview
Implements the solution suggested in CRM-21460 to allow monitoring / storing the scheduled job execution results, assuming this is the right direction.
Before
At the moment the job log does not store any structured information about the execution status, only a message in a freetext format. One would have to parse localized messages to extract whether jobs have succeeded or not.
After
Two new hooks:
preJob
andpostJob
called right before and after the execution of a scheduled job. Rather than storing new info in the log table, hooks let implementers chose what to do with the info, and whether they want to store it or immediately act upon it.Technical Details
Having both a pre and a post hook is mostly to measure execution time or detect stuck jobs. The pre hook doesn't give the job and params objects by reference, so the hook is not meant to alter the job before its execution.
In the post hook, the result can also be an exception object when the job execution was interrupted by an exception.
Comments
See Sencivity for an example of how these hooks can be used.