fix(ai): AI 分析队列 claim_next 添加租户隔离
This commit is contained in:
@@ -88,15 +88,21 @@ impl AnalysisQueue {
|
|||||||
Ok(id)
|
Ok(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn claim_next(&self) -> AiResult<Option<ai_analysis_queue::Model>> {
|
pub async fn claim_next(&self, tenant_id: Option<Uuid>) -> AiResult<Option<ai_analysis_queue::Model>> {
|
||||||
let sql = r#"
|
let sql = match tenant_id {
|
||||||
SELECT * FROM ai_analysis_queue
|
Some(tid) => format!(
|
||||||
WHERE status = 'pending'
|
"SELECT * FROM ai_analysis_queue WHERE tenant_id = '{}' AND status = 'pending' AND deleted_at IS NULL AND scheduled_at <= NOW() ORDER BY priority DESC, scheduled_at ASC LIMIT 1",
|
||||||
AND deleted_at IS NULL
|
tid
|
||||||
AND scheduled_at <= NOW()
|
),
|
||||||
ORDER BY priority DESC, scheduled_at ASC
|
None => r#"
|
||||||
LIMIT 1
|
SELECT * FROM ai_analysis_queue
|
||||||
"#;
|
WHERE status = 'pending'
|
||||||
|
AND deleted_at IS NULL
|
||||||
|
AND scheduled_at <= NOW()
|
||||||
|
ORDER BY priority DESC, scheduled_at ASC
|
||||||
|
LIMIT 1
|
||||||
|
"#.to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
let row: Option<QueueRow> = QueueRow::find_by_statement(
|
let row: Option<QueueRow> = QueueRow::find_by_statement(
|
||||||
Statement::from_string(sea_orm::DatabaseBackend::Postgres, sql.to_string()),
|
Statement::from_string(sea_orm::DatabaseBackend::Postgres, sql.to_string()),
|
||||||
|
|||||||
Reference in New Issue
Block a user