mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-24 10:16:56 +00:00
refactor(workflow): throw non-retryable ApplicationFailure for validation errors
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { ApplicationFailure } from '@temporalio/workflow'
|
||||
import type { WorkflowTask } from '@/generated/prisma/client'
|
||||
import {
|
||||
getActivities,
|
||||
@@ -50,7 +51,7 @@ export async function agentAutofillMedia(task: WorkflowTask): Promise<void> {
|
||||
const asset = await executeActivity(TaskQueueDb, getAssetActivity, task.assetId)
|
||||
const key = asset?.storageKey?.key
|
||||
if (!asset || !asset.project || !key) {
|
||||
throw new Error('Asset or project not found')
|
||||
throw ApplicationFailure.create({ message: 'Asset or project not found', nonRetryable: true })
|
||||
}
|
||||
const teamId = asset.project.teamId
|
||||
const projectId = asset.project.id
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { ApplicationFailure } from '@temporalio/workflow'
|
||||
import type { WorkflowTask } from '@/generated/prisma/client'
|
||||
import {
|
||||
executeActivity,
|
||||
@@ -31,18 +32,29 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
|
||||
})
|
||||
|
||||
const payload = task.payload
|
||||
if (!payload) throw new Error('Task payload is missing')
|
||||
if (!payload) {
|
||||
throw ApplicationFailure.create({ message: 'Task payload is missing', nonRetryable: true })
|
||||
}
|
||||
|
||||
const agentId = payload.agent?.agentId
|
||||
if (!agentId) throw new Error('agentId missing in payload')
|
||||
if (!agentId) {
|
||||
throw ApplicationFailure.create({ message: 'agentId missing in payload', nonRetryable: true })
|
||||
}
|
||||
|
||||
let sessionId = payload.agent?.sessionId
|
||||
|
||||
// 1. Get User Comment
|
||||
const userCommentId = payload.agent?.userCommentId
|
||||
if (!userCommentId) throw new Error('userCommentId missing in payload')
|
||||
if (!userCommentId) {
|
||||
throw ApplicationFailure.create({
|
||||
message: 'userCommentId missing in payload',
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
const userComment = await executeActivity(TaskQueueDb, getCommentActivity, userCommentId)
|
||||
if (!userComment) throw new Error('User comment not found')
|
||||
if (!userComment) {
|
||||
throw ApplicationFailure.create({ message: 'User comment not found', nonRetryable: true })
|
||||
}
|
||||
|
||||
// 2. Create Placeholder Comment
|
||||
const placeholder = await executeActivity(TaskQueueDb, createCommentActivity, {
|
||||
@@ -57,7 +69,7 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
|
||||
// 3. Get Asset
|
||||
const asset = await executeActivity(TaskQueueDb, getAssetActivity, task.assetId)
|
||||
if (!asset || !asset.project) {
|
||||
throw new Error('Asset or project not found')
|
||||
throw ApplicationFailure.create({ message: 'Asset or project not found', nonRetryable: true })
|
||||
}
|
||||
const teamId = asset.project.teamId
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { ApplicationFailure } from '@temporalio/workflow'
|
||||
import type { WorkflowTask } from '@/generated/prisma/client'
|
||||
import { getActivities, executeActivity, TaskQueueDb, TaskQueueAgent } from '../workflow-utils'
|
||||
|
||||
@@ -32,7 +33,9 @@ export async function agentEmbeddingMedia(task: WorkflowTask): Promise<void> {
|
||||
})
|
||||
placeholderCommentId = placeholder.id
|
||||
|
||||
if (!task.teamId) throw new Error('Task has no teamId')
|
||||
if (!task.teamId) {
|
||||
throw ApplicationFailure.create({ message: 'Task has no teamId', nonRetryable: true })
|
||||
}
|
||||
|
||||
// 1. Fetch Agent Context (Database Activity on db_queue)
|
||||
const context = await executeActivity(TaskQueueDb, getEmbeddingContextActivity, {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { ApplicationFailure } from '@temporalio/workflow'
|
||||
import type { WorkflowTask } from '@/generated/prisma/client'
|
||||
import {
|
||||
getActivities,
|
||||
@@ -44,7 +45,7 @@ export async function aiTranscriptionMedia(task: WorkflowTask): Promise<void> {
|
||||
const asset = await executeActivity(TaskQueueDb, getAssetActivity, task.assetId)
|
||||
const key = asset?.storageKey?.key
|
||||
if (!asset || !key) {
|
||||
throw new Error('Asset not found')
|
||||
throw ApplicationFailure.create({ message: 'Asset not found', nonRetryable: true })
|
||||
}
|
||||
|
||||
// 2. Extract Audio (Requires FFmpeg)
|
||||
|
||||
Reference in New Issue
Block a user