Merge lp:~wgrant/launchpad/celery-tweaks into lp:launchpad

Proposed by William Grant
Status: Merged
Approved by: Steve Kowalik
Approved revision: no longer in the source branch.
Merged at revision: 16666
Proposed branch: lp:~wgrant/launchpad/celery-tweaks
Merge into: lp:launchpad
Diff against target: 104 lines (+50/-2)
3 files modified
lib/lp/services/job/celeryjob.py (+2/-0)
lib/lp/soyuz/model/queue.py (+1/-0)
lib/lp/soyuz/tests/test_packagecopyjob.py (+47/-2)
To merge this branch: bzr merge lp:~wgrant/launchpad/celery-tweaks
Reviewer Review Type Date Requested Status
Steve Kowalik (community) code Approve
Review via email: mp+167197@code.launchpad.net

Commit message

Two celery fixes: reschedule accepted PackageCopyJobs, and fix mail delivery.

Description of the change

Two celery fixes:

 - PackageCopyJobs need to be requeued in celery once they're resumed by acceptFromQueue.
 - celery Zope initialisation was calling execute_zcml_for_scripts but not set_immediate_mail_delivery, so it was using dev-configured Zope transactional appserver mail.

To post a comment you must log in.
Revision history for this message
Steve Kowalik (stevenk) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/services/job/celeryjob.py'
--- lib/lp/services/job/celeryjob.py 2012-08-02 15:21:50 +0000
+++ lib/lp/services/job/celeryjob.py 2013-06-04 05:56:27 +0000
@@ -34,6 +34,7 @@
34 install_feature_controller,34 install_feature_controller,
35 make_script_feature_controller,35 make_script_feature_controller,
36 )36 )
37from lp.services.mail.sendmail import set_immediate_mail_delivery
37from lp.services.job.model.job import (38from lp.services.job.model.job import (
38 Job,39 Job,
39 UniversalJobSource,40 UniversalJobSource,
@@ -139,6 +140,7 @@
139 return140 return
140 transaction.abort()141 transaction.abort()
141 scripts.execute_zcml_for_scripts(use_web_security=False)142 scripts.execute_zcml_for_scripts(use_web_security=False)
143 set_immediate_mail_delivery(True)
142 needs_zcml = False144 needs_zcml = False
143145
144146
145147
=== modified file 'lib/lp/soyuz/model/queue.py'
--- lib/lp/soyuz/model/queue.py 2013-05-31 02:51:23 +0000
+++ lib/lp/soyuz/model/queue.py 2013-06-04 05:56:27 +0000
@@ -542,6 +542,7 @@
542 self.setAccepted()542 self.setAccepted()
543 job = PlainPackageCopyJob.get(self.package_copy_job_id)543 job = PlainPackageCopyJob.get(self.package_copy_job_id)
544 job.resume()544 job.resume()
545 job.celeryRunOnCommit()
545 # The copy job will send emails as appropriate. We don't546 # The copy job will send emails as appropriate. We don't
546 # need to worry about closing bugs from syncs, although we547 # need to worry about closing bugs from syncs, although we
547 # should probably give karma but that needs more work to548 # should probably give karma but that needs more work to
548549
=== modified file 'lib/lp/soyuz/tests/test_packagecopyjob.py'
--- lib/lp/soyuz/tests/test_packagecopyjob.py 2013-05-24 01:02:43 +0000
+++ lib/lp/soyuz/tests/test_packagecopyjob.py 2013-06-04 05:56:27 +0000
@@ -59,7 +59,7 @@
59from lp.soyuz.model.queue import PackageUpload59from lp.soyuz.model.queue import PackageUpload
60from lp.soyuz.tests.test_publishing import SoyuzTestPublisher60from lp.soyuz.tests.test_publishing import SoyuzTestPublisher
61from lp.testing import (61from lp.testing import (
62 celebrity_logged_in,62 admin_logged_in,
63 person_logged_in,63 person_logged_in,
64 run_script,64 run_script,
65 TestCaseWithFactory,65 TestCaseWithFactory,
@@ -87,7 +87,7 @@
87def create_proper_job(factory):87def create_proper_job(factory):
88 """Create a job that will complete successfully."""88 """Create a job that will complete successfully."""
89 publisher = SoyuzTestPublisher()89 publisher = SoyuzTestPublisher()
90 with celebrity_logged_in('admin'):90 with admin_logged_in():
91 publisher.prepareBreezyAutotest()91 publisher.prepareBreezyAutotest()
92 distroseries = publisher.breezy_autotest92 distroseries = publisher.breezy_autotest
9393
@@ -1642,6 +1642,51 @@
1642 emails = pop_remote_notifications()1642 emails = pop_remote_notifications()
1643 self.assertEqual(1, len(emails))1643 self.assertEqual(1, len(emails))
16441644
1645 def test_resume_from_queue(self):
1646 # Accepting a suspended copy from the queue sends it back
1647 # through celery.
1648 self.useFixture(FeatureFixture({
1649 'jobs.celery.enabled_classes': 'PlainPackageCopyJob',
1650 }))
1651
1652 source_pub = self.factory.makeSourcePackagePublishingHistory(
1653 component=u"main", status=PackagePublishingStatus.PUBLISHED)
1654 target_series = self.factory.makeDistroSeries()
1655 getUtility(ISourcePackageFormatSelectionSet).add(
1656 target_series, SourcePackageFormat.FORMAT_1_0)
1657 requester = self.factory.makePerson()
1658 with person_logged_in(target_series.main_archive.owner):
1659 target_series.main_archive.newComponentUploader(requester, u"main")
1660 job = getUtility(IPlainPackageCopyJobSource).create(
1661 package_name=source_pub.source_package_name,
1662 package_version=source_pub.source_package_version,
1663 source_archive=source_pub.archive,
1664 target_archive=target_series.main_archive,
1665 target_distroseries=target_series,
1666 target_pocket=PackagePublishingPocket.PROPOSED,
1667 include_binaries=False, requester=requester)
1668
1669 # Run the job once. There's no ancestry so it will be suspended
1670 # and added to the queue.
1671 with block_on_job(self):
1672 transaction.commit()
1673 self.assertEqual(JobStatus.SUSPENDED, job.status)
1674
1675 # Approve its queue entry and rerun to completion.
1676 pu = getUtility(IPackageUploadSet).getByPackageCopyJobIDs(
1677 [job.id]).one()
1678 with admin_logged_in():
1679 pu.acceptFromQueue()
1680 self.assertEqual(JobStatus.WAITING, job.status)
1681
1682 with block_on_job(self):
1683 transaction.commit()
1684 self.assertEqual(JobStatus.COMPLETED, job.status)
1685 self.assertEqual(
1686 1,
1687 target_series.main_archive.getPublishedSources(
1688 name=source_pub.source_package_name).count())
1689
16451690
1646class TestPlainPackageCopyJobPermissions(TestCaseWithFactory):1691class TestPlainPackageCopyJobPermissions(TestCaseWithFactory):
16471692