mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 18:07:13 +00:00
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:
@@ -23,15 +23,23 @@ import {
|
||||
isOfficeDocument,
|
||||
} from '@shumai/core/src/utils/mime'
|
||||
import { logger } from '@shumai/core/src/logger'
|
||||
import { ApplicationFailure, Context } from '@temporalio/activity'
|
||||
import { getLocalTaskAbortSignal } from '@shumai/workflow-core'
|
||||
import { ApplicationFailure, getLocalTaskAbortSignal } from '@shumai/workflow-core'
|
||||
|
||||
function getActivityCancellationSignal(taskId?: string): AbortSignal | undefined {
|
||||
try {
|
||||
return Context.current().cancellationSignal
|
||||
} catch {
|
||||
return getLocalTaskAbortSignal(taskId)
|
||||
return getLocalTaskAbortSignal(taskId)
|
||||
}
|
||||
|
||||
export async function ensureLocalMediaFile(assetKey: string, filePath: string): Promise<string> {
|
||||
if (fs.existsSync(filePath)) {
|
||||
return filePath
|
||||
}
|
||||
const dir = path.dirname(filePath)
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir, { recursive: true })
|
||||
}
|
||||
const bucket = process.env.S3_BUCKET || 'shumai'
|
||||
await s3Service.downloadToFile(bucket, assetKey, filePath)
|
||||
return filePath
|
||||
}
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
@@ -367,6 +375,7 @@ export async function transcodeVideoActivity(
|
||||
// Not found
|
||||
}
|
||||
|
||||
await ensureLocalMediaFile(params.assetKey, params.filePath)
|
||||
const tmpDir = path.dirname(params.filePath)
|
||||
const outputFile = path.join(tmpDir, `${stem}-${suffix}.mp4`)
|
||||
|
||||
@@ -489,6 +498,7 @@ export async function transcodeHlsActivity(params: HlsActivityParams): Promise<P
|
||||
})
|
||||
}
|
||||
|
||||
await ensureLocalMediaFile(params.assetKey, params.filePath)
|
||||
const hlsTmpDir = path.join(path.dirname(params.filePath), `hls-${ulid()}`)
|
||||
|
||||
try {
|
||||
@@ -670,6 +680,7 @@ export async function transcodeAudioActivity(
|
||||
// Not found
|
||||
}
|
||||
|
||||
await ensureLocalMediaFile(params.assetKey, params.filePath)
|
||||
const tmpDir = path.dirname(params.filePath)
|
||||
const outputFile = path.join(tmpDir, `${stem}-audio-proxy.mp4`)
|
||||
|
||||
@@ -750,6 +761,7 @@ export async function transcodeImageActivity(
|
||||
// Not found
|
||||
}
|
||||
|
||||
await ensureLocalMediaFile(params.assetKey, params.filePath)
|
||||
const tmpDir = path.dirname(params.filePath)
|
||||
const outputFile = path.join(tmpDir, `${stem}-${params.imageSpec.width}p.webp`)
|
||||
|
||||
@@ -824,6 +836,7 @@ export async function generateSpriteActivity(params: GenerateSpriteActivityParam
|
||||
// Not found
|
||||
}
|
||||
|
||||
await ensureLocalMediaFile(params.assetKey, params.filePath)
|
||||
const tmpDir = path.dirname(params.filePath)
|
||||
const spriteFile = path.join(tmpDir, 'sprite.webp')
|
||||
const posterFile = path.join(tmpDir, 'poster.webp')
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
import { watermarkService } from '@shumai/core/src/watermark/watermark'
|
||||
import { logger } from '@shumai/core/src/logger'
|
||||
import { stemFromKey } from '@shumai/core/src/utils/filename'
|
||||
import { ApplicationFailure } from '@temporalio/activity'
|
||||
import { ApplicationFailure } from '@shumai/workflow-core'
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
import { ulid } from 'ulid'
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
import type { WorkflowTask } from '@shumai/db'
|
||||
import { executeActivity, getActivities, TaskQueueTranscode } from '@shumai/workflow-core'
|
||||
import { ApplicationFailure } from '@temporalio/workflow'
|
||||
import {
|
||||
ApplicationFailure,
|
||||
executeActivity,
|
||||
getActivities,
|
||||
TaskQueueTranscode,
|
||||
} from '@shumai/workflow-core'
|
||||
|
||||
export async function getWorkerQueueAndStartTask(task: WorkflowTask): Promise<string> {
|
||||
const { getTranscodeWorkerQueueActivity, updateTaskStatusActivity } = getActivities()
|
||||
const workerQueue = await executeActivity(TaskQueueTranscode, getTranscodeWorkerQueueActivity)
|
||||
await executeActivity(workerQueue, updateTaskStatusActivity, {
|
||||
const { updateTaskStatusActivity } = getActivities()
|
||||
await executeActivity(TaskQueueTranscode, updateTaskStatusActivity, {
|
||||
taskId: task.id,
|
||||
status: 'processing',
|
||||
})
|
||||
return workerQueue
|
||||
return TaskQueueTranscode
|
||||
}
|
||||
|
||||
export async function fetchAssetWithKey(workerQueue: string, assetId: string) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { WorkflowTask } from '@shumai/db'
|
||||
import '@shumai/db/src/prisma-json-types'
|
||||
import { executeActivity, getActivities } from '@shumai/workflow-core'
|
||||
import { ApplicationFailure } from '@temporalio/workflow'
|
||||
import { executeActivity, getActivities, ApplicationFailure } from '@shumai/workflow-core'
|
||||
import { getWorkerQueueAndStartTask, completeTask, failTask } from './common'
|
||||
|
||||
export async function overlayImageAnnotationWorkflow(task: WorkflowTask): Promise<void> {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { WorkflowTask } from '@shumai/db'
|
||||
import { executeActivity, getActivities } from '@shumai/workflow-core'
|
||||
import { ApplicationFailure } from '@temporalio/workflow'
|
||||
import { executeActivity, getActivities, ApplicationFailure } from '@shumai/workflow-core'
|
||||
import { getWorkerQueueAndStartTask, fetchAssetWithKey, completeTask, failTask } from './common'
|
||||
|
||||
export async function renderPdfPagesWorkflow(task: WorkflowTask): Promise<void> {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { WorkflowTask } from '@shumai/db'
|
||||
import { executeActivity, getActivities } from '@shumai/workflow-core'
|
||||
import { ApplicationFailure } from '@temporalio/workflow'
|
||||
import { executeActivity, getActivities, ApplicationFailure } from '@shumai/workflow-core'
|
||||
import { getWorkerQueueAndStartTask, fetchAssetWithKey, completeTask, failTask } from './common'
|
||||
|
||||
export async function takeVideoScreenshotsWorkflow(task: WorkflowTask): Promise<void> {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { WorkflowTask } from '@shumai/db'
|
||||
import '@shumai/db/src/prisma-json-types'
|
||||
import { executeActivity, getActivities } from '@shumai/workflow-core'
|
||||
import { ApplicationFailure } from '@temporalio/workflow'
|
||||
import { executeActivity, getActivities, ApplicationFailure } from '@shumai/workflow-core'
|
||||
import { getWorkerQueueAndStartTask, completeTask, failTask } from './common'
|
||||
|
||||
export async function transcodeWatermarkWorkflow(task: WorkflowTask): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user