-
Notifications
You must be signed in to change notification settings - Fork 195
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
Update FailedRunsNotificationCronJob to report more clearly #101
base: master
Are you sure you want to change the base?
Update FailedRunsNotificationCronJob to report more clearly #101
Conversation
cdb858a
to
c1e3614
Compare
4 similar comments
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.
This looks pretty good, I left some comments for you to address. Once done, I will test locally again and merge. Thanks for the contributions 👍
django_cron/cron.py
Outdated
""" | ||
RUN_EVERY_MINS = 30 | ||
RUN_EVERY_MINS = 0 |
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.
Put this in settings to and add to readme. There may be a case when someone won't want this to run every time their crons run
|
||
schedule = Schedule(run_every_mins=RUN_EVERY_MINS) | ||
code = 'django_cron.FailedRunsNotificationCronJob' | ||
|
||
def do(self): | ||
self.config = self.get_config() |
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.
add documentation as you do below
docs/sample_cron_configurations.rst
Outdated
@@ -59,7 +59,7 @@ This will run job every 2h plus one run at 6:30. | |||
Allowing parallels runs | |||
----------------------- | |||
|
|||
By deafult parallels runs are not allowed (for security reasons). However if you | |||
By default parallels runs are not allowed (for security reasons). However if you |
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.
while you're here: should be By default parallel
runs ...
""" | ||
Report in Slack that the given Cron job failed. | ||
""" | ||
slack.post("ERROR - Cron job '{0}' failed.".format(cron_cls.code)) |
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
django_cron/cron.py
Outdated
A regular job to send email reports for failed Cron jobs. | ||
|
||
The job log is used to check for all unreported failures for each job | ||
classes specified within the CRON_CLASSES dictionary. When the number of |
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.
class
not classes
django_cron/cron.py
Outdated
|
||
schedule = Schedule(run_every_mins=RUN_EVERY_MINS) | ||
code = 'django_cron.FailedRunsNotificationCronJob' | ||
|
||
def do(self): | ||
self.config = self.get_config() | ||
cron_classes = [get_class(c_name) for c_name in settings.CRON_CLASSES] |
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.
Be as explicit as possible throughout. c_name
to class_name
, cron_cls
to cron_class
(this is referenced a lot), and avoid single letter variables. While it isn't difficult to follow it would be nice.
This sample cron job checks for any unreported failed jobs for each job class | ||
provided in your ``CRON_CLASSES`` list, and reports them as necessary. The job | ||
is set to run on each ``runcrons`` task, and the default process is to email | ||
all the users specified in the ``ADMINS`` settings list when a job fails more |
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.
the default process is to email all the users specified in the
ADMINS
settings list when a job fails more ...
add using the default from email from settings list as well
if not job.is_success: | ||
failures += 1 | ||
message += 'Job ran at %s : \n\n %s \n\n' % (job.start_time, job.message) | ||
if len(failed_reports) > 1: |
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.
shouldn't this always be true / == to the min_failures? Why not just define times before first definition of subject and add to it there?
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.
Not necessarily, because the failed report job doesn't have to run every time that another job does. For example, you could set the failed reported to run every day, so its entirely possible for the number of failures to exceed the MIN_NUM_FAILURES
option.
* Fix typos in documentation * Add a docstring to `do()` * Namespace configuration, and add documentation for all settings * Extend test coverage
@sci-tab thanks for going through the PR, should have addressed all your comments |
edf6cd4
to
c0bbe43
Compare
failure_reported
flag added to each log entry, which is used to avoid notifying users multiple times about the same failed job>=
to account for when the job in question has run multiple times before the notification job runs