本文整理汇总了Python中lp.services.database.interfaces.IMasterStore.order_by方法的典型用法代码示例。如果您正苦于以下问题:Python IMasterStore.order_by方法的具体用法?Python IMasterStore.order_by怎么用?Python IMasterStore.order_by使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lp.services.database.interfaces.IMasterStore
的用法示例。
在下文中一共展示了IMasterStore.order_by方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: iterReady
# 需要导入模块: from lp.services.database.interfaces import IMasterStore [as 别名]
# 或者: from lp.services.database.interfaces.IMasterStore import order_by [as 别名]
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