-- ============================================ -- Pipeline Queue 集成 -- ============================================ -- Version: 1.0 -- Date: 2026-10-11 -- Description: Pipeline 命令队列路由配置 -- ============================================ -- ============================================ -- 1. 插入 Pipeline 命令路由 -- ============================================ INSERT INTO queue_routes (command_type, command_category, queue_name, handler, priority, billing_required) VALUES -- Pipeline 操作 ('internal', 'pipeline_store_asrx', 'pipeline.commands', 'pipeline_worker', 1, false), ('internal', 'pipeline_execute_rule1', 'pipeline.commands', 'pipeline_worker', 2, false), ('internal', 'pipeline_vectorize', 'pipeline.commands', 'pipeline_worker', 3, false), ('internal', 'pipeline_phase1_pack', 'pipeline.commands', 'pipeline_worker', 2, false), ('internal', 'pipeline_mark_complete', 'pipeline.commands', 'pipeline_worker', 1, false), ('internal', 'pipeline_execute_rule3', 'pipeline.commands', 'pipeline_worker', 2, false), ('internal', 'pipeline_reindex_embeddings', 'pipeline.commands', 'pipeline_worker', 3, false) ON CONFLICT (command_type, command_category) DO NOTHING; -- ============================================ -- 2. 创建 Pipeline 进度追踪表 -- ============================================ CREATE TABLE IF NOT EXISTS pipeline_progress ( id SERIAL PRIMARY KEY, command_id VARCHAR(36) NOT NULL UNIQUE, file_uuid VARCHAR(32) NOT NULL, command_type VARCHAR(50) NOT NULL, -- 进度 progress INTEGER DEFAULT 0, -- 0-100 message TEXT, processed_count BIGINT DEFAULT 0, total_count BIGINT DEFAULT 0, -- 状态 status VARCHAR(20) DEFAULT 'processing', error_message TEXT, -- 时间戳 started_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(), completed_at TIMESTAMP WITH TIME ZONE, -- 索引 FOREIGN KEY (command_id) REFERENCES command_queue(message_id) ON DELETE CASCADE ); CREATE INDEX idx_pipeline_progress_file ON pipeline_progress(file_uuid, started_at); CREATE INDEX idx_pipeline_progress_status ON pipeline_progress(status, started_at); -- ============================================ -- 3. 创建 Pipeline 执行日志视图 -- ============================================ CREATE OR REPLACE VIEW pipeline_execution_stats AS SELECT command_category, COUNT(*) as total_executions, COUNT(*) FILTER (WHERE status = 'completed') as successful, COUNT(*) FILTER (WHERE status = 'failed') as failed, AVG(EXTRACT(EPOCH FROM (processing_completed_at - processing_started_at)) * 1000) FILTER (WHERE status = 'completed') as avg_duration_ms, MIN(processing_started_at) as first_execution, MAX(processing_started_at) as last_execution FROM command_queue WHERE command_type = 'internal' AND command_category LIKE 'pipeline_%' GROUP BY command_category ORDER BY command_category; -- ============================================ -- Schema 扩展完成 -- ============================================