本文整理匯總了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