launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #02947
[Merge] lp:~abentley/launchpad/translation-job-status into lp:launchpad
Aaron Bentley has proposed merging lp:~abentley/launchpad/translation-job-status into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~abentley/launchpad/translation-job-status/+merge/53326
= Summary =
Translation sharing page wants to say whether there is a pending or running
merge job.
== Proposed fix ==
Provide TranslationMergeJob.getNextJobStatus, to return the JobStatus of the
next TranslationMergeJob that is WAITING or RUNNING.
== Pre-implementation notes ==
None
== Implementation details ==
None
== Tests ==
bin/test test_translationpackagingjob -t getNextJobStatus
== Demo and Q/A ==
None
= Launchpad lint =
Checking for conflicts and issues in changed files.
Linting changed files:
lib/lp/registry/model/packagingjob.py
lib/lp/translations/model/translationpackagingjob.py
lib/lp/translations/tests/test_translationpackagingjob.py
--
https://code.launchpad.net/~abentley/launchpad/translation-job-status/+merge/53326
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~abentley/launchpad/translation-job-status into lp:launchpad.
=== modified file 'lib/lp/registry/model/packagingjob.py'
--- lib/lp/registry/model/packagingjob.py 2011-02-25 21:29:09 +0000
+++ lib/lp/registry/model/packagingjob.py 2011-03-14 21:28:31 +0000
@@ -30,7 +30,10 @@
from lp.registry.model.productseries import ProductSeries
from lp.registry.model.sourcepackagename import SourcePackageName
from lp.services.database.stormbase import StormBase
-from lp.services.job.interfaces.job import IJob
+from lp.services.job.interfaces.job import (
+ IJob,
+ JobStatus,
+ )
from lp.services.job.model.job import Job
@@ -179,6 +182,24 @@
*extra_clauses)
return (cls._subclass[job.job_type](job) for job in jobs)
+ @classmethod
+ def getNextJobStatus(cls, packaging):
+ """Return the status of the next job to run."""
+ store = IStore(PackagingJob)
+ result = store.find(
+ Job, Job.id == PackagingJob.job_id,
+ PackagingJob.distroseries_id == packaging.distroseries.id,
+ PackagingJob.sourcepackagename_id ==
+ packaging.sourcepackagename.id,
+ PackagingJob.productseries_id == packaging.productseries.id,
+ PackagingJob.job_type == cls.class_job_type,
+ Job._status.is_in([JobStatus.WAITING, JobStatus.RUNNING]))
+ result.order_by(PackagingJob.id)
+ job = result.first()
+ if job is None:
+ return None
+ return job.status
+
#make accessible to zcml
schedule_job = PackagingJobDerived.scheduleJob
=== modified file 'lib/lp/translations/model/translationpackagingjob.py'
--- lib/lp/translations/model/translationpackagingjob.py 2011-02-25 21:29:09 +0000
+++ lib/lp/translations/model/translationpackagingjob.py 2011-03-14 21:28:31 +0000
@@ -57,7 +57,7 @@
@classmethod
def forPackaging(cls, packaging):
- """Create a TranslationMergeJob for a Packaging.
+ """Create a TranslationPackagingJob for a Packaging.
:param packaging: The `Packaging` to create the job for.
:return: A `TranslationMergeJob`.
=== modified file 'lib/lp/translations/tests/test_translationpackagingjob.py'
--- lib/lp/translations/tests/test_translationpackagingjob.py 2011-02-25 20:49:57 +0000
+++ lib/lp/translations/tests/test_translationpackagingjob.py 2011-03-14 21:28:31 +0000
@@ -15,8 +15,12 @@
)
from lp.registry.interfaces.packaging import IPackagingUtil
from lp.registry.model.packagingjob import PackagingJob, PackagingJobDerived
-from lp.services.job.interfaces.job import IRunnableJob
+from lp.services.job.interfaces.job import (
+ IRunnableJob,
+ JobStatus,
+ )
from lp.testing import (
+ EventRecorder,
TestCaseWithFactory,
)
from lp.translations.interfaces.side import TranslationSide
@@ -169,6 +173,74 @@
# Ensure no constraints were violated.
transaction.commit()
+ def test_getNextJobStatus(self):
+ """Should find next packaging job."""
+ #suppress job creation.
+ with EventRecorder() as recorder:
+ packaging = self.factory.makePackagingLink()
+ self.assertIs(None, TranslationMergeJob.getNextJobStatus(packaging))
+ TranslationMergeJob.forPackaging(packaging)
+ self.assertEqual(
+ JobStatus.WAITING,
+ TranslationMergeJob.getNextJobStatus(packaging))
+
+ def test_getNextJobStatus_wrong_packaging(self):
+ """Jobs on wrong packaging should be ignored."""
+ #suppress job creation.
+ with EventRecorder() as recorder:
+ packaging = self.factory.makePackagingLink()
+ self.factory.makePackagingLink(
+ productseries=packaging.productseries)
+ self.assertIs(None, TranslationMergeJob.getNextJobStatus(packaging))
+ self.factory.makePackagingLink()
+ other_packaging = self.factory.makePackagingLink(
+ distroseries=packaging.distroseries)
+ other_packaging = self.factory.makePackagingLink(
+ distroseries=packaging.distroseries)
+ self.assertIs(None, TranslationMergeJob.getNextJobStatus(packaging))
+ TranslationMergeJob.create(
+ sourcepackagename=packaging.sourcepackagename,
+ distroseries=packaging.distroseries,
+ productseries=self.factory.makeProductSeries())
+ self.assertIs(None, TranslationMergeJob.getNextJobStatus(packaging))
+
+ def test_getNextJobStatus_wrong_type(self):
+ """Only TranslationMergeJobs should result."""
+ #suppress job creation.
+ with EventRecorder() as recorder:
+ packaging = self.factory.makePackagingLink()
+ job = TranslationSplitJob.forPackaging(packaging)
+ self.assertIs(
+ None, TranslationMergeJob.getNextJobStatus(packaging))
+
+ def test_getNextJobStatus_status(self):
+ """Only RUNNING and WAITING jobs should influence status."""
+ #suppress job creation.
+ with EventRecorder() as recorder:
+ packaging = self.factory.makePackagingLink()
+ job = TranslationMergeJob.forPackaging(packaging)
+ job.start()
+ self.assertEqual(JobStatus.RUNNING,
+ TranslationMergeJob.getNextJobStatus(packaging))
+ job.fail()
+ self.assertIs(None, TranslationMergeJob.getNextJobStatus(packaging))
+ job2 = TranslationMergeJob.forPackaging(packaging)
+ job2.start()
+ job2.complete()
+ job3 = TranslationMergeJob.forPackaging(packaging)
+ job3.suspend()
+ self.assertIs(None, TranslationMergeJob.getNextJobStatus(packaging))
+
+ def test_getNextJobStatus_order(self):
+ """Status should order by id."""
+ with EventRecorder() as recorder:
+ packaging = self.factory.makePackagingLink()
+ job = TranslationMergeJob.forPackaging(packaging)
+ job.start()
+ job2 = TranslationMergeJob.forPackaging(packaging)
+ self.assertEqual(JobStatus.RUNNING,
+ TranslationMergeJob.getNextJobStatus(packaging))
+
class TestTranslationSplitJob(TestCaseWithFactory):