Merge lp:~gmb/launchpad/not-nullify-bwa.result-bug-546774 into lp:launchpad/db-devel

Proposed by Graham Binns
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~gmb/launchpad/not-nullify-bwa.result-bug-546774
Merge into: lp:launchpad/db-devel
Diff against target: 185 lines (+51/-14)
7 files modified
database/schema/patch-2207-47-0.sql (+6/-0)
lib/lp/bugs/doc/bug-watch-activity.txt (+9/-5)
lib/lp/bugs/interfaces/bugwatch.py (+14/-0)
lib/lp/bugs/model/bugwatch.py (+6/-1)
lib/lp/bugs/scripts/checkwatches/scheduler.py (+4/-4)
lib/lp/bugs/stories/bugwatches/xx-bugwatch-errors.txt (+8/-2)
lib/lp/bugs/tests/test_bugwatch.py (+4/-2)
To merge this branch: bzr merge lp:~gmb/launchpad/not-nullify-bwa.result-bug-546774
Reviewer Review Type Date Requested Status
Björn Tillenius (community) db Approve
Gavin Panella (community) code Approve
Stuart Bishop (community) db Approve
Review via email: mp+22934@code.launchpad.net

Commit message

Make BugWatchActivity.result NOT NULL and add a default SYNC_SUCCESS BugWatchActivityStatus.

Description of the change

This branch adds a DB patch to make BugWatchActivity.result NOT NULL,
updates all existing BugWatchActivity's with a NULL result to have a
result of BugWatchActivityStatus.SYNC_SUCCESS, which is now our base
success status.

== database/schema/patch-2207-99-0.sql ==

 - This patch updates all existing BugWatchActivity records with a NULL
   result to have a result value of 9, which corresponds with
   BugWatchActivityStatus.SYNC_SUCCESS.
 - The patch also makes BugWatchActivity.result NOT NULL.

== lib/lp/bugs/doc/bug-watch-activity.txt ==

 - I've updated the tests to account for the fact that
   BugWatchActivity.result can't now be None.

== lib/lp/bugs/interfaces/bugwatch.py ==

 - I've added a SYNC_SUCCESS status to BugWatchActivityStatus.
 - I've added a list of BugWatchActivityStatuses considered successful
   which we can use in queries and so on. We plan to expand this later.

== lib/lp/bugs/model/bugwatch.py ==

 - I've updated addActivity() so that it now sets the result of the new
   BugWatchActivity entry to SYNC_SUCCESS if no other value is
   specified.

== lib/lp/bugs/scripts/checkwatches/scheduler.py ==

 - I've updated the scheduler query to query for activity without a
   success status rather than just querying for result is not null.

== lib/lp/bugs/tests/test_bugwatch.py ==

 - I've updated the test to ensure that the scheduler treats success
   results correctly (i.e. by ignoring them when it calculates when next
   to check the watch).

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Looks good. Approved as patch-2207-47-0.sql

review: Approve (db)
Revision history for this message
Gavin Panella (allenap) :
review: Approve (code)
Revision history for this message
Björn Tillenius (bjornt) :
review: Approve (db)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'database/schema/patch-2207-47-0.sql'
--- database/schema/patch-2207-47-0.sql 1970-01-01 00:00:00 +0000
+++ database/schema/patch-2207-47-0.sql 2010-04-08 09:52:48 +0000
@@ -0,0 +1,6 @@
1SET client_min_messages=ERROR;
2
3UPDATE BugWatchActivity SET result = 9 WHERE result IS NULL;
4ALTER TABLE BugWatchActivity ALTER COLUMN result SET NOT NULL;
5
6INSERT INTO LaunchpadDatabaseRevision VALUES (2207, 47, 0);
07
=== modified file 'lib/lp/bugs/doc/bug-watch-activity.txt'
--- lib/lp/bugs/doc/bug-watch-activity.txt 2010-03-22 14:28:03 +0000
+++ lib/lp/bugs/doc/bug-watch-activity.txt 2010-04-08 09:52:48 +0000
@@ -50,11 +50,14 @@
50 >>> activity.activity_date50 >>> activity.activity_date
51 datetime.datetime...51 datetime.datetime...
5252
53The BugWatchActivity's result will be BugWatchActivityStatus.SYNC_SUCCEEDED.
54
55 >>> print activity.result.title
56 Synchronisation succeeded
57
53The other fields on the BugWatchActivity record, which aren't required,58The other fields on the BugWatchActivity record, which aren't required,
54will all be None.59will all be None.
5560
56 >>> print activity.result
57 None
58 >>> print activity.message61 >>> print activity.message
59 None62 None
60 >>> print activity.oops_id63 >>> print activity.oops_id
@@ -83,12 +86,13 @@
83 >>> print bug_watch.activity.count()86 >>> print bug_watch.activity.count()
84 287 2
8588
86The most recent activity entry will have a result of None since it was89The most recent activity entry will have a result of
90BugWatchActivityStatus.SYNC_SUCCEEDED since it was
87successful.91successful.
8892
89 >>> most_recent_activity = bug_watch.activity.first()93 >>> most_recent_activity = bug_watch.activity.first()
90 >>> print most_recent_activity.result94 >>> print most_recent_activity.result.title
91 None95 Synchronisation succeeded
9296
93Its message will also be empty97Its message will also be empty
9498
9599
=== modified file 'lib/lp/bugs/interfaces/bugwatch.py'
--- lib/lp/bugs/interfaces/bugwatch.py 2010-03-23 12:55:05 +0000
+++ lib/lp/bugs/interfaces/bugwatch.py 2010-04-08 09:52:48 +0000
@@ -8,6 +8,7 @@
8__metaclass__ = type8__metaclass__ = type
99
10__all__ = [10__all__ = [
11 'BUG_WATCH_ACTIVITY_SUCCESS_STATUSES',
11 'BugWatchActivityStatus',12 'BugWatchActivityStatus',
12 'IBugWatch',13 'IBugWatch',
13 'IBugWatchActivity',14 'IBugWatchActivity',
@@ -93,6 +94,19 @@
93 Launchpad cannot import the status of private remote bugs.94 Launchpad cannot import the status of private remote bugs.
94 """)95 """)
9596
97 SYNC_SUCCEEDED = DBItem(9, """
98 Synchronisation succeeded
99
100 The remote bug's status was successfully synchronised to Launchpad.
101 """)
102
103
104# The set of BugWatchActivityStatuses that are considered to indicate
105# success.
106BUG_WATCH_ACTIVITY_SUCCESS_STATUSES = [
107 BugWatchActivityStatus.SYNC_SUCCEEDED,
108 ]
109
96110
97class IBugWatch(IHasBug):111class IBugWatch(IHasBug):
98 """A bug on a remote system."""112 """A bug on a remote system."""
99113
=== modified file 'lib/lp/bugs/model/bugwatch.py'
--- lib/lp/bugs/model/bugwatch.py 2010-03-23 12:55:05 +0000
+++ lib/lp/bugs/model/bugwatch.py 2010-04-08 09:52:48 +0000
@@ -282,7 +282,12 @@
282 """See `IBugWatch`."""282 """See `IBugWatch`."""
283 activity = BugWatchActivity()283 activity = BugWatchActivity()
284 activity.bug_watch = self284 activity.bug_watch = self
285 activity.result = result285 if result is None:
286 # If no result is passed we assume that the activity
287 # succeded and set the result field accordingly.
288 activity.result = BugWatchActivityStatus.SYNC_SUCCEEDED
289 else:
290 activity.result = result
286 if message is not None:291 if message is not None:
287 activity.message = unicode(message)292 activity.message = unicode(message)
288 if oops_id is not None:293 if oops_id is not None:
289294
=== modified file 'lib/lp/bugs/scripts/checkwatches/scheduler.py'
--- lib/lp/bugs/scripts/checkwatches/scheduler.py 2010-03-26 14:33:46 +0000
+++ lib/lp/bugs/scripts/checkwatches/scheduler.py 2010-04-08 09:52:48 +0000
@@ -10,12 +10,11 @@
1010
11import transaction11import transaction
1212
13from storm.expr import Not
14
15from canonical.database.sqlbase import sqlvalues13from canonical.database.sqlbase import sqlvalues
16from canonical.launchpad.utilities.looptuner import TunableLoop14from canonical.launchpad.utilities.looptuner import TunableLoop
17from canonical.launchpad.interfaces import IMasterStore15from canonical.launchpad.interfaces import IMasterStore
1816
17from lp.bugs.interfaces.bugwatch import BUG_WATCH_ACTIVITY_SUCCESS_STATUSES
19from lp.bugs.model.bugwatch import BugWatch18from lp.bugs.model.bugwatch import BugWatch
2019
2120
@@ -70,7 +69,7 @@
70 FROM (SELECT 169 FROM (SELECT 1
71 FROM bugwatchactivity70 FROM bugwatchactivity
72 WHERE bugwatchactivity.bug_watch = bug_watch.id71 WHERE bugwatchactivity.bug_watch = bug_watch.id
73 AND bugwatchactivity.result IS NOT NULL72 AND bugwatchactivity.result NOT IN (%s)
74 ORDER BY bugwatchactivity.id DESC73 ORDER BY bugwatchactivity.id DESC
75 LIMIT %s) AS recent_failures74 LIMIT %s) AS recent_failures
76 ) AS recent_failure_count75 ) AS recent_failure_count
@@ -80,7 +79,8 @@
80 ) AS counts79 ) AS counts
81 WHERE BugWatch.id = counts.id80 WHERE BugWatch.id = counts.id
82 """ % sqlvalues(81 """ % sqlvalues(
83 self.delay_coefficient, self.max_sample_size, chunk_size)82 self.delay_coefficient, BUG_WATCH_ACTIVITY_SUCCESS_STATUSES,
83 self.max_sample_size, chunk_size)
84 self.transaction.begin()84 self.transaction.begin()
85 result = self.store.execute(query)85 result = self.store.execute(query)
86 self.log.debug("Scheduled %s watches" % result.rowcount)86 self.log.debug("Scheduled %s watches" % result.rowcount)
8787
=== modified file 'lib/lp/bugs/stories/bugwatches/xx-bugwatch-errors.txt'
--- lib/lp/bugs/stories/bugwatches/xx-bugwatch-errors.txt 2010-03-22 10:36:53 +0000
+++ lib/lp/bugs/stories/bugwatches/xx-bugwatch-errors.txt 2010-04-08 09:52:48 +0000
@@ -54,11 +54,17 @@
54 The Mozilla.org Bug Tracker bug #900 appears not to exist. Check54 The Mozilla.org Bug Tracker bug #900 appears not to exist. Check
55 that the bug number is correct.55 that the bug number is correct.
5656
57We can observe this for each of the BugWatchActivityStatus values:57We can observe this for each of the BugWatchActivityStatus failure values:
5858
59 >>> from lp.bugs.interfaces.bugwatch import (
60 ... BUG_WATCH_ACTIVITY_SUCCESS_STATUSES)
59 >>> from lp.bugs.tests.externalbugtracker import (61 >>> from lp.bugs.tests.externalbugtracker import (
60 ... set_bugwatch_error_type)62 ... set_bugwatch_error_type)
61 >>> for item in sorted(BugWatchActivityStatus.items):63
64 >>> failure_values = [
65 ... value for value in sorted(BugWatchActivityStatus.items) if
66 ... value not in BUG_WATCH_ACTIVITY_SUCCESS_STATUSES]
67 >>> for item in failure_values:
62 ... set_bugwatch_error_type(watch, item)68 ... set_bugwatch_error_type(watch, item)
63 ... user_browser.open('http://bugs.launchpad.dev/thunderbird/+bug/12')69 ... user_browser.open('http://bugs.launchpad.dev/thunderbird/+bug/12')
64 ... for tag in find_tags_by_class(user_browser.contents,70 ... for tag in find_tags_by_class(user_browser.contents,
6571
=== modified file 'lib/lp/bugs/tests/test_bugwatch.py'
--- lib/lp/bugs/tests/test_bugwatch.py 2010-03-26 14:49:24 +0000
+++ lib/lp/bugs/tests/test_bugwatch.py 2010-04-08 09:52:48 +0000
@@ -16,10 +16,9 @@
16from zope.component import getUtility16from zope.component import getUtility
1717
18from canonical.launchpad.ftests import login, ANONYMOUS18from canonical.launchpad.ftests import login, ANONYMOUS
19from canonical.launchpad.scripts.garbo import BugWatchActivityPruner
19from canonical.launchpad.scripts.logger import QuietFakeLogger20from canonical.launchpad.scripts.logger import QuietFakeLogger
20from canonical.launchpad.webapp import urlsplit21from canonical.launchpad.webapp import urlsplit
21from canonical.launchpad.scripts.garbo import BugWatchActivityPruner
22from canonical.launchpad.scripts.logger import QuietFakeLogger
23from canonical.testing import (22from canonical.testing import (
24 DatabaseFunctionalLayer, LaunchpadFunctionalLayer, LaunchpadZopelessLayer)23 DatabaseFunctionalLayer, LaunchpadFunctionalLayer, LaunchpadZopelessLayer)
2524
@@ -496,6 +495,9 @@
496 # If a watch has been checked and has never failed its next495 # If a watch has been checked and has never failed its next
497 # check will be scheduled for 24 hours after its last check.496 # check will be scheduled for 24 hours after its last check.
498 now = datetime.now(utc)497 now = datetime.now(utc)
498 # Add some succesful activity to ensure that successful activity
499 # is handled correctly.
500 self.bug_watch.addActivity()
499 self.bug_watch.lastchecked = now501 self.bug_watch.lastchecked = now
500 self.bug_watch.next_check = None502 self.bug_watch.next_check = None
501 transaction.commit()503 transaction.commit()

Subscribers

People subscribed via source and target branches

to status/vote changes: