Improve job status notifications
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
||||
setTaskWorkflowRunId,
|
||||
updateTaskNotificationState
|
||||
} from '@/lib/server/repos/tasks';
|
||||
import { buildTaskNotification } from '@/lib/server/task-notifications';
|
||||
|
||||
type EnqueueTaskInput = {
|
||||
userId: string;
|
||||
@@ -72,15 +73,21 @@ async function reconcileTaskWithWorkflow(task: Task) {
|
||||
|
||||
const updated = await setTaskStatusFromWorkflow(task.id, nextStatus, nextError);
|
||||
|
||||
return updated ?? {
|
||||
const fallbackTask = {
|
||||
...task,
|
||||
status: nextStatus,
|
||||
stage: nextStatus,
|
||||
stage_detail: null,
|
||||
stage_detail: nextStatus === 'failed' ? nextError : 'Workflow run completed.',
|
||||
stage_context: null,
|
||||
error: nextError,
|
||||
finished_at: nextStatus === 'queued' || nextStatus === 'running'
|
||||
? null
|
||||
: task.finished_at ?? new Date().toISOString()
|
||||
} satisfies Omit<Task, 'notification'>;
|
||||
|
||||
return updated ?? {
|
||||
...fallbackTask,
|
||||
notification: buildTaskNotification(fallbackTask)
|
||||
};
|
||||
} catch {
|
||||
return task;
|
||||
|
||||
Reference in New Issue
Block a user