Beispiel #1
0
 def test_suspend(self):
     """A job that is in the WAITING state can be suspended."""
     job = Job(_status=JobStatus.WAITING)
     job.suspend()
     self.assertEqual(
         job.status,
         JobStatus.SUSPENDED)
Beispiel #2
0
 def test_resume(self):
     """A job that is suspended can be resumed."""
     job = Job(_status=JobStatus.SUSPENDED)
     job.resume()
     self.assertEqual(
         job.status,
         JobStatus.WAITING)
Beispiel #3
0
    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)
Beispiel #4
0
    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)
Beispiel #5
0
    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)
Beispiel #6
0
    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)
Beispiel #7
0
    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)
Beispiel #8
0
class StuckJob(StaticJobSource):
    """Simulation of a job that stalls."""
    implements(IRunnableJob)

    done = False

    # A list of jobs to run: id, lease_length, delay.
    #
    # For the first job, have a very long lease, so that it
    # doesn't expire and so we soak up the ZCML loading time.  For the
    # second job, have a short lease so we hit the timeout.
    jobs = [
        (10000, 0),
        (5, 30),
    ]

    def __init__(self, id, lease_length, delay):
        self.id = id
        self.lease_length = lease_length
        self.delay = delay
        self.job = Job()

    def __repr__(self):
        return '<%s(%r, lease_length=%s, delay=%s)>' % (
            self.__class__.__name__, self.id, self.lease_length, self.delay)

    def acquireLease(self):
        return self.job.acquireLease(self.lease_length)

    def run(self):
        sleep(self.delay)
Beispiel #9
0
    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 create_multiple_jobs(derived_series, parent_series):
    """Create `DistroSeriesDifferenceJob`s between parent and derived series.

    :param derived_series: A `DistroSeries` that is assumed to be derived
        from another one.
    :param parent_series: A `DistroSeries` that is a parent of
        `derived_series`.
    :return: A list of newly-created `DistributionJob` ids.
    """
    store = IStore(SourcePackagePublishingHistory)
    spn_ids = store.find(
        SourcePackagePublishingHistory.sourcepackagenameID,
        SourcePackagePublishingHistory.distroseries == derived_series.id,
        SourcePackagePublishingHistory.status.is_in(active_publishing_status))
    spn_ids = list(spn_ids)

    if len(spn_ids) == 0:
        return []

    job_ids = Job.createMultiple(store, len(spn_ids))
    return bulk.create(
            (DistributionJob.distribution, DistributionJob.distroseries,
             DistributionJob.job_type, DistributionJob.job_id,
             DistributionJob.metadata),
            [(derived_series.distribution, derived_series,
              DistributionJobType.DISTROSERIESDIFFERENCE, job_id,
              make_metadata(spn_id, parent_series.id))
             for job_id, spn_id in zip(job_ids, spn_ids)],
            get_primary_keys=True)
 def createMultiple(
     cls,
     copy_tasks,
     requester,
     copy_policy=PackageCopyPolicy.INSECURE,
     include_binaries=False,
     sponsored=None,
     unembargo=False,
     auto_approve=False,
 ):
     """See `IPlainPackageCopyJobSource`."""
     store = IMasterStore(Job)
     job_ids = Job.createMultiple(store, len(copy_tasks), requester)
     job_contents = [
         cls._composeJobInsertionTuple(
             copy_policy, include_binaries, job_id, task, sponsored, unembargo, auto_approve
         )
         for job_id, task in zip(job_ids, copy_tasks)
     ]
     return bulk.create(
         (
             PackageCopyJob.job_type,
             PackageCopyJob.target_distroseries,
             PackageCopyJob.copy_policy,
             PackageCopyJob.source_archive,
             PackageCopyJob.target_archive,
             PackageCopyJob.package_name,
             PackageCopyJob.job_id,
             PackageCopyJob.metadata,
         ),
         job_contents,
         get_primary_keys=True,
     )
Beispiel #12
0
 def createMultiple(cls,
                    copy_tasks,
                    requester,
                    copy_policy=PackageCopyPolicy.INSECURE,
                    include_binaries=False,
                    sponsored=None,
                    unembargo=False,
                    auto_approve=False,
                    silent=False):
     """See `IPlainPackageCopyJobSource`."""
     store = IMasterStore(Job)
     job_ids = Job.createMultiple(store, len(copy_tasks), requester)
     job_contents = [
         cls._composeJobInsertionTuple(copy_policy, include_binaries,
                                       job_id, task, sponsored, unembargo,
                                       auto_approve, silent)
         for job_id, task in zip(job_ids, copy_tasks)
     ]
     return bulk.create(
         (PackageCopyJob.job_type, PackageCopyJob.target_distroseries,
          PackageCopyJob.copy_policy, PackageCopyJob.source_archive,
          PackageCopyJob.target_archive, PackageCopyJob.package_name,
          PackageCopyJob.job_id, PackageCopyJob.metadata),
         job_contents,
         get_primary_keys=True)
def create_multiple_jobs(derived_series, parent_series):
    """Create `DistroSeriesDifferenceJob`s between parent and derived series.

    :param derived_series: A `DistroSeries` that is assumed to be derived
        from another one.
    :param parent_series: A `DistroSeries` that is a parent of
        `derived_series`.
    :return: A list of newly-created `DistributionJob` ids.
    """
    store = IStore(SourcePackagePublishingHistory)
    spn_ids = store.find(
        SourcePackagePublishingHistory.sourcepackagenameID,
        SourcePackagePublishingHistory.distroseries == derived_series.id,
        SourcePackagePublishingHistory.status.is_in(active_publishing_status))
    spn_ids = list(spn_ids)

    if len(spn_ids) == 0:
        return []

    job_ids = Job.createMultiple(store, len(spn_ids))
    return bulk.create(
            (DistributionJob.distribution, DistributionJob.distroseries,
             DistributionJob.job_type, DistributionJob.job_id,
             DistributionJob.metadata),
            [(derived_series.distribution, derived_series,
              DistributionJobType.DISTROSERIESDIFFERENCE, job_id,
              make_metadata(spn_id, parent_series.id))
             for job_id, spn_id in zip(job_ids, spn_ids)],
            get_primary_keys=True)
class StuckJob(StaticJobSource):
    """Simulation of a job that stalls."""
    implements(IRunnableJob)

    done = False

    # A list of jobs to run: id, lease_length, delay.
    #
    # For the first job, have a very long lease, so that it
    # doesn't expire and so we soak up the ZCML loading time.  For the
    # second job, have a short lease so we hit the timeout.
    jobs = [
        (10000, 0),
        (5, 30),
        ]

    def __init__(self, id, lease_length, delay):
        self.id = id
        self.lease_length = lease_length
        self.delay = delay
        self.job = Job()

    def __repr__(self):
        return '<%s(%r, lease_length=%s, delay=%s)>' % (
            self.__class__.__name__, self.id, self.lease_length, self.delay)

    def acquireLease(self):
        return self.job.acquireLease(self.lease_length)

    def run(self):
        sleep(self.delay)
Beispiel #15
0
 def test_ready_jobs(self):
     """Job.ready_jobs should include new jobs."""
     preexisting = self._sampleData()
     job = Job()
     self.assertEqual(
         preexisting + [(job.id,)],
         list(Store.of(job).execute(Job.ready_jobs)))
Beispiel #16
0
 def __init__(self, distribution, distroseries, job_type, metadata):
     super(DistributionJob, self).__init__()
     self.job = Job()
     self.distribution = distribution
     self.distroseries = distroseries
     self.job_type = job_type
     self.metadata = metadata
Beispiel #17
0
 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)
Beispiel #18
0
 def test_ready_jobs_lease_expired(self):
     """Job.ready_jobs should include jobs with expired leases."""
     preexisting = self._sampleData()
     UNIX_EPOCH = datetime.fromtimestamp(0, pytz.timezone('UTC'))
     job = Job(lease_expires=UNIX_EPOCH)
     self.assertEqual(
         preexisting + [(job.id,)],
         list(Store.of(job).execute(Job.ready_jobs)))
Beispiel #19
0
 def makeJob(self):
     """See `ISourcePackageRecipeBuildJob`."""
     store = Store.of(self)
     job = Job()
     store.add(job)
     specific_job = getUtility(ISourcePackageRecipeBuildJobSource).new(
         self, job)
     return specific_job
Beispiel #20
0
 def test_ready_jobs_lease_in_future(self):
     """Job.ready_jobs should not include jobs with active leases."""
     preexisting = self._sampleData()
     future = datetime.fromtimestamp(
         time.time() + 1000, pytz.timezone('UTC'))
     job = Job(lease_expires=future)
     self.assertEqual(
         preexisting, list(Store.of(job).execute(Job.ready_jobs)))
 def create(cls, packagediff):
     job = Job(
         base_job_type=JobType.GENERATE_PACKAGE_DIFF,
         requester=packagediff.requester,
         base_json_data=simplejson.dumps({'packagediff': packagediff.id}))
     derived = cls(job)
     derived.celeryRunOnCommit()
     return derived
Beispiel #22
0
    def test_start_manages_transactions(self):
        # Job.start() does not commit the transaction by default.
        with TransactionRecorder() as recorder:
            job = Job()
            job.start()
            self.assertEqual([], recorder.transaction_calls)

        # If explicitly specified, Job.start() commits the transaction.
        with TransactionRecorder() as recorder:
            job = Job()
            job.start(manage_transaction=True)
            self.assertEqual(['commit'], recorder.transaction_calls)
Beispiel #23
0
 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)])
Beispiel #24
0
 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)))
Beispiel #25
0
 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 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
Beispiel #27
0
 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 = []
Beispiel #28
0
    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')
Beispiel #29
0
    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
Beispiel #30
0
 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)
Beispiel #31
0
    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
Beispiel #33
0
    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 __init__(self, id, lease_length, delay):
     self.id = id
     self.lease_length = lease_length
     self.delay = delay
     self.job = Job()