diff options
author | Jon Turney <jon.turney@dronecode.org.uk> | 2017-04-12 14:21:44 +0300 |
---|---|---|
committer | Jon Turney <jon.turney@dronecode.org.uk> | 2017-04-12 14:24:53 +0300 |
commit | eca884d381ce3d1ab5e430850ad54b64aec48f14 (patch) | |
tree | 1c9491f0527a64c13da973937abc1020f2cc734b | |
parent | 1f4e125ab00389c54a03c9d703c414e4e7ce3584 (diff) |
Log exceptions in daemon mode
-rwxr-xr-x | calm/calm.py | 75 |
1 files changed, 39 insertions, 36 deletions
diff --git a/calm/calm.py b/calm/calm.py index c01bc1a..0a66074 100755 --- a/calm/calm.py +++ b/calm/calm.py @@ -489,42 +489,45 @@ def do_daemon(args, state): state.packages = {} - while running: - with mail_logs(args.email, toaddrs=args.email, subject='%s' % (state.subject), thresholdLevel=logging.ERROR) as leads_email: - # re-read relarea on SIGALRM or SIGUSR2 - if read_relarea: - read_relarea = False - state.packages = process_relarea(args) - - if not state.packages: - logging.error("not processing uploads or writing setup.ini") - else: - if read_uploads: - # read uploads on SIGUSR1 - read_uploads = False - state.packages = process_uploads(args, state) - - do_output(args, state) - - # if there is more work to do, but don't spin if we can't do it - if read_uploads: - continue - - # we wake at a 10 minute offset from the next 30 minute boundary - # (i.e. at :10 or :40 past the hour) to check the state of the - # release area, in case someone has ninja-ed in a change there... - interval = 30*60 - offset = 10*60 - delay = interval - ((time.time() - offset) % interval) - signal.alarm(int(delay)) - - # wait until interrupted by a signal - logging.info("sleeping for %d seconds" % (delay)) - signal.pause() - logging.info("woken") - - # cancel any pending alarm - signal.alarm(0) + try: + while running: + with mail_logs(args.email, toaddrs=args.email, subject='%s' % (state.subject), thresholdLevel=logging.ERROR) as leads_email: + # re-read relarea on SIGALRM or SIGUSR2 + if read_relarea: + read_relarea = False + state.packages = process_relarea(args) + + if not state.packages: + logging.error("not processing uploads or writing setup.ini") + else: + if read_uploads: + # read uploads on SIGUSR1 + read_uploads = False + state.packages = process_uploads(args, state) + + do_output(args, state) + + # if there is more work to do, but don't spin if we can't do it + if read_uploads: + continue + + # we wake at a 10 minute offset from the next 30 minute boundary + # (i.e. at :10 or :40 past the hour) to check the state of the + # release area, in case someone has ninja-ed in a change there... + interval = 30*60 + offset = 10*60 + delay = interval - ((time.time() - offset) % interval) + signal.alarm(int(delay)) + + # wait until interrupted by a signal + logging.info("sleeping for %d seconds" % (delay)) + signal.pause() + logging.info("woken") + + # cancel any pending alarm + signal.alarm(0) + except Exception as e: + logging.error("exception %s" % (type(e).__name__), exc_info=True) logging.info("calm daemon stopped") |