From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17944 invoked by alias); 12 Apr 2017 11:32:45 -0000 Mailing-List: contact cygwin-apps-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cygwin-apps-cvs-owner@sourceware.org Received: (qmail 17903 invoked by uid 9795); 12 Apr 2017 11:32:44 -0000 Date: Wed, 12 Apr 2017 11:32:00 -0000 Message-ID: <20170412113244.17877.qmail@sourceware.org> From: jturney@sourceware.org To: cygwin-apps-cvs@sourceware.org Subject: [calm - Cygwin server-side packaging maintenance script] branch master, updated. 20160705-65-geca884d X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 1f4e125ab00389c54a03c9d703c414e4e7ce3584 X-Git-Newrev: eca884d381ce3d1ab5e430850ad54b64aec48f14 X-SW-Source: 2017-q2/txt/msg00011.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/calm.git;h=eca884d381ce3d1ab5e430850ad54b64aec48f14 commit eca884d381ce3d1ab5e430850ad54b64aec48f14 Author: Jon Turney Date: Wed Apr 12 12:21:44 2017 +0100 Log exceptions in daemon mode Diff: --- 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")