MCPcopy Create free account
hub / github.com/acking-you/static_flow / process_one_task

Function process_one_task

crates/backend/src/comment_worker.rs:178–359  ·  view source on GitHub ↗
(
    store: Arc<CommentDataStore>,
    config: CommentAiWorkerConfig,
    task_id: &str,
)

Source from the content-addressed store, hash-verified

176}
177
178async fn process_one_task(
179 store: Arc<CommentDataStore>,
180 config: CommentAiWorkerConfig,
181 task_id: &str,
182) -> Result<()> {
183 let mut task = match store.get_comment_task(task_id).await? {
184 Some(task) => task,
185 None => {
186 tracing::warn!("comment worker skipped missing task {task_id}");
187 return Ok(());
188 },
189 };
190
191 if task.status == COMMENT_STATUS_REJECTED || task.status == COMMENT_STATUS_DONE {
192 tracing::info!("comment worker skipped finalized task {task_id}");
193 return Ok(());
194 }
195
196 if task.status == COMMENT_STATUS_APPROVED {
197 let transitioned = store
198 .transition_comment_task(task_id, COMMENT_STATUS_RUNNING, None, None, true)
199 .await?;
200 if let Some(updated) = transitioned {
201 task = updated;
202 }
203 } else if task.status != COMMENT_STATUS_RUNNING {
204 tracing::warn!("comment worker skipped task {} with status {}", task.task_id, task.status);
205 return Ok(());
206 }
207
208 let run_id = generate_ai_run_id(&task.task_id);
209 let run_created = store
210 .create_ai_run(NewCommentAiRunInput {
211 run_id: run_id.clone(),
212 task_id: task.task_id.clone(),
213 runner_program: config.runner_program.clone(),
214 runner_args_json: serde_json::to_string(&config.runner_args).unwrap_or_default(),
215 skill_path: config.skill_path.display().to_string(),
216 })
217 .await;
218 if let Err(err) = run_created {
219 let reason = format!("failed to create comment ai run record: {err}");
220 mark_task_failed(store.as_ref(), task_id, reason).await;
221 return Ok(());
222 }
223
224 let run_output = match run_ai_runner(store.clone(), &config, &task, &run_id).await {
225 Ok(output) => output,
226 Err(err) => {
227 let reason = err.to_string();
228 let _ = store
229 .finalize_ai_run(
230 &run_id,
231 COMMENT_AI_RUN_STATUS_FAILED,
232 None,
233 Some(reason.clone()),
234 None,
235 )

Callers 1

spawn_comment_workerFunction · 0.85

Calls 13

generate_ai_run_idFunction · 0.85
mark_task_failedFunction · 0.85
run_ai_runnerFunction · 0.85
inspect_runner_outputFunction · 0.85
derive_author_identityFunction · 0.85
get_comment_taskMethod · 0.80
cloneMethod · 0.80
summaryMethod · 0.80
create_ai_runMethod · 0.45

Tested by

no test coverage detected