mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-25 14:38:21 +00:00
feat(deploy): implement KEDA ScaledJob and scale-to-zero On-Demand transcoding
This commit is contained in:
@@ -14,14 +14,26 @@ async function run() {
|
||||
// Initialize workflows and activities
|
||||
initTranscodeWorkflows()
|
||||
|
||||
console.log('🚀 Starting Transcode Worker...')
|
||||
const isOnce = process.argv.includes('--once') || process.env.SHUMAI_WORKER_ONCE === 'true'
|
||||
if (isOnce) {
|
||||
workflowService.getExecutor().setOnceMode(true)
|
||||
console.log('🚀 Starting Transcode Worker in --once mode (single-task execution)...')
|
||||
} else {
|
||||
console.log('🚀 Starting Transcode Worker...')
|
||||
}
|
||||
|
||||
await workflowService.startWorkers(TaskQueueTranscode)
|
||||
|
||||
let isShuttingDown = false
|
||||
let idleTimer: Timer | null = null
|
||||
|
||||
const shutdown = async () => {
|
||||
if (isShuttingDown) return
|
||||
isShuttingDown = true
|
||||
if (idleTimer) {
|
||||
clearTimeout(idleTimer)
|
||||
idleTimer = null
|
||||
}
|
||||
console.log('Shutting down Transcode Worker gracefully...')
|
||||
try {
|
||||
await workflowService.shutdownWorkers()
|
||||
@@ -31,6 +43,32 @@ async function run() {
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
if (isOnce) {
|
||||
const idleTimeoutMs = process.env.SHUMAI_WORKER_IDLE_TIMEOUT_MS
|
||||
? parseInt(process.env.SHUMAI_WORKER_IDLE_TIMEOUT_MS, 10)
|
||||
: 15_000
|
||||
|
||||
idleTimer = setTimeout(async () => {
|
||||
console.log(
|
||||
`[Transcode Worker] No tasks received within idle timeout (${idleTimeoutMs / 1000}s), shutting down.`,
|
||||
)
|
||||
await shutdown()
|
||||
}, idleTimeoutMs)
|
||||
|
||||
workflowService.getExecutor().on('workflowStarted', (task) => {
|
||||
console.log(`[Transcode Worker] Claimed task ${task.id}, cancelling idle timer.`)
|
||||
if (idleTimer) {
|
||||
clearTimeout(idleTimer)
|
||||
idleTimer = null
|
||||
}
|
||||
})
|
||||
|
||||
workflowService.getExecutor().on('workflowFinished', async ({ taskId }) => {
|
||||
console.log(`[Transcode Worker] Completed task ${taskId} in --once mode, shutting down.`)
|
||||
await shutdown()
|
||||
})
|
||||
}
|
||||
|
||||
process.on('SIGINT', shutdown)
|
||||
process.on('SIGTERM', shutdown)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user