Merge lp:~abentley/launchpad/celery-everywhere-7 into lp:launchpad

Proposed by Aaron Bentley
Status: Merged
Approved by: Aaron Bentley
Approved revision: no longer in the source branch.
Merged at revision: 15150
Proposed branch: lp:~abentley/launchpad/celery-everywhere-7
Merge into: lp:launchpad
Diff against target: 121 lines (+52/-3)
3 files modified
lib/lp/services/job/model/job.py (+2/-1)
lib/lp/translations/model/pofilestatsjob.py (+18/-1)
lib/lp/translations/tests/test_pofilestatsjob.py (+32/-1)
To merge this branch: bzr merge lp:~abentley/launchpad/celery-everywhere-7
Reviewer Review Type Date Requested Status
Abel Deuring (community) code Approve
Review via email: mp+103483@code.launchpad.net

Commit message

Support running POFileStatsJob via Celery.

Description of the change

= Summary =
Support running POFileStatsJob via Celery

== Pre-implementation notes ==
None

== LOC Rationale ==
Part of a resourced arc that will remove code.

== Implementation details ==
Update POFileStatsJob to provide config and makeDerived. Update pofilestatsjob.schedule to request Celery to run the job.

Update UniversalJobSource to return POFileStatsJob.

== Tests ==
bin/test --layer=CeleryJobLayer test_pofilestatsjob

== Demo and Q/A ==
None

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/translations/tests/test_pofilestatsjob.py
  lib/lp/translations/model/pofilestatsjob.py
  lib/lp/services/job/model/job.py

To post a comment you must log in.
Revision history for this message
Abel Deuring (adeuring) wrote :

looks good

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/model/job.py'
--- lib/lp/services/job/model/job.py 2012-04-24 18:26:06 +0000
+++ lib/lp/services/job/model/job.py 2012-04-25 14:31:24 +0000
@@ -277,6 +277,7 @@
277 BranchMergeProposalJob,277 BranchMergeProposalJob,
278 )278 )
279 from lp.soyuz.model.distributionjob import DistributionJob279 from lp.soyuz.model.distributionjob import DistributionJob
280 from lp.translations.model.pofilestatsjob import POFileStatsJob
280 from lp.translations.model.translationsharingjob import (281 from lp.translations.model.translationsharingjob import (
281 TranslationSharingJob,282 TranslationSharingJob,
282 )283 )
@@ -285,7 +286,7 @@
285286
286 for baseclass in [287 for baseclass in [
287 ApportJob, BranchJob, BranchMergeProposalJob, DistributionJob,288 ApportJob, BranchJob, BranchMergeProposalJob, DistributionJob,
288 TranslationSharingJob,289 POFileStatsJob, TranslationSharingJob,
289 ]:290 ]:
290 derived, base_class, store = cls._getDerived(job_id, baseclass)291 derived, base_class, store = cls._getDerived(job_id, baseclass)
291 if derived is not None:292 if derived is not None:
292293
=== modified file 'lib/lp/translations/model/pofilestatsjob.py'
--- lib/lp/translations/model/pofilestatsjob.py 2012-01-03 13:47:27 +0000
+++ lib/lp/translations/model/pofilestatsjob.py 2012-04-25 14:31:24 +0000
@@ -24,6 +24,7 @@
24 implements,24 implements,
25 )25 )
2626
27from lp.services.config import config
27from lp.services.database.stormbase import StormBase28from lp.services.database.stormbase import StormBase
28from lp.services.job.interfaces.job import IRunnableJob29from lp.services.job.interfaces.job import IRunnableJob
29from lp.services.job.model.job import Job30from lp.services.job.model.job import Job
@@ -43,6 +44,8 @@
4344
44 __storm_table__ = 'POFileStatsJob'45 __storm_table__ = 'POFileStatsJob'
4546
47 config = config.pofile_stats
48
46 # Instances of this class are runnable jobs.49 # Instances of this class are runnable jobs.
47 implements(IRunnableJob)50 implements(IRunnableJob)
4851
@@ -100,7 +103,21 @@
100 And(POFileStatsJob.job == Job.id,103 And(POFileStatsJob.job == Job.id,
101 Job.id.is_in(Job.ready_jobs)))104 Job.id.is_in(Job.ready_jobs)))
102105
106 def makeDerived(self):
107 """Support UniversalJobSource.
108
109 (Most Job ORM classes are generic, because their database table is
110 used for several related job types. Therefore, they have derived
111 classes to implement the specific Job.
112
113 POFileStatsJob implements the specific job, so its makeDerived returns
114 itself.)
115 """
116 return self
117
103118
104def schedule(pofile):119def schedule(pofile):
105 """Schedule a job to update a POFile's stats."""120 """Schedule a job to update a POFile's stats."""
106 return POFileStatsJob(pofile)121 job = POFileStatsJob(pofile)
122 job.celeryRunOnCommit()
123 return job
107124
=== modified file 'lib/lp/translations/tests/test_pofilestatsjob.py'
--- lib/lp/translations/tests/test_pofilestatsjob.py 2012-01-04 16:17:43 +0000
+++ lib/lp/translations/tests/test_pofilestatsjob.py 2012-04-25 14:31:24 +0000
@@ -6,16 +6,25 @@
6__metaclass__ = type6__metaclass__ = type
77
88
9import transaction
10
9from lp.app.enums import ServiceUsage11from lp.app.enums import ServiceUsage
10from lp.services.config import config12from lp.services.config import config
13from lp.services.features.testing import FeatureFixture
11from lp.services.job.interfaces.job import (14from lp.services.job.interfaces.job import (
12 IJobSource,15 IJobSource,
13 IRunnableJob,16 IRunnableJob,
14 )17 )
18from lp.services.job.tests import (
19 block_on_job
20 )
15from lp.services.webapp.testing import verifyObject21from lp.services.webapp.testing import verifyObject
16from lp.testing import TestCaseWithFactory22from lp.testing import TestCaseWithFactory
17from lp.testing.dbuser import dbuser23from lp.testing.dbuser import dbuser
18from lp.testing.layers import LaunchpadZopelessLayer24from lp.testing.layers import (
25 CeleryJobLayer,
26 LaunchpadZopelessLayer,
27 )
19from lp.translations.interfaces.pofilestatsjob import IPOFileStatsJobSource28from lp.translations.interfaces.pofilestatsjob import IPOFileStatsJobSource
20from lp.translations.interfaces.side import TranslationSide29from lp.translations.interfaces.side import TranslationSide
21from lp.translations.model import pofilestatsjob30from lp.translations.model import pofilestatsjob
@@ -190,3 +199,25 @@
190 pofile2 = template2.getPOFileByLang(language.code)199 pofile2 = template2.getPOFileByLang(language.code)
191200
192 self.assertJobUpdatesStats(pofile1, pofile2)201 self.assertJobUpdatesStats(pofile1, pofile2)
202
203
204class TestViaCelery(TestCaseWithFactory):
205
206 layer = CeleryJobLayer
207
208 def test_run(self):
209 # POFileJob can run via Celery.
210 self.useFixture(FeatureFixture(
211 {'jobs.celery.enabled_classes': 'POFileStatsJob'}))
212 # Running a job causes the POFile statistics to be updated.
213 singular = self.factory.getUniqueString()
214 pofile = self.factory.makePOFile(side=TranslationSide.UPSTREAM)
215 # Create a message so we have something to have statistics about.
216 self.factory.makePOTMsgSet(pofile.potemplate, singular)
217 # The statistics start at 0.
218 self.assertEqual(pofile.potemplate.messageCount(), 0)
219 pofilestatsjob.schedule(pofile.id)
220 with block_on_job():
221 transaction.commit()
222 # Now that the job ran, the statistics have been updated.
223 self.assertEqual(pofile.potemplate.messageCount(), 1)