launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #08241
[Merge] lp:~stevenk/launchpad/set-spph-packageupload into lp:launchpad
Steve Kowalik has proposed merging lp:~stevenk/launchpad/set-spph-packageupload into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~stevenk/launchpad/set-spph-packageupload/+merge/107583
Write a garbo job that will try and populate the new packageupload column of SPPH. It makes use of memcache to set the start_at since it's not a problem if an SPPH does not have a PackageUpload.
--
https://code.launchpad.net/~stevenk/launchpad/set-spph-packageupload/+merge/107583
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~stevenk/launchpad/set-spph-packageupload into lp:launchpad.
=== modified file 'lib/lp/scripts/garbo.py'
--- lib/lp/scripts/garbo.py 2012-05-24 05:43:49 +0000
+++ lib/lp/scripts/garbo.py 2012-05-28 06:22:19 +0000
@@ -98,6 +98,11 @@
MAIN_STORE,
MASTER_FLAVOR,
)
+from lp.soyuz.model.publishing import SourcePackagePublishingHistory
+from lp.soyuz.model.queue import (
+ PackageUpload,
+ PackageUploadSource,
+ )
from lp.translations.interfaces.potemplate import IPOTemplateSet
from lp.translations.model.potmsgset import POTMsgSet
from lp.translations.model.potranslation import POTranslation
@@ -1137,6 +1142,47 @@
transaction.commit()
+class PopulateSourcePackagePublishingHistoryPackageUpload(TunableLoop):
+
+ maximum_chunk_size = 5000
+
+ def __init__(self, log, abort_time=None):
+ super(
+ PopulateSourcePackagePublishingHistoryPackageUpload,
+ self).__init__(log, abort_time)
+ self.store = IMasterStore(SourcePackagePublishingHistory)
+ self.memcache_key = '%s:populate-spph-pu' % config.instance_name
+ watermark = getUtility(IMemcacheClient).get(self.memcache_key)
+ self.start_at = watermark or 0
+
+ def findSPPHs(self):
+ return self.store.find(
+ SourcePackagePublishingHistory,
+ SourcePackagePublishingHistory.packageuploadID == None,
+ SourcePackagePublishingHistory.id >= self.start_at).order_by(
+ SourcePackagePublishingHistory.id)
+
+ def isDone(self):
+ return self.findSPPHs().is_empty()
+
+ def __call__(self, chunk_size):
+ for spph in self.findSPPHs()[:chunk_size]:
+ pu = self.store.find(
+ PackageUpload,
+ SourcePackagePublishingHistory.sourcepackagereleaseID ==
+ PackageUploadSource.sourcepackagereleaseID,
+ PackageUploadSource.packageuploadID == PackageUpload.id,
+ SourcePackagePublishingHistory.id == spph.id).one()
+ if pu is not None:
+ spph.packageupload = pu
+ self.start_at = spph.id + 1
+ result = getUtility(IMemcacheClient).set(
+ self.memcache_key, self.start_at)
+ if not result:
+ self.log.warning('Failed to set start_at in memcache.')
+ transaction.commit()
+
+
class BaseDatabaseGarbageCollector(LaunchpadCronScript):
"""Abstract base class to run a collection of TunableLoops."""
script_name = None # Script name for locking and database user. Override.
@@ -1392,6 +1438,7 @@
DuplicateSessionPruner,
BugHeatUpdater,
BugTaskFlattener,
+ PopulateSourcePackagePublishingHistoryPackageUpload,
]
experimental_tunable_loops = []
=== modified file 'lib/lp/scripts/tests/test_garbo.py'
--- lib/lp/scripts/tests/test_garbo.py 2012-05-09 01:35:41 +0000
+++ lib/lp/scripts/tests/test_garbo.py 2012-05-28 06:22:19 +0000
@@ -1149,6 +1149,16 @@
self.runHourly()
self.assertEqual((task.id,), get_flat())
+ def test_PopulateSourcePackagePublishingHistoryPackageUpload(self):
+ with dbuser('testadmin'):
+ spph = self.factory.makeSourcePackagePublishingHistory()
+ pu = self.factory.makePackageUpload()
+ pu.addSource(spph.sourcepackagerelease)
+ self.assertIs(None, spph.packageupload)
+ self.runHourly()
+ with dbuser('testadmin'):
+ self.assertEqual(pu, spph.packageupload)
+
class TestGarboTasks(TestCaseWithFactory):
layer = LaunchpadZopelessLayer