|
|
@@ -23,8 +23,8 @@ def get_next_unprocessed_demand() -> Optional[Dict[str, Any]]:
|
|
|
"""
|
|
|
联表查询 demand_content 和 demand_find_task,找到创建最早且未处理的 demand_content。
|
|
|
|
|
|
- 未处理定义:该 demand_content_id 下无 status 为 0/1/2 的任务
|
|
|
- (即无待执行、执行中、成功的记录)
|
|
|
+ 未处理定义:该 demand_content_id 在 demand_find_task 中尚无任何记录。
|
|
|
+ 已有任务则视为已跑过(含失败),不再被定时任务选中。
|
|
|
|
|
|
Returns:
|
|
|
{"demand_content_id": int, "query": str} 或 None
|
|
|
@@ -35,7 +35,7 @@ def get_next_unprocessed_demand() -> Optional[Dict[str, Any]]:
|
|
|
FROM demand_content dc
|
|
|
WHERE NOT EXISTS (
|
|
|
SELECT 1 FROM demand_find_task t
|
|
|
- WHERE t.demand_content_id = dc.id AND t.status IN (%s, %s, %s)
|
|
|
+ WHERE t.demand_content_id = dc.id
|
|
|
)
|
|
|
ORDER BY dc.id ASC
|
|
|
LIMIT 1
|
|
|
@@ -44,7 +44,7 @@ def get_next_unprocessed_demand() -> Optional[Dict[str, Any]]:
|
|
|
try:
|
|
|
conn = get_connection()
|
|
|
with conn.cursor() as cur:
|
|
|
- cur.execute(sql, (STATUS_PENDING, STATUS_RUNNING, STATUS_SUCCESS))
|
|
|
+ cur.execute(sql)
|
|
|
row = cur.fetchone()
|
|
|
return dict(row) if row else None
|
|
|
except Exception as e:
|