feat: 新增 Job Worker 系統與 API 文檔全面更新
This commit is contained in:
+28
-28
@@ -8,6 +8,7 @@ use std::sync::{Arc, Mutex};
|
||||
use momentry_core::core::api_key::{ApiKeyService, ApiKeyType};
|
||||
use momentry_core::core::chunk::types::{Chunk, ChunkRule, ChunkType};
|
||||
use momentry_core::core::db::Database;
|
||||
use momentry_core::core::time::FrameTime;
|
||||
use momentry_core::ui::progress::{ProcessorType, ProgressState, ProgressUi};
|
||||
use momentry_core::{
|
||||
Embedder, OutputDir, PostgresDb, QdrantDb, RedisClient, VectorPayload, VideoRecord, VideoStatus,
|
||||
@@ -821,6 +822,7 @@ enum N8nAction {
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
dotenv::dotenv().ok();
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let cli = Cli::parse();
|
||||
@@ -1808,16 +1810,14 @@ async fn main() -> Result<()> {
|
||||
// Store ASR sentence pre_chunks
|
||||
let mut asr_pre_chunk_ids = Vec::new();
|
||||
for seg in asr_result.segments.iter() {
|
||||
let start_frame = (seg.start * fps) as i64;
|
||||
let end_frame = (seg.end * fps) as i64;
|
||||
let start_frame = FrameTime::from_seconds(seg.start, fps).frames();
|
||||
let end_frame = FrameTime::from_seconds(seg.end, fps).frames();
|
||||
let pre_chunk = momentry_core::core::db::postgres_db::PreChunk {
|
||||
id: 0,
|
||||
file_id,
|
||||
source_type: "asr".to_string(),
|
||||
source_file: Some(asr_path.clone()),
|
||||
chunk_type: "sentence".to_string(),
|
||||
start_time: seg.start,
|
||||
end_time: seg.end,
|
||||
start_frame,
|
||||
end_frame,
|
||||
fps,
|
||||
@@ -1840,8 +1840,6 @@ async fn main() -> Result<()> {
|
||||
source_type: "cut".to_string(),
|
||||
source_file: Some(cut_path.clone()),
|
||||
chunk_type: "cut".to_string(),
|
||||
start_time: scene.start_time,
|
||||
end_time: scene.end_time,
|
||||
start_frame: scene.start_frame as i64,
|
||||
end_frame: scene.end_frame as i64,
|
||||
fps,
|
||||
@@ -1863,8 +1861,8 @@ async fn main() -> Result<()> {
|
||||
let mut time_start = 0.0;
|
||||
while time_start < duration {
|
||||
let time_end = (time_start + 10.0).min(duration);
|
||||
let start_frame = (time_start * fps) as i64;
|
||||
let end_frame = (time_end * fps) as i64;
|
||||
let start_frame = FrameTime::from_seconds(time_start, fps).frames();
|
||||
let end_frame = FrameTime::from_seconds(time_end, fps).frames();
|
||||
|
||||
let pre_chunk = momentry_core::core::db::postgres_db::PreChunk {
|
||||
id: 0,
|
||||
@@ -1872,8 +1870,6 @@ async fn main() -> Result<()> {
|
||||
source_type: "time".to_string(),
|
||||
source_file: None,
|
||||
chunk_type: "time".to_string(),
|
||||
start_time: time_start,
|
||||
end_time: time_end,
|
||||
start_frame,
|
||||
end_frame,
|
||||
fps,
|
||||
@@ -1965,7 +1961,7 @@ async fn main() -> Result<()> {
|
||||
let mut sentence_chunks = Vec::new();
|
||||
for (i, seg) in asr_result.segments.iter().enumerate() {
|
||||
let pre_chunk_id = asr_pre_chunk_ids.get(i).copied().unwrap_or(0);
|
||||
let chunk = Chunk::new(
|
||||
let chunk = Chunk::from_seconds(
|
||||
file_id as i32,
|
||||
uuid.clone(),
|
||||
i as u32,
|
||||
@@ -1987,7 +1983,7 @@ async fn main() -> Result<()> {
|
||||
let mut cut_chunks = Vec::new();
|
||||
for (i, scene) in cut_result.scenes.iter().enumerate() {
|
||||
let pre_chunk_id = cut_pre_chunk_ids.get(i).copied().unwrap_or(0);
|
||||
let chunk = Chunk::new(
|
||||
let chunk = Chunk::from_seconds(
|
||||
file_id as i32,
|
||||
uuid.clone(),
|
||||
i as u32,
|
||||
@@ -2016,8 +2012,8 @@ async fn main() -> Result<()> {
|
||||
i as u32,
|
||||
ChunkType::TimeBased,
|
||||
ChunkRule::Rule1,
|
||||
tc.start_time,
|
||||
tc.end_time,
|
||||
tc.start_frame,
|
||||
tc.end_frame,
|
||||
fps,
|
||||
serde_json::json!({"interval": 10.0}),
|
||||
)
|
||||
@@ -2107,12 +2103,13 @@ async fn main() -> Result<()> {
|
||||
println!("\n=== Scene {} ===", i + 1);
|
||||
println!(
|
||||
"Time: {:.2}s - {:.2}s",
|
||||
story_chunk.start_time, story_chunk.end_time
|
||||
story_chunk.start_time().seconds(),
|
||||
story_chunk.end_time().seconds()
|
||||
);
|
||||
|
||||
// Get context: expand time range by 5 seconds before and after
|
||||
let context_start = (story_chunk.start_time - 5.0).max(0.0);
|
||||
let context_end = (story_chunk.end_time + 5.0).min(duration);
|
||||
let context_start = (story_chunk.start_time().seconds() - 5.0).max(0.0);
|
||||
let context_end = (story_chunk.end_time().seconds() + 5.0).min(duration);
|
||||
|
||||
// Get chunks in context range (sentence chunks with ASR text)
|
||||
let context_chunks = db
|
||||
@@ -2129,8 +2126,8 @@ async fn main() -> Result<()> {
|
||||
story.push_str(&format!(
|
||||
"Scene {} ({:.1}s - {:.1}s)\n\n",
|
||||
i + 1,
|
||||
story_chunk.start_time,
|
||||
story_chunk.end_time
|
||||
story_chunk.start_time().seconds(),
|
||||
story_chunk.end_time().seconds()
|
||||
));
|
||||
|
||||
// Add audio/text content
|
||||
@@ -2280,8 +2277,8 @@ async fn main() -> Result<()> {
|
||||
uuid: chunk.uuid.clone(),
|
||||
chunk_id: chunk.chunk_id.clone(),
|
||||
chunk_type: "sentence".to_string(),
|
||||
start_time: chunk.start_time,
|
||||
end_time: chunk.end_time,
|
||||
start_time: chunk.start_time().seconds(),
|
||||
end_time: chunk.end_time().seconds(),
|
||||
text: Some(text.to_string()),
|
||||
};
|
||||
if let Err(e) = qdrant
|
||||
@@ -2408,13 +2405,16 @@ async fn main() -> Result<()> {
|
||||
} => {
|
||||
use momentry_core::worker::{JobWorker, WorkerConfig};
|
||||
|
||||
let config = WorkerConfig {
|
||||
max_concurrent: max_concurrent.unwrap_or(2),
|
||||
poll_interval_secs: poll_interval.unwrap_or(5),
|
||||
enabled: true,
|
||||
batch_size: batch_size.unwrap_or(10),
|
||||
processor_timeout_secs: 3600,
|
||||
};
|
||||
let mut config = WorkerConfig::default();
|
||||
if let Some(max) = max_concurrent {
|
||||
config.max_concurrent = max;
|
||||
}
|
||||
if let Some(interval) = poll_interval {
|
||||
config.poll_interval_secs = interval;
|
||||
}
|
||||
if let Some(batch) = batch_size {
|
||||
config.batch_size = batch;
|
||||
}
|
||||
|
||||
let db = PostgresDb::init().await?;
|
||||
let redis = RedisClient::new()?;
|
||||
|
||||
Reference in New Issue
Block a user