~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Stuart Bishop
  • Date: 2011-03-30 08:50:53 UTC
  • mto: (8758.5.1 parallel-garbo)
  • mto: This revision was merged to the branch mainline in revision 12712.
  • Revision ID: stuart.bishop@canonical.com-20110330085053-o74ux3ijbmmhp2ok
Switch CodeImportEventPruner to use BulkPruner

Show diffs side-by-side

added added

removed removed

Lines of Context:
301
301
        transaction.commit()
302
302
 
303
303
 
304
 
class CodeImportEventPruner(TunableLoop):
 
304
class CodeImportEventPruner(BulkPruner):
305
305
    """Prune `CodeImportEvent`s that are more than a month old.
306
306
 
307
307
    Events that happened more than 30 days ago are really of no
308
308
    interest to us.
309
309
    """
310
 
 
311
 
    maximum_chunk_size = 10000
312
 
    minimum_chunk_size = 500
313
 
 
314
 
    def isDone(self):
315
 
        store = IMasterStore(CodeImportEvent)
316
 
        events = store.find(
317
 
            CodeImportEvent,
318
 
            CodeImportEvent.date_created < THIRTY_DAYS_AGO)
319
 
        return events.any() is None
320
 
 
321
 
    def __call__(self, chunk_size):
322
 
        chunk_size = int(chunk_size)
323
 
        store = IMasterStore(CodeImportEvent)
324
 
        event_ids = Select(
325
 
            [CodeImportEvent.id],
326
 
            CodeImportEvent.date_created < THIRTY_DAYS_AGO,
327
 
            limit=chunk_size)
328
 
        num_removed = store.find(
329
 
            CodeImportEvent, CodeImportEvent.id.is_in(event_ids)).remove()
330
 
        transaction.commit()
331
 
        self.log.debug("Removed %d old CodeImportEvents" % num_removed)
 
310
    target_table_class = CodeImportEvent
 
311
    ids_to_prune_query = """
 
312
        SELECT id FROM CodeImportEvent
 
313
        WHERE date_created < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'
 
314
            - CAST('30 days' AS interval)
 
315
        """
332
316
 
333
317
 
334
318
class CodeImportResultPruner(TunableLoop):