Esempio n. 1
0
 def iterReady(job_type=None):
     from lp.code.model.branch import Branch
     SourceBranch = ClassAlias(Branch)
     TargetBranch = ClassAlias(Branch)
     clauses = [
         BranchMergeProposalJob.job == Job.id,
         Job._status.is_in([JobStatus.WAITING, JobStatus.RUNNING]),
         BranchMergeProposalJob.branch_merge_proposal ==
         BranchMergeProposal.id,
         BranchMergeProposal.source_branch == SourceBranch.id,
         BranchMergeProposal.target_branch == TargetBranch.id,
     ]
     if job_type is not None:
         clauses.append(BranchMergeProposalJob.job_type == job_type)
     jobs = IMasterStore(Branch).find(
         (BranchMergeProposalJob, Job, BranchMergeProposal, SourceBranch,
          TargetBranch), And(*clauses))
     # Order by the job status first (to get running before waiting), then
     # the date_created, then job type.  This should give us all creation
     # jobs before comment jobs.
     jobs = jobs.order_by(Desc(Job._status), Job.date_created,
                          Desc(BranchMergeProposalJob.job_type))
     # Now only return one job for any given merge proposal.
     ready_jobs = []
     seen_merge_proposals = set()
     for bmp_job, job, bmp, source, target in jobs:
         # If we've seen this merge proposal already, skip this job.
         if bmp.id in seen_merge_proposals:
             continue
         # We have now seen this merge proposal.
         seen_merge_proposals.add(bmp.id)
         # If the job is running, then skip it
         if job.status == JobStatus.RUNNING:
             continue
         derived_job = bmp_job.makeDerived()
         # If the job is an update preview diff, then check that it is
         # ready.
         if IUpdatePreviewDiffJob.providedBy(derived_job):
             try:
                 derived_job.checkReady()
             except (UpdatePreviewDiffNotReady, BranchHasPendingWrites):
                 # If the job was created under 15 minutes ago wait a bit.
                 minutes = (
                     config.codehosting.update_preview_diff_ready_timeout)
                 cut_off_time = (datetime.now(pytz.UTC) -
                                 timedelta(minutes=minutes))
                 if job.date_created > cut_off_time:
                     continue
         ready_jobs.append(derived_job)
     return ready_jobs
Esempio n. 2
0
 def iterReady(job_type=None):
     clauses = [
         BranchMergeProposalJob.job == Job.id,
         Job._status.is_in([JobStatus.WAITING, JobStatus.RUNNING]),
         BranchMergeProposalJob.branch_merge_proposal ==
         BranchMergeProposal.id,
     ]
     if job_type is not None:
         clauses.append(BranchMergeProposalJob.job_type == job_type)
     jobs = IMasterStore(BranchMergeProposalJob).find(
         (BranchMergeProposalJob, Job, BranchMergeProposal), And(*clauses))
     # Order by the job status first (to get running before waiting), then
     # the date_created, then job type.  This should give us all creation
     # jobs before comment jobs.
     jobs = jobs.order_by(Desc(Job._status), Job.date_created,
                          Desc(BranchMergeProposalJob.job_type))
     # Now only return one job for any given merge proposal.
     ready_jobs = []
     seen_merge_proposals = set()
     for bmp_job, job, bmp in jobs:
         # If we've seen this merge proposal already, skip this job.
         if bmp.id in seen_merge_proposals:
             continue
         # We have now seen this merge proposal.
         seen_merge_proposals.add(bmp.id)
         # If the job is running or can't currently be run due to its
         # lease or its start time, then skip it.
         if (job.status == JobStatus.RUNNING
                 or (job.lease_expires is not None
                     and job.lease_expires >= datetime.now(pytz.UTC))
                 or (job.scheduled_start is not None
                     and job.scheduled_start > datetime.now(pytz.UTC))):
             continue
         derived_job = bmp_job.makeDerived()
         # If the job is an update preview diff, then check that it is
         # ready.
         if IUpdatePreviewDiffJob.providedBy(derived_job):
             try:
                 derived_job.checkReady()
             except (UpdatePreviewDiffNotReady, BranchHasPendingWrites):
                 # If the job was created under 15 minutes ago wait a bit.
                 minutes = (
                     config.codehosting.update_preview_diff_ready_timeout)
                 cut_off_time = (datetime.now(pytz.UTC) -
                                 timedelta(minutes=minutes))
                 if job.date_created > cut_off_time:
                     continue
         ready_jobs.append(derived_job)
     return ready_jobs
    def iterReady(job_type=None):
        from lp.code.model.branch import Branch

        SourceBranch = ClassAlias(Branch)
        TargetBranch = ClassAlias(Branch)
        clauses = [
            BranchMergeProposalJob.job == Job.id,
            Job._status.is_in([JobStatus.WAITING, JobStatus.RUNNING]),
            BranchMergeProposalJob.branch_merge_proposal == BranchMergeProposal.id,
            BranchMergeProposal.source_branch == SourceBranch.id,
            BranchMergeProposal.target_branch == TargetBranch.id,
        ]
        if job_type is not None:
            clauses.append(BranchMergeProposalJob.job_type == job_type)
        jobs = IMasterStore(Branch).find(
            (BranchMergeProposalJob, Job, BranchMergeProposal, SourceBranch, TargetBranch), And(*clauses)
        )
        # Order by the job status first (to get running before waiting), then
        # the date_created, then job type.  This should give us all creation
        # jobs before comment jobs.
        jobs = jobs.order_by(Desc(Job._status), Job.date_created, Desc(BranchMergeProposalJob.job_type))
        # Now only return one job for any given merge proposal.
        ready_jobs = []
        seen_merge_proposals = set()
        for bmp_job, job, bmp, source, target in jobs:
            # If we've seen this merge proposal already, skip this job.
            if bmp.id in seen_merge_proposals:
                continue
            # We have now seen this merge proposal.
            seen_merge_proposals.add(bmp.id)
            # If the job is running, then skip it
            if job.status == JobStatus.RUNNING:
                continue
            derived_job = bmp_job.makeDerived()
            # If the job is an update preview diff, then check that it is
            # ready.
            if IUpdatePreviewDiffJob.providedBy(derived_job):
                try:
                    derived_job.checkReady()
                except (UpdatePreviewDiffNotReady, BranchHasPendingWrites):
                    # If the job was created under 15 minutes ago wait a bit.
                    minutes = config.codehosting.update_preview_diff_ready_timeout
                    cut_off_time = datetime.now(pytz.UTC) - timedelta(minutes=minutes)
                    if job.date_created > cut_off_time:
                        continue
            ready_jobs.append(derived_job)
        return ready_jobs