~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/scripts/garbo.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-09-12 21:08:41 UTC
  • mfrom: (8758.3.25 garbo)
  • Revision ID: launchpad@pqm.canonical.com-20110912210841-qyag5sunk3vo01we
[r=bac][bug=795305] Add garbo-frequently for every 5 mins tasks,
        reduce transaction target to 2 seconds,
        rollup bugsummary journal in garbo-grequently.

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
from lp.bugs.interfaces.bug import IBugSet
63
63
from lp.bugs.model.bug import Bug
64
64
from lp.bugs.model.bugattachment import BugAttachment
65
 
from lp.bugs.model.bugmessage import BugMessage
66
65
from lp.bugs.model.bugnotification import BugNotification
67
66
from lp.bugs.model.bugwatch import BugWatchActivity
68
67
from lp.bugs.scripts.checkwatches.scheduler import (
302
301
        """
303
302
 
304
303
 
 
304
class BugSummaryJournalRollup(TunableLoop):
 
305
    """Rollup BugSummaryJournal rows into BugSummary."""
 
306
    maximum_chunk_size = 5000
 
307
 
 
308
    def __init__(self, log, abort_time=None):
 
309
        super(BugSummaryJournalRollup, self).__init__(log, abort_time)
 
310
        self.store = getUtility(IStoreSelector).get(MAIN_STORE, MASTER_FLAVOR)
 
311
 
 
312
    def isDone(self):
 
313
        has_more = self.store.execute(
 
314
            "SELECT EXISTS (SELECT TRUE FROM BugSummaryJournal LIMIT 1)"
 
315
            ).get_one()[0]
 
316
        return not has_more
 
317
 
 
318
    def __call__(self, chunk_size):
 
319
        chunk_size = int(chunk_size + 0.5)
 
320
        self.store.execute(
 
321
            "SELECT bugsummary_rollup_journal(%s)", (chunk_size,),
 
322
            noresult=True)
 
323
        self.store.commit()
 
324
 
 
325
 
305
326
class OpenIDConsumerNoncePruner(TunableLoop):
306
327
    """An ITunableLoop to prune old OpenIDConsumerNonce records.
307
328
 
1145
1166
                transaction.abort()
1146
1167
 
1147
1168
 
1148
 
class HourlyDatabaseGarbageCollector(BaseDatabaseGarbageCollector):
1149
 
    script_name = 'garbo-hourly'
 
1169
class FrequentDatabaseGarbageCollector(BaseDatabaseGarbageCollector):
 
1170
    """Run every 5 minutes.
 
1171
 
 
1172
    This may become even more frequent in the future.
 
1173
 
 
1174
    Jobs with low overhead can go here to distribute work more evenly.
 
1175
    """
 
1176
    script_name = 'garbo-frequently'
1150
1177
    tunable_loops = [
 
1178
        BugSummaryJournalRollup,
1151
1179
        OAuthNoncePruner,
1152
1180
        OpenIDConsumerNoncePruner,
1153
1181
        OpenIDConsumerAssociationPruner,
 
1182
        AntiqueSessionPruner,
 
1183
        ]
 
1184
    experimental_tunable_loops = []
 
1185
 
 
1186
    # 5 minmutes minus 20 seconds for cleanup. This helps ensure the
 
1187
    # script is fully terminated before the next scheduled hourly run
 
1188
    # kicks in.
 
1189
    default_abort_script_time = 60 * 5 - 20
 
1190
 
 
1191
 
 
1192
class HourlyDatabaseGarbageCollector(BaseDatabaseGarbageCollector):
 
1193
    """Run every hour.
 
1194
 
 
1195
    Jobs we want to run fairly often but have noticable overhead go here.
 
1196
    """
 
1197
    script_name = 'garbo-hourly'
 
1198
    tunable_loops = [
1154
1199
        RevisionCachePruner,
1155
1200
        BugWatchScheduler,
1156
 
        AntiqueSessionPruner,
1157
1201
        UnusedSessionPruner,
1158
1202
        DuplicateSessionPruner,
1159
1203
        BugHeatUpdater,
1166
1210
 
1167
1211
 
1168
1212
class DailyDatabaseGarbageCollector(BaseDatabaseGarbageCollector):
 
1213
    """Run every day.
 
1214
 
 
1215
    Jobs that don't need to be run frequently.
 
1216
 
 
1217
    If there is low overhead, consider putting these tasks in more
 
1218
    frequently invoked lists to distribute the work more evenly.
 
1219
    """
1169
1220
    script_name = 'garbo-daily'
1170
1221
    tunable_loops = [
1171
1222
        AnswerContactPruner,