mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-29 04:14:30 +00:00
refactor(monorepo): decouple and split background workflow workers into packages
Splits monolithic workflow workers into four decoupled workspaces under the Bun workspaces monorepo: - @shumai/workflow-core containing the core execution engine and utilities. - @shumai/agent containing agent-specific logic, workflows, and activities. - @shumai/transcode containing transcoding workflows, transcoder, and transcode activities. - @shumai/worker-db containing database activities. Introduces a dynamic workflow and activity registration pattern on LocalExecutor to eliminate circular dependencies. Updates worker bootstrapping and test suites to cleanly leverage generic workspace modules.
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { prisma } from '@shumai/db'
|
||||
import { setupTestDbHooks } from '@shumai/db'
|
||||
import {
|
||||
updateTaskStatusActivity,
|
||||
updateAssetStatusActivity,
|
||||
updateTaskUsageActivity,
|
||||
} from '@shumai/worker-db'
|
||||
import { WorkflowTaskStatus, WorkflowTaskType, AssetStatus } from '@shumai/db'
|
||||
|
||||
describe('Task Activities', () => {
|
||||
setupTestDbHooks()
|
||||
|
||||
it('should update task status', async () => {
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
assetId: 'asset-1',
|
||||
type: WorkflowTaskType.ai_embedding,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
},
|
||||
})
|
||||
|
||||
await updateTaskStatusActivity({
|
||||
taskId: task.id,
|
||||
status: WorkflowTaskStatus.processing,
|
||||
})
|
||||
|
||||
const updated = await prisma.workflowTask.findUnique({ where: { id: task.id } })
|
||||
expect(updated?.status).toBe(WorkflowTaskStatus.processing)
|
||||
})
|
||||
|
||||
it('should update asset status', async () => {
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'test.mp4',
|
||||
storageKey: { create: { key: 'test.mp4' } },
|
||||
status: 'uploaded',
|
||||
type: 'file',
|
||||
},
|
||||
})
|
||||
|
||||
await updateAssetStatusActivity({
|
||||
assetId: asset.id,
|
||||
status: AssetStatus.processing,
|
||||
})
|
||||
|
||||
const updated = await prisma.asset.findUnique({ where: { id: asset.id } })
|
||||
expect(updated?.status).toBe(AssetStatus.processing)
|
||||
})
|
||||
|
||||
it('should update task usage', async () => {
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
assetId: 'asset-1',
|
||||
type: WorkflowTaskType.ai_embedding,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
},
|
||||
})
|
||||
|
||||
await updateTaskUsageActivity({
|
||||
taskId: task.id,
|
||||
inputTokens: 100,
|
||||
outputTokens: 200,
|
||||
model: 'gpt-4o',
|
||||
})
|
||||
|
||||
const updated = await prisma.workflowTask.findUnique({ where: { id: task.id } })
|
||||
expect(updated?.inputTokens).toBe(100)
|
||||
expect(updated?.outputTokens).toBe(200)
|
||||
expect(updated?.model).toBe('gpt-4o')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,7 @@
|
||||
export async function getTranscodeWorkerQueueActivity(): Promise<string> {
|
||||
return 'transcode_queue'
|
||||
}
|
||||
|
||||
export async function getAgentWorkerQueueActivity(): Promise<string> {
|
||||
return 'agent_queue'
|
||||
}
|
||||
Reference in New Issue
Block a user