Merge lp:~jcsackett/launchpad/bug-expiration-doesnt-oops into lp:launchpad
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | j.c.sackett | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 12888 | ||||
Proposed branch: | lp:~jcsackett/launchpad/bug-expiration-doesnt-oops | ||||
Merge into: | lp:launchpad | ||||
Diff against target: |
27 lines (+10/-4) 1 file modified
cronscripts/expire-bugtasks.py (+10/-4) |
||||
To merge this branch: | bzr merge lp:~jcsackett/launchpad/bug-expiration-doesnt-oops | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Robert Collins (community) | Approve | ||
Review via email: mp+58412@code.launchpad.net |
Commit message
Adds some exception catching and Oops logging to a previously patched problem area in expire-bugtasks.py
Description of the change
Summary
=======
The bug expiration script wasn't working due to a permisions error, but because it wasn't logging the issue no Oops was raised.
The major parts of setting up the script and running the expiration job are now enclosed in try/excepts that log any errors to the Oops handler.
Preimplementation
=================
Spoke with Curtis Hovey
Implementation
==============
Added try/excepts around the initialization of the BugJanitor and the janitor running it's expiration job. The excepts are catchalls because we can't predict what might happen--anything expected should be handled within the routines called, this is a last-ditch "at least log it" measure.
Tests
=====
I cannot for the life of me figure out how to test a cronjob itself. The actual expiration code used by the cronjob is already tested, and the error actually occurs when the cronscript itself is run. If there is a utility to test cronscript/crontabs that I am unaware of, I am happy to implement tests for this.
QA
==
qa-untestable. This will only come into being if we encounter a new error. If necessary, we can alter security.cfg to reintroduce the error we originally discovered and see if it gets logged properly.
Lint
====
= Launchpad lint =
Checking for conflicts and issues in changed files.
Linting changed files:
cronscripts/
./cronscripts/
16: '_pythonpath' imported but unused
33: E222 multiple spaces after operator
So, I'm ok on the testing aspect, but the code needs to be correct :)
try:
foo = bar
except Exception:
..
try:
foo.quux()
except Exception:
..
is going to fail horridly because foo won't be assigned in the second try:except: block.
You can write this correctly as:
try:
foo = bar
except Exception:
..
else:
try:
foo.quux()
except Exception:
..
But I think that really all you need is:
try:
foo = bar
foo.quux()
except Exception:
..
raise
e.g. (and I've improved the use of logging here too): options. limit) expireBugTasks( self.txn)
+ try:
+ janitor = BugJanitor(
+ log=self.logger, target=target, limit=self.
+ janitor.
+ except Exception:
+ self.logger.error(
+ 'An error occured trying to expire bugtasks.', exc_info=1)
+ raise
The raise is there because we shouldn't swallow exceptions unless we have corrected the error - and we haven't. It may not be needed (I haven't checked to see if that was the last line in the script) but its safer to assume its needed - or put a comment in on why its not, as catchall excepts really are, well, the exception.