def makeJob(self): """See `ISourcePackageRecipeBuildJob`.""" store = Store.of(self) job = Job() store.add(job) specific_job = getUtility(ISourcePackageRecipeBuildJobSource).new( self, job) return specific_job
def test_start_increments_attempt_count(self): """Job.start should increment the attempt count.""" job = Job(date_finished=UTC_NOW) self.assertEqual(0, job.attempt_count) job.start() self.assertEqual(1, job.attempt_count) job.queue() job.start() self.assertEqual(2, job.attempt_count)
def setUp(self): super(TestBuildersHomepage, self).setUp() # Create a non-buildfarm job to ensure that the BuildQueue and # Job IDs differ, detecting bug #919116. Job() # And create BuildFarmJobs of the various types to throw IDs off # even further, detecting more preloading issues. self.factory.makeBinaryPackageBuild().queueBuild() self.factory.makeSourcePackageRecipeBuild().queueBuild() self.factory.makeTranslationTemplatesBuild().queueBuild()
def test_fail(self): """Job.fail should update the Job appropriately. It should set date_finished and set the job status to FAILED. """ job = Job(_status=JobStatus.RUNNING) self.assertEqual(None, job.date_finished) job.fail() self.assertNotEqual(None, job.date_finished) self.assertEqual(job.status, JobStatus.FAILED)
def test_queue(self): """Job.queue should update the job appropriately. It should set date_finished, and set status to WAITING. """ job = Job(_status=JobStatus.RUNNING) self.assertEqual(None, job.date_finished) job.queue() self.assertNotEqual(None, job.date_finished) self.assertEqual(job.status, JobStatus.WAITING)
def test_complete(self): """Job.complete should update the Job appropriately. It should set date_finished and set the job status to COMPLETED. """ job = Job(_status=JobStatus.RUNNING) self.assertEqual(None, job.date_finished) job.complete() self.assertNotEqual(None, job.date_finished) self.assertEqual(job.status, JobStatus.COMPLETED)
def test_null_reference(self): # create() handles None as a Reference value. job = IStore(Job).add(Job()) wanted = [(None, job, BranchJobType.RECLAIM_BRANCH_SPACE)] [branchjob] = bulk.create( (BranchJob.branch, BranchJob.job, BranchJob.job_type), wanted, get_objects=True) self.assertEqual( wanted, [(branchjob.branch, branchjob.job, branchjob.job_type)])
def create(cls, sourcepackagerelease, libraryfilealias, requester): job = Job( base_job_type=JobType.UPLOAD_PACKAGE_TRANSLATIONS, requester=requester, base_json_data=simplejson.dumps( {'sourcepackagerelease': sourcepackagerelease.id, 'libraryfilealias': libraryfilealias.id})) derived = cls(job) derived.celeryRunOnCommit() return derived
def test_ready_jobs_not_jobs_scheduled_in_future(self): """Job.ready_jobs does not included jobs scheduled for a time in the future. """ preexisting = self._sampleData() future = datetime.fromtimestamp( time.time() + 1000, pytz.timezone('UTC')) job = Job(scheduled_start=future) self.assertEqual( preexisting, list(Store.of(job).execute(Job.ready_jobs)))
def test_acquireLeaseTimeout(self): """Test that getTimeout correctly calculates value from lease. The imprecision is because leases are relative to the current time, and the current time may have changed by the time we get to job.getTimeout() <= 300. """ job = Job() job.acquireLease(300) self.assertTrue(job.getTimeout() > 0) self.assertTrue(job.getTimeout() <= 300)
def __init__(self, completion_message, oops_recipients=None, error_recipients=None): self.message = completion_message self.job = Job() self.oops_recipients = oops_recipients if self.oops_recipients is None: self.oops_recipients = [] self.error_recipients = error_recipients if self.error_recipients is None: self.error_recipients = []
def test_start(self): """Job.start should update the object appropriately. It should set date_started, clear date_finished, and set the status to RUNNING.""" job = Job(date_finished=UTC_NOW) self.assertEqual(None, job.date_started) self.assertNotEqual(None, job.date_finished) job.start() self.assertNotEqual(None, job.date_started) self.assertEqual(None, job.date_finished) self.assertEqual(job.status, JobStatus.RUNNING)
def __init__(self, product, job_type, metadata): """Constructor. :param product: The product the job is for. :param job_type: The type job the product needs run. :param metadata: A dict of JSON-compatible data to pass to the job. """ super(ProductJob, self).__init__() self.job = Job() self.product = product self.job_type = job_type json_data = simplejson.dumps(metadata) self._json_data = json_data.decode('utf-8')
def __init__(self, archive, job_type, metadata): """Create an ArchiveJob. :param archive: the `IArchive` this job relates to. :param job_type: the `ArchiveJobType` of this job. :param metadata: the type-specific variables, as a json-compatible dict. """ super(ArchiveJob, self).__init__() self.job = Job() self.archive = archive self.job_type = job_type self.metadata = metadata
def test_can_return_ids(self): # create() can be asked to return the created IDs instead of objects. job = IStore(Job).add(Job()) IStore(Job).flush() wanted = [(None, job, BranchJobType.RECLAIM_BRANCH_SPACE)] with StormStatementRecorder() as recorder: [created_id] = bulk.create( (BranchJob.branch, BranchJob.job, BranchJob.job_type), wanted, get_primary_keys=True) self.assertThat(recorder, HasQueryCount(Equals(1))) [reclaimjob] = ReclaimBranchSpaceJob.iterReady() self.assertEqual(created_id, reclaimjob.context.id)
def __init__(self, question, job_type, metadata): """Constructor. :param question: The question related to this job. :param job_type: The specific job being performed for the question. :param metadata: The type-specific variables, as a JSON-compatible dict. """ super(QuestionJob, self).__init__() self.job = Job() self.job_type = job_type self.question = question json_data = simplejson.dumps(metadata) self._json_data = json_data.decode('utf-8')
def create(cls, distroseries, libraryfilealias, sourcepackagename, requester): job = Job(base_job_type=JobType.UPLOAD_PACKAGE_TRANSLATIONS, requester=requester, base_json_data=json.dumps({ 'distroseries': distroseries.id, 'libraryfilealias': libraryfilealias.id, 'sourcepackagename': sourcepackagename.id, })) derived = cls(job) derived.celeryRunOnCommit() return derived
def __init__(self, branch, job_type, metadata, **job_args): """Constructor. Extra keyword parameters are used to construct the underlying Job object. :param branch: The database branch this job relates to. :param job_type: The BranchJobType of this job. :param metadata: The type-specific variables, as a JSON-compatible dict. """ json_data = simplejson.dumps(metadata) SQLBase.__init__( self, job=Job(**job_args), branch=branch, job_type=job_type, _json_data=json_data)
def test_queue_manages_transactions(self): # Job.queue() does not commit the transaction by default. job = Job() job.start() with TransactionRecorder() as recorder: job.queue() self.assertEqual([], recorder.transaction_calls) # If explicitly specified, Job.queue() commits the transaction. # Note that there is an additional commit to update the job status. job = Job() job.start() with TransactionRecorder() as recorder: job.queue(manage_transaction=True) self.assertEqual(['commit', 'commit'], recorder.transaction_calls) # If abort_transaction=True is also passed to Job.queue() # the transaction is first aborted, then two times committed. job = Job() job.start() with TransactionRecorder() as recorder: job.queue(manage_transaction=True, abort_transaction=True) self.assertEqual( ['abort', 'commit', 'commit'], recorder.transaction_calls)
def __init__(self, snapbuild, job_type, metadata, **job_args): """Constructor. Extra keyword arguments are used to construct the underlying Job object. :param snapbuild: The `ISnapBuild` this job relates to. :param job_type: The `SnapBuildJobType` of this job. :param metadata: The type-specific variables, as a JSON-compatible dict. """ super(SnapBuildJob, self).__init__() self.job = Job(**job_args) self.snapbuild = snapbuild self.job_type = job_type self.metadata = metadata
def __init__(self, blob, job_type, metadata): """Constructor. :param blob: The ITemporaryBlobStorage object this job relates to. :param job_type: The ApportJobType of this job. :param metadata: The type-specific variables, as a JSON-compatible dict. """ super(ApportJob, self).__init__() json_data = simplejson.dumps(metadata) self.job = Job() self.blob = blob self.job_type = job_type # XXX AaronBentley 2009-01-29 bug=322819: This should be a # bytestring, but the DB representation is unicode. self._json_data = json_data.decode('utf-8')
def __init__(self, branch_merge_proposal, job_type, metadata): """Constructor. :param branch_merge_proposal: The proposal this job relates to. :param job_type: The BranchMergeProposalJobType of this job. :param metadata: The type-specific variables, as a JSON-compatible dict. """ super(BranchMergeProposalJob, self).__init__() json_data = simplejson.dumps(metadata) self.job = Job() self.branch_merge_proposal = branch_merge_proposal self.job_type = job_type # XXX AaronBentley 2009-01-29 bug=322819: This should be a bytestring, # but the DB representation is unicode. self._json_data = json_data.decode('utf-8')
def test_load_can_be_skipped(self): # create() can be told not to load the created rows. job = IStore(Job).add(Job()) IStore(Job).flush() wanted = [(None, job, BranchJobType.RECLAIM_BRANCH_SPACE)] with StormStatementRecorder() as recorder: self.assertIs( None, bulk.create( (BranchJob.branch, BranchJob.job, BranchJob.job_type), wanted, get_objects=False)) self.assertThat(recorder, HasQueryCount(Equals(1))) [reclaimjob] = ReclaimBranchSpaceJob.iterReady() branchjob = reclaimjob.context self.assertEqual( wanted, [(branchjob.branch, branchjob.job, branchjob.job_type)])
def create(cls, productseries=None, distroseries=None, sourcepackagename=None, potemplate=None): """"Create a TranslationPackagingJob backed by TranslationSharingJob. :param productseries: The ProductSeries side of the Packaging. :param distroseries: The distroseries of the Packaging sourcepackage. :param sourcepackagename: The name of the Packaging sourcepackage. :param potemplate: POTemplate to restrict to (if any). """ context = TranslationSharingJob(Job(), cls.class_job_type, productseries, distroseries, sourcepackagename, potemplate) derived = cls(context) derived.celeryRunOnCommit() return derived
def __init__(self, repository, job_type, metadata, **job_args): """Constructor. Extra keyword arguments are used to construct the underlying Job object. :param repository: The database repository this job relates to. :param job_type: The `GitJobType` of this job. :param metadata: The type-specific variables, as a JSON-compatible dict. """ super(GitJob, self).__init__() self.job = Job(**job_args) self.repository = repository self.job_type = job_type self.metadata = metadata if repository is not None: self.metadata["repository_name"] = repository.unique_name
def __init__(self, source_archive, target_archive, target_distroseries, job_type, metadata, requester, package_name=None, copy_policy=None): super(PackageCopyJob, self).__init__() self.job = Job() self.job.requester = requester self.job_type = job_type self.source_archive = source_archive self.target_archive = target_archive self.target_distroseries = target_distroseries self.package_name = unicode(package_name) self.copy_policy = copy_policy self.metadata = metadata
def __init__(self, job_type, pillar, grantee, metadata): """Constructor. :param job_type: The BranchMergeProposalJobType of this job. :param metadata: The type-specific variables, as a JSON-compatible dict. """ super(SharingJob, self).__init__() json_data = simplejson.dumps(metadata) self.job = Job() self.job_type = job_type self.grantee = grantee self.product = self.distro = None if IProduct.providedBy(pillar): self.product = pillar else: self.distro = pillar # XXX AaronBentley 2009-01-29 bug=322819: This should be a bytestring, # but the DB representation is unicode. self._json_data = json_data.decode('utf-8')
def __init__(self, minor_person, major_person, job_type, metadata, requester=None): """Constructor. :param minor_person: The person or team being added to or removed from the major_person. :param major_person: The person or team that is receiving or losing the minor person. :param job_type: The specific membership action being performed. :param metadata: The type-specific variables, as a JSON-compatible dict. """ super(PersonTransferJob, self).__init__() self.job = Job(requester=requester) self.job_type = job_type self.major_person = major_person self.minor_person = minor_person json_data = simplejson.dumps(metadata) # XXX AaronBentley 2009-01-29 bug=322819: This should be a bytestring, # but the DB representation is unicode. self._json_data = json_data.decode('utf-8')
def __init__(self, job_id=None): if job_id is not None: store = IStore(Job) self.job = store.find(Job, id=job_id)[0] else: self.job = Job(max_retries=2)
def test_stores_requester(self): job = Job() random_joe = self.factory.makePerson() job.requester = random_joe self.assertEqual(random_joe, job.requester)