Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

evenicoulddoit
Copy link
Contributor

  • A failure_reported flag added to each log entry, which is used to avoid notifying users multiple times about the same failed job
  • Uses >= to account for when the job in question has run multiple times before the notification job runs
  • Allows for global settings config to redefine the default number of failures as well as the from and to emails
  • Separates concerns to allow users to extend the notifier and report failures using a different method of their choosing
  • Doesn't consider itself when iterating over jobs

@coveralls
Copy link

coveralls commented Nov 29, 2016

Coverage Status

Coverage increased (+0.9%) to 90.698% when pulling c2f16d6 on HousekeepLtd:failed-notifications-improvements into 57bd912 on Tivix:master.

@coveralls
Copy link

coveralls commented Nov 30, 2016

Coverage Status

Coverage increased (+0.9%) to 90.698% when pulling c44e552 on HousekeepLtd:failed-notifications-improvements into 57bd912 on Tivix:master.

@coveralls
Copy link

coveralls commented Nov 30, 2016

Coverage Status

Coverage increased (+0.9%) to 90.698% when pulling cdb858a on HousekeepLtd:failed-notifications-improvements into 57bd912 on Tivix:master.

@evenicoulddoit evenicoulddoit force-pushed the failed-notifications-improvements branch from cdb858a to c1e3614 Compare November 30, 2016 12:18
@coveralls
Copy link

coveralls commented Nov 30, 2016

Coverage Status

Coverage increased (+0.9%) to 90.698% when pulling c1e3614 on HousekeepLtd:failed-notifications-improvements into 57bd912 on Tivix:master.

4 similar comments
@coveralls
Copy link

coveralls commented Nov 30, 2016

Coverage Status

Coverage increased (+0.9%) to 90.698% when pulling c1e3614 on HousekeepLtd:failed-notifications-improvements into 57bd912 on Tivix:master.

@coveralls
Copy link

coveralls commented Nov 30, 2016

Coverage Status

Coverage increased (+0.9%) to 90.698% when pulling c1e3614 on HousekeepLtd:failed-notifications-improvements into 57bd912 on Tivix:master.

@coveralls
Copy link

coveralls commented Nov 30, 2016

Coverage Status

Coverage increased (+0.9%) to 90.698% when pulling c1e3614 on HousekeepLtd:failed-notifications-improvements into 57bd912 on Tivix:master.

@coveralls
Copy link

coveralls commented Nov 30, 2016

Coverage Status

Coverage increased (+0.9%) to 90.698% when pulling c1e3614 on HousekeepLtd:failed-notifications-improvements into 57bd912 on Tivix:master.

@coveralls
Copy link

coveralls commented Dec 1, 2016

Coverage Status

Coverage increased (+0.9%) to 90.698% when pulling fccc6df on HousekeepLtd:failed-notifications-improvements into db4a5cc on Tivix:master.

Copy link
Contributor

@tab-cmd tab-cmd left a 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 👍

"""
RUN_EVERY_MINS = 30
RUN_EVERY_MINS = 0
Copy link
Contributor

@tab-cmd tab-cmd Jan 13, 2017

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()
Copy link
Contributor

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

@@ -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
Copy link
Contributor

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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class not classes


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]
Copy link
Contributor

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
Copy link
Contributor

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:
Copy link
Contributor

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?

Copy link
Contributor Author

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
@evenicoulddoit
Copy link
Contributor Author

@sci-tab thanks for going through the PR, should have addressed all your comments

@coveralls
Copy link

coveralls commented Jan 15, 2017

Coverage Status

Coverage increased (+1.4%) to 91.246% when pulling d66f068 on HousekeepLtd:failed-notifications-improvements into db4a5cc on Tivix:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants