Improve job status notifications
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { runTaskProcessor } from '@/lib/server/task-processors';
|
||||
import { runTaskProcessor, type TaskExecutionOutcome } from '@/lib/server/task-processors';
|
||||
import {
|
||||
completeTask,
|
||||
getTaskById,
|
||||
@@ -23,14 +23,14 @@ export async function runTaskWorkflow(taskId: string) {
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await processTaskStep(refreshedTask);
|
||||
await completeTaskStep(task.id, result);
|
||||
const outcome = await processTaskStep(refreshedTask);
|
||||
await completeTaskStep(task.id, outcome);
|
||||
} catch (error) {
|
||||
const reason = error instanceof Error
|
||||
? error.message
|
||||
: 'Task failed unexpectedly';
|
||||
|
||||
await markTaskFailureStep(task.id, reason);
|
||||
const latestTask = await loadTaskStep(task.id);
|
||||
await markTaskFailureStep(task.id, reason, latestTask);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -52,15 +52,21 @@ async function processTaskStep(task: Task) {
|
||||
|
||||
// Keep retries at the projection workflow level to avoid duplicate side effects.
|
||||
(
|
||||
processTaskStep as ((task: Task) => Promise<Record<string, unknown>>) & { maxRetries?: number }
|
||||
processTaskStep as ((task: Task) => Promise<TaskExecutionOutcome>) & { maxRetries?: number }
|
||||
).maxRetries = 0;
|
||||
|
||||
async function completeTaskStep(taskId: string, result: Record<string, unknown>) {
|
||||
async function completeTaskStep(taskId: string, outcome: TaskExecutionOutcome) {
|
||||
'use step';
|
||||
await completeTask(taskId, result);
|
||||
await completeTask(taskId, outcome.result, {
|
||||
detail: outcome.completionDetail,
|
||||
context: outcome.completionContext ?? null
|
||||
});
|
||||
}
|
||||
|
||||
async function markTaskFailureStep(taskId: string, reason: string) {
|
||||
async function markTaskFailureStep(taskId: string, reason: string, latestTask: Task | null) {
|
||||
'use step';
|
||||
await markTaskFailure(taskId, reason);
|
||||
await markTaskFailure(taskId, reason, 'failed', {
|
||||
detail: reason,
|
||||
context: latestTask?.stage_context ?? null
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user