mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-30 12:54:55 +00:00
fix(transcode): make deterministic transcode activity failures non-retryable in Temporal
This commit is contained in:
@@ -1,6 +1,27 @@
|
||||
import { describe, it, expect, vi, beforeAll } from 'vitest'
|
||||
import { describe, it, expect, vi, beforeAll, afterAll } from 'vitest'
|
||||
import * as wf from '@temporalio/workflow'
|
||||
import { getActivities, executeActivity } from './workflow-utils'
|
||||
|
||||
const mockWorkflowInfo = vi.fn().mockImplementation(() => {
|
||||
throw new Error('Not in workflow context')
|
||||
})
|
||||
const mockProxyActivities = vi.fn()
|
||||
|
||||
vi.mock('@temporalio/workflow', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('@temporalio/workflow')>()
|
||||
return {
|
||||
...actual,
|
||||
workflowInfo: () => mockWorkflowInfo(),
|
||||
proxyActivities: (...args: unknown[]) => mockProxyActivities(...args),
|
||||
log: {
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
error: vi.fn(),
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
describe('workflow-utils executeActivity', () => {
|
||||
beforeAll(() => {
|
||||
// Inject mock activities for local execution tests
|
||||
@@ -39,4 +60,37 @@ describe('workflow-utils executeActivity', () => {
|
||||
'executeActivity must be called with an activity function obtained from getActivities()',
|
||||
)
|
||||
})
|
||||
|
||||
describe('Temporal mode', () => {
|
||||
beforeAll(() => {
|
||||
// Mock workflowInfo to simulate running in Temporal by returning a fake object
|
||||
mockWorkflowInfo.mockReturnValue({} as unknown as wf.WorkflowInfo)
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
mockWorkflowInfo.mockImplementation(() => {
|
||||
throw new Error('Not in workflow context')
|
||||
})
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('should configure proxyActivities with retry options', async () => {
|
||||
mockProxyActivities.mockReturnValue({
|
||||
mockActivity: vi.fn().mockResolvedValue('temporal-success'),
|
||||
})
|
||||
|
||||
const { mockActivity } = getActivities()
|
||||
const result = await executeActivity('test-queue', mockActivity, 'arg1')
|
||||
|
||||
expect(mockProxyActivities).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
retry: {
|
||||
maximumAttempts: 5,
|
||||
initialInterval: '10s',
|
||||
},
|
||||
}),
|
||||
)
|
||||
expect(result).toBe('temporal-success')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -71,6 +71,10 @@ export function getActivities<T = any>(): T {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
baseProxy = wf.proxyActivities<any>({
|
||||
startToCloseTimeout: '10 minutes',
|
||||
retry: {
|
||||
maximumAttempts: 5,
|
||||
initialInterval: '10s',
|
||||
},
|
||||
})
|
||||
} else {
|
||||
baseProxy = localActivitiesProxy()
|
||||
@@ -163,6 +167,10 @@ export async function executeActivity(
|
||||
const handle = wf.proxyActivities<any>({
|
||||
startToCloseTimeout: '10 minutes',
|
||||
taskQueue: queue,
|
||||
retry: {
|
||||
maximumAttempts: 5,
|
||||
initialInterval: '10s',
|
||||
},
|
||||
})
|
||||
result = await handle[activityName](...args)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user