feat(workflow): integrate temporal workflow bundles and support dev/prod mode

This commit is contained in:
yiling
2026-06-03 09:10:31 +08:00
parent 925e90cd1c
commit 35cfe68280
13 changed files with 103 additions and 36 deletions
@@ -9,7 +9,9 @@ export async function getAgentWorkerQueueActivity(): Promise<string> {
return 'agent_queue'
}
export async function getAssetStatusActivity(params: { assetId: string }): Promise<AssetStatus | null> {
export async function getAssetStatusActivity(params: {
assetId: string
}): Promise<AssetStatus | null> {
const asset = await prisma.asset.findUnique({
where: { id: params.assetId },
select: { status: true },
+40 -3
View File
@@ -1,8 +1,8 @@
import { WorkflowTask } from '@shumai/db'
import { prisma, registerWorkflowTrigger, WorkflowTask } from '@shumai/db'
import path from 'path'
import { Executor } from './executor'
import { LocalExecutor } from './local-executor'
import { TemporalExecutor } from './temporal-executor'
import { prisma, registerWorkflowTrigger } from '@shumai/db'
export class WorkflowService {
private executor: Executor
@@ -56,7 +56,10 @@ export class WorkflowService {
}
// Starts Temporal workers for specific task queues
async startWorkers(queue: string): Promise<void> {
async startWorkers(
queue: string,
options: { workflowBundle?: unknown; workflowsPath?: string } = {},
): Promise<void> {
const type = process.env.WORKFLOW_EXECUTOR || 'local'
if (type === 'temporal') {
const { Worker, NativeConnection } = await import('@temporalio/worker')
@@ -85,10 +88,31 @@ export class WorkflowService {
sharedActivities.getTranscodeWorkerQueueActivity = async () => workerSpecificQueue
}
const { workflowBundle, workflowsPath } = options
const sharedWorker = await Worker.create({
connection,
// The workflowBundle is a pre-bundled set of workflows, its internal structure
// is managed by the Temporal worker and doesn't need explicit typing here.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...(workflowBundle ? { workflowBundle: workflowBundle as any } : {}),
...(workflowsPath ? { workflowsPath } : {}),
activities: sharedActivities,
taskQueue: queue,
bundlerOptions: {
webpackConfigHook: (config) => {
config.resolve = config.resolve || {}
config.resolve.alias = {
...config.resolve.alias,
// Find the exact absolute path to the package directory
'@temporalio/workflow': path.dirname(
require.resolve('@temporalio/workflow/package.json'),
),
}
return config
},
},
})
const specificWorker = await Worker.create({
@@ -96,6 +120,19 @@ export class WorkflowService {
// No workflows needed for the unique queue
activities,
taskQueue: workerSpecificQueue,
bundlerOptions: {
webpackConfigHook: (config) => {
config.resolve = config.resolve || {}
config.resolve.alias = {
...config.resolve.alias,
// Find the exact absolute path to the package directory
'@temporalio/workflow': path.dirname(
require.resolve('@temporalio/workflow/package.json'),
),
}
return config
},
},
})
await Promise.all([sharedWorker.run(), specificWorker.run()])