1
Batching in checkwatches
2
========================
4
The checkwatches system tries to be sensitive to batching options
5
given. Specifically, the _getRemoteIdsToCheck() method is responsible
6
for batching up operations.
9
>>> from lp.bugs.scripts.checkwatches import CheckwatchesMaster
10
>>> from pprint import pprint
12
>>> updater = CheckwatchesMaster(transaction)
13
>>> transaction.commit()
19
>>> class BasicRemoteSystem:
20
... sync_comments = False
22
>>> remote = BasicRemoteSystem()
24
When there are no bug watches to check, the result is empty.
26
>>> pprint(updater._getRemoteIdsToCheck(
27
... remote, [], batch_size=2))
28
{'all_remote_ids': [],
29
'remote_ids_to_check': [],
30
'unmodified_remote_ids': []}
32
With up to batch_size watches, it advises us to check all the remote
36
... factory.makeBugWatch(remote_bug='a'),
37
... factory.makeBugWatch(remote_bug='b'),
39
>>> transaction.commit()
41
>>> pprint(updater._getRemoteIdsToCheck(
42
... remote, bug_watches, batch_size=2))
43
{'all_remote_ids': [u'a', u'b'],
44
'remote_ids_to_check': [u'a', u'b'],
45
'unmodified_remote_ids': []}
47
With more than batch_size watches, it advises to only check a subset
48
of the remote bug IDs given.
51
... factory.makeBugWatch(remote_bug='a'),
52
... factory.makeBugWatch(remote_bug='b'),
53
... factory.makeBugWatch(remote_bug='c'),
55
>>> transaction.commit()
57
>>> pprint(updater._getRemoteIdsToCheck(
58
... remote, bug_watches, batch_size=2))
59
{'all_remote_ids': [u'a', u'b'],
60
'remote_ids_to_check': [u'a', u'b'],
61
'unmodified_remote_ids': []}
64
Querying the remote system for modified bugs
65
--------------------------------------------
67
For bug watches that have been checked before, the remote system is
68
asked which of a list of bugs have been modified since a given date.
70
>>> from zope.security.proxy import removeSecurityProxy
71
>>> from datetime import datetime
72
>>> from pytz import UTC
74
>>> class QueryableRemoteSystem:
75
... sync_comments = False
76
... def getModifiedRemoteBugs(self, remote_bug_ids, timestamp):
77
... print "getModifiedRemoteBugs(%r, %r)" % (
78
... remote_bug_ids, timestamp)
79
... # Return every *other* bug ID for demo purposes.
80
... return remote_bug_ids[::2]
82
>>> remote = QueryableRemoteSystem()
83
>>> now = datetime(2010, 01, 13, 16, 52, tzinfo=UTC)
85
When there are no bug watches to check, the result is empty, and the
86
remote system is not queried.
88
>>> ids_to_check = updater._getRemoteIdsToCheck(
89
... remote, [], batch_size=2,
90
... server_time=now, now=now)
92
>>> pprint(ids_to_check)
93
{'all_remote_ids': [],
94
'remote_ids_to_check': [],
95
'unmodified_remote_ids': []}
97
With up to batch_size previously checked watches, the remote system is
98
queried once, and we are advised to check only one of the watches.
101
... factory.makeBugWatch(remote_bug='a'),
102
... factory.makeBugWatch(remote_bug='b'),
104
>>> for bug_watch in bug_watches:
105
... removeSecurityProxy(bug_watch).lastchecked = now
106
>>> transaction.commit()
108
>>> ids_to_check = updater._getRemoteIdsToCheck(
109
... remote, bug_watches, batch_size=2,
110
... server_time=now, now=now)
111
getModifiedRemoteBugs([u'a', u'b'], datetime.datetime(...))
113
>>> pprint(ids_to_check)
114
{'all_remote_ids': [u'a', u'b'],
115
'remote_ids_to_check': [u'a'],
116
'unmodified_remote_ids': [u'b']}
118
With just more than batch_size previously checked watches, the remote
119
system is queried twice, and we are advised to check two of the
123
... factory.makeBugWatch(remote_bug='a'),
124
... factory.makeBugWatch(remote_bug='b'),
125
... factory.makeBugWatch(remote_bug='c'),
127
>>> for bug_watch in bug_watches:
128
... removeSecurityProxy(bug_watch).lastchecked = now
129
>>> transaction.commit()
131
>>> ids_to_check = updater._getRemoteIdsToCheck(
132
... remote, bug_watches, batch_size=2,
133
... server_time=now, now=now)
134
getModifiedRemoteBugs([u'a', u'b'], datetime.datetime(...))
135
getModifiedRemoteBugs([u'c'], datetime.datetime(...))
137
>>> pprint(ids_to_check)
138
{'all_remote_ids': [u'a', u'b', u'c'],
139
'remote_ids_to_check': [u'a', u'c'],
140
'unmodified_remote_ids': [u'b']}