feat(contract-payment): 采购合同付款预警
This commit is contained in:
1 parent
5aa431cc8e
commit
03e5e88e27
113 files changed
+11381
-2991
No files matched your search
@@ -678,21 +678,36 @@ def recover_stale_jobs(
|
||||
)
|
||||
if on_recovered is not None:
|
||||
on_recovered(job)
|
||||
current_app.logger.warning(
|
||||
"合同任务超时回收 job_id=%s job_type=%s status=%s attempts=%s/%s timeout_seconds=%s message=%s",
|
||||
job.id, job.job_type, job.status, snap_attempts, max_attempts, int(timeout_seconds), job.message,
|
||||
)
|
||||
recovered += 1
|
||||
db.session.commit()
|
||||
if recovered:
|
||||
current_app.logger.warning("合同任务超时回收完成 domain=%s recovered=%d", domain, recovered)
|
||||
return recovered
|
||||
|
||||
|
||||
def claim_next_job(*, domain: str, job_types: list[str | JobType] | None = None, worker_id: str | None = None) -> Job | None:
|
||||
"""原子领取指定业务域下一条 queued 任务。"""
|
||||
def claim_next_job(*, domain: str | None, job_types: list[str | JobType] | None = None, worker_id: str | None = None) -> Job | None:
|
||||
"""
|
||||
原子领取指定业务域下一条 queued 任务。
|
||||
|
||||
核心逻辑:有 domain 时按业务域隔离;传入 None 时只按 job_types 领取,
|
||||
供共享的合同 worker 消费合同审查与合同付款预警子域。
|
||||
Args:
|
||||
domain: 业务域;None 表示不按域过滤。
|
||||
job_types: 可领取的任务类型。
|
||||
worker_id: 可选 worker 标识,用于领取审计。
|
||||
Returns:
|
||||
已置为 running 的任务;无可领取任务时返回 None。
|
||||
"""
|
||||
normalized_types = [_normalize_job_type(item) for item in (job_types or []) if _normalize_job_type(item)]
|
||||
now = datetime.utcnow()
|
||||
try:
|
||||
query = db.session.query(Job).filter(
|
||||
Job.domain == domain,
|
||||
Job.status == "queued",
|
||||
Job.created_at <= now,
|
||||
)
|
||||
query = db.session.query(Job).filter(Job.status == "queued", Job.created_at <= now)
|
||||
if domain is not None:
|
||||
query = query.filter(Job.domain == str(domain))
|
||||
if normalized_types:
|
||||
query = query.filter(Job.job_type.in_(normalized_types))
|
||||
job = (
|
||||
|
||||
Reference in new issue
Block a user