← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~maxiberta/launchpad/garbo-snapbuildjob-pruner into lp:launchpad

 

Maximiliano Bertacchini has proposed merging lp:~maxiberta/launchpad/garbo-snapbuildjob-pruner into lp:launchpad.

Commit message:
New garbo job for pruning old SnapBuildJobs.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~maxiberta/launchpad/garbo-snapbuildjob-pruner/+merge/295268

New garbo job for pruning old SnapBuildJobs.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~maxiberta/launchpad/garbo-snapbuildjob-pruner into lp:launchpad.
=== modified file 'lib/lp/scripts/garbo.py'
--- lib/lp/scripts/garbo.py	2016-05-17 13:35:03 +0000
+++ lib/lp/scripts/garbo.py	2016-05-19 21:45:10 +0000
@@ -1080,7 +1080,7 @@
 class BranchJobPruner(BulkPruner):
     """Prune `BranchJob`s that are in a final state and more than a month old.
 
-    When a BranchJob is completed, it gets set to a final state.  These jobs
+    When a BranchJob is completed, it gets set to a final state. These jobs
     should be pruned from the database after a month.
     """
     target_table_class = Job
@@ -1097,7 +1097,7 @@
 class GitJobPruner(BulkPruner):
     """Prune `GitJob`s that are in a final state and more than a month old.
 
-    When a GitJob is completed, it gets set to a final state.  These jobs
+    When a GitJob is completed, it gets set to a final state. These jobs
     should be pruned from the database after a month.
     """
     target_table_class = Job
@@ -1111,6 +1111,24 @@
         """
 
 
+class SnapBuildJobPruner(BulkPruner):
+    """Prune `SnapBuildJob`s that are in a final state and more than a month
+    old.
+
+    When a SnapBuildJob is completed, it gets set to a final state. These jobs
+    should be pruned from the database after a month.
+    """
+    target_table_class = Job
+    ids_to_prune_query = """
+        SELECT DISTINCT Job.id
+        FROM Job, SnapBuildJob
+        WHERE
+            Job.id = SnapBuildJob.job
+            AND Job.date_finished < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'
+                - CAST('30 days' AS interval)
+        """
+
+
 class WebhookJobPruner(TunableLoop):
     """Prune `WebhookJobs` that finished more than a month ago."""
 
@@ -1670,7 +1688,7 @@
         ]
     experimental_tunable_loops = []
 
-    # 5 minmutes minus 20 seconds for cleanup. This helps ensure the
+    # 5 minutes minus 20 seconds for cleanup. This helps ensure the
     # script is fully terminated before the next scheduled hourly run
     # kicks in.
     default_abort_script_time = 60 * 5 - 20
@@ -1724,6 +1742,7 @@
         ProductVCSPopulator,
         RevisionAuthorEmailLinker,
         ScrubPOFileTranslator,
+        SnapBuildJobPruner,
         SuggestiveTemplatesCacheUpdater,
         TeamMembershipPruner,
         UnlinkedAccountPruner,

=== modified file 'lib/lp/scripts/tests/test_garbo.py'
--- lib/lp/scripts/tests/test_garbo.py	2016-05-17 13:35:03 +0000
+++ lib/lp/scripts/tests/test_garbo.py	2016-05-19 21:45:10 +0000
@@ -113,6 +113,11 @@
 from lp.services.verification.interfaces.authtoken import LoginTokenType
 from lp.services.verification.model.logintoken import LoginToken
 from lp.services.worlddata.interfaces.language import ILanguageSet
+from lp.snappy.interfaces.snap import SNAP_TESTING_FLAGS
+from lp.snappy.model.snapbuildjob import (
+    SnapBuildJob,
+    SnapStoreUploadJob,
+    )
 from lp.soyuz.enums import PackagePublishingStatus
 from lp.soyuz.interfaces.livefs import LIVEFS_FEATURE_FLAG
 from lp.soyuz.model.livefsbuild import LiveFSFile
@@ -978,6 +983,26 @@
         switch_dbuser('testadmin')
         self.assertEqual(1, store.find(GitJob).count())
 
+    def test_SnapBuildJobPruner(self):
+        # Garbo should remove jobs completed over 30 days ago.
+        self.useFixture(FeatureFixture(SNAP_TESTING_FLAGS))
+        switch_dbuser('testadmin')
+        store = IMasterStore(Job)
+
+        snapbuild = self.factory.makeSnapBuild()
+        snapbuild_job = SnapStoreUploadJob.create(snapbuild)
+
+        snapbuild2 = self.factory.makeSnapBuild()
+        snapbuild_job2 = SnapStoreUploadJob.create(snapbuild2)
+        snapbuild_job2.job.date_finished = THIRTY_DAYS_AGO
+
+        self.assertEqual(2, store.find(SnapBuildJob).count())
+
+        self.runDaily()
+
+        switch_dbuser('testadmin')
+        self.assertEqual(snapbuild_job.context, store.find(SnapBuildJob).one())
+
     def test_WebhookJobPruner(self):
         # Garbo should remove jobs completed over 30 days ago.
         switch_dbuser('testadmin')


Follow ups