feat(workflow): migrate workflow engine from temporal to dbos

Replace Temporal and LocalExecutor with DBOS Transact (@dbos-inc/dbos-sdk) as the unified workflow engine. Background tasks, media transcoding, and AI agent workflows now execute with durable steps and task queues directly against PostgreSQL, eliminating the need for an external Temporal cluster and separate polling executors.
This commit is contained in:
yiling
2026-10-17 15:50:17 +08:00
parent f7ed3bafdf
commit 97af81d157
65 changed files with 4397 additions and 5933 deletions
+75 -97
View File
@@ -9,118 +9,96 @@ import * as path from 'path'
import * as fs from 'fs'
const currentDir = path.dirname(fileURLToPath(import.meta.url))
const transcodeWorkflowsPath = path.resolve(currentDir, '../../../apps/transcode/src/workflows.ts')
const fixturesDir = path.resolve(currentDir, '../fixtures')
describe.each(['local', 'temporal'] as const)(
'Workflow E2E - renderPdfPagesWorkflow (executor: %s)',
(mode) => {
setupTestDbHooks()
describe('Workflow E2E - renderPdfPagesWorkflow', () => {
setupTestDbHooks()
let transcodeWorkerPromise: Promise<void> | null = null
beforeAll(async () => {
process.env.S3_BUCKET = 'shumai-e2e-test-bucket-transcode'
initTranscodeWorkflows()
await workflowService.startWorkers(TaskQueueTranscode)
})
beforeAll(async () => {
process.env.S3_BUCKET = 'shumai-e2e-test-bucket-transcode'
afterAll(async () => {
await workflowService.shutdownWorkers()
workflowService.close()
vi.restoreAllMocks()
try {
console.log('Cleaning up local E2E storage files...')
await s3Service.deletePrefix('shumai-e2e-test-bucket-transcode', '')
} catch (err) {
console.error('Failed to clean up E2E storage folder:', err)
}
})
workflowService.setExecutorType(mode)
initTranscodeWorkflows()
if (mode === 'temporal') {
console.log('Starting background worker for transcode Temporal E2E tests...')
transcodeWorkerPromise = workflowService.startWorkers(TaskQueueTranscode, {
workflowsPath: transcodeWorkflowsPath,
})
await new Promise((resolve) => setTimeout(resolve, 2000))
} else {
console.log('Starting local workflow service polling...')
workflowService.start()
}
it('should run renderPdfPages workflow for a PDF asset successfully', async () => {
// 1. Seed Database
const team = await prisma.team.create({
data: { name: 'E2E PDF Pages Team' },
})
afterAll(async () => {
if (mode === 'temporal') {
console.log('Shutting down Temporal workers...')
await workflowService.shutdownWorkers()
await Promise.all([transcodeWorkerPromise].filter(Boolean))
}
workflowService.close()
vi.restoreAllMocks()
try {
console.log('Cleaning up local E2E storage files...')
await s3Service.deletePrefix('shumai-e2e-test-bucket-transcode', '')
} catch (err) {
console.error('Failed to clean up E2E storage folder:', err)
}
const project = await prisma.project.create({
data: { name: 'E2E PDF Pages Project', teamId: team.id },
})
it('should run renderPdfPages workflow for a PDF asset successfully', async () => {
// 1. Seed Database
const team = await prisma.team.create({
data: { name: 'E2E PDF Pages Team' },
})
const storageKey = await prisma.storageKey.create({
data: {
key: 'projects/e2e/test-pages.pdf',
},
})
const project = await prisma.project.create({
data: { name: 'E2E PDF Pages Project', teamId: team.id },
})
const asset = await prisma.asset.create({
data: {
name: 'test-pages.pdf',
type: 'file',
status: 'uploaded',
mediaType: 'application/pdf',
projectId: project.id,
storageKeyId: storageKey.id,
},
})
const storageKey = await prisma.storageKey.create({
data: {
key: 'projects/e2e/test-pages.pdf',
},
})
// 2. Seed S3 Storage from fixture test.pdf
const pdfPath = path.join(fixturesDir, 'test.pdf')
const pdfBuffer = fs.readFileSync(pdfPath)
await s3Service.putObject(
'shumai-e2e-test-bucket-transcode',
'projects/e2e/test-pages.pdf',
pdfBuffer,
pdfBuffer.length,
'application/pdf',
)
const asset = await prisma.asset.create({
data: {
name: 'test-pages.pdf',
type: 'file',
status: 'uploaded',
mediaType: 'application/pdf',
// 3. Create Workflow Task
const task = await prisma.workflowTask.create({
data: {
type: 'transcode_pdf_pages',
status: 'pending',
assetId: asset.id,
projectId: project.id,
teamId: team.id,
payload: {
projectId: project.id,
storageKeyId: storageKey.id,
},
})
// 2. Seed S3 Storage from fixture test.pdf
const pdfPath = path.join(fixturesDir, 'test.pdf')
const pdfBuffer = fs.readFileSync(pdfPath)
await s3Service.putObject(
'shumai-e2e-test-bucket-transcode',
'projects/e2e/test-pages.pdf',
pdfBuffer,
pdfBuffer.length,
'application/pdf',
)
// 3. Create Workflow Task
const task = await prisma.workflowTask.create({
data: {
type: 'transcode_pdf_pages',
status: 'pending',
assetId: asset.id,
projectId: project.id,
teamId: team.id,
payload: {
projectId: project.id,
pdfPages: {
start: 1,
end: 2,
},
pdfPages: {
start: 1,
end: 2,
},
},
})
},
})
// 4. Wait for workflow to complete
console.log(`Submitted E2E PDF Pages Workflow Task. ID: ${task.id}. Awaiting completion...`)
const completedTask = await workflowService.executeWait(task, 45000)
// 4. Wait for workflow to complete
console.log(`Submitted E2E PDF Pages Workflow Task. ID: ${task.id}. Awaiting completion...`)
const completedTask = await workflowService.executeWait(task, 45000)
// 5. Verification
expect(completedTask.status).toBe('completed')
// 5. Verification
expect(completedTask.status).toBe('completed')
// Verify output contains rendered pages
const output = completedTask.output as unknown as { pages: { key: string; page: number }[] }
expect(output).toBeDefined()
expect(output.pages).toBeDefined()
expect(output.pages.length).toBeGreaterThan(0)
}, 50000)
},
)
// Verify output contains rendered pages
const output = completedTask.output as unknown as { pages: { key: string; page: number }[] }
expect(output).toBeDefined()
expect(output.pages).toBeDefined()
expect(output.pages.length).toBeGreaterThan(0)
}, 50000)
})