Files
momentry_core/src/core/vlm/mod.rs
T
Accusys 63fbbe1225 release: v1.3.1 - Pipeline Queue Integration, OCR Fix, Worker Compatibility
Major Changes:
- Pipeline Queue integration completed (internal.file + pipeline.commands)
- Fixed old job_worker database compatibility with new command_queue table
- Compiled Swift OCR binary (was missing, causing empty OCR results)
- Added deep scan functionality through re-scan API

Fixes:
- Changed CommandJob.id from i32 to i64 for database compatibility
- Added UUID generation in create_command (message_id field)
- Fixed claim_pending_commands to query queue_name = 'internal.file'
- Fixed field mappings: command_id → message_id, job_type → command_type
- Added support for 'processing' status in CommandJobStatus

Queue System:
- internal.file queue: for register/unregister/re-scan commands (job_worker)
- pipeline.commands queue: for vectorize/store_asrx/etc commands (pipeline_worker)

Documentation:
- Added comprehensive queue system documentation
- Created M4 workspace status reports
- Updated AGENTS.md with queue system details
2026-10-12 10:00:51 +08:00

85 lines
2.2 KiB
Rust

pub mod client;
pub mod consumer;
pub mod error;
pub mod producer;
pub mod types;
pub mod worker;
pub use client::VLMClient;
pub use consumer::VLMConsumer;
pub use error::VLMError;
pub use producer::VLMProducer;
pub use types::{
VLMMessage, VLMQueueStatus, VLMRequest, VLMRequestType, VLMResult, VLMStats, VLMStatus,
};
pub use worker::{start_workers, VLMWorker};
use sqlx::PgPool;
use std::sync::Arc;
use once_cell::sync::OnceCell;
/// Global VLM Producer instance
static VLM_PRODUCER: OnceCell<Arc<VLMProducer>> = OnceCell::new();
/// Initialize global VLM Producer
pub fn init_producer(db: PgPool) {
let producer = Arc::new(VLMProducer::new(db));
let _ = VLM_PRODUCER.set(producer);
}
/// Get global VLM Producer
pub fn get_producer() -> Option<Arc<VLMProducer>> {
VLM_PRODUCER.get().cloned()
}
/// 初始化 VLM 队列系统
pub async fn init(db: PgPool) -> Result<(), error::VLMError> {
// 1. 创建表(如果不存在)
create_tables_if_not_exists(&db).await?;
// 2. 启动 Workers
let num_workers = std::env::var("MOMENTRY_VLM_MAX_CONCURRENT")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(3);
worker::start_workers(db, num_workers, 2).await;
Ok(())
}
/// 创建表(如果不存在)
async fn create_tables_if_not_exists(db: &PgPool) -> Result<(), error::VLMError> {
// 检查表是否存在
let table_exists: bool = sqlx::query_scalar(
r#"
SELECT EXISTS (
SELECT 1 FROM information_schema.tables
WHERE table_name = 'vlm_requests'
)
"#,
)
.fetch_one(db)
.await?;
if !table_exists {
// 读取迁移文件并执行
tracing::info!("Creating VLM queue tables...");
// 这里简化处理,实际应该使用 sqlx-cli 运行迁移
// 暂时使用硬编码 SQL(从迁移文件提取)
let sql = include_str!("../../../migrations/20261011_vlm_queue.sql");
// 分割 SQL 语句并逐个执行
for statement in sql.split(';') {
let statement = statement.trim();
if !statement.is_empty() {
sqlx::query(statement).execute(db).await?;
}
}
tracing::info!("VLM queue tables created successfully");
}
Ok(())
}