@outputai/core 0.1.13-dev.98dfd72.0 → 0.1.13-dev.e3e3291.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/worker/configs.js +1 -4
- package/src/worker/index.js +2 -5
- package/src/worker/index.spec.js +1 -6
- package/src/worker/start_catalog.js +20 -3
- package/src/worker/start_catalog.spec.js +71 -8
- package/src/worker/proxy.js +0 -16
- package/src/worker/proxy.spec.js +0 -63
package/package.json
CHANGED
package/src/worker/configs.js
CHANGED
|
@@ -26,9 +26,7 @@ const envVarSchema = z.object( {
|
|
|
26
26
|
// Whether to send activity heartbeats (enabled by default)
|
|
27
27
|
OUTPUT_ACTIVITY_HEARTBEAT_ENABLED: z.transform( v => v === undefined ? true : isStringboolTrue( v ) ),
|
|
28
28
|
// Time to allow for hooks to flush before shutdown
|
|
29
|
-
OUTPUT_PROCESS_FAILURE_SHUTDOWN_DELAY: z.preprocess( coalesceEmptyString, z.coerce.number().int().positive().default( 3000 ) )
|
|
30
|
-
// HTTP CONNECT proxy for Temporal gRPC connections (e.g. "proxy-host:8080")
|
|
31
|
-
TEMPORAL_GRPC_PROXY: z.string().optional()
|
|
29
|
+
OUTPUT_PROCESS_FAILURE_SHUTDOWN_DELAY: z.preprocess( coalesceEmptyString, z.coerce.number().int().positive().default( 3000 ) )
|
|
32
30
|
} );
|
|
33
31
|
|
|
34
32
|
const { data: envVars, error } = envVarSchema.safeParse( process.env );
|
|
@@ -49,4 +47,3 @@ export const catalogId = envVars.OUTPUT_CATALOG_ID;
|
|
|
49
47
|
export const activityHeartbeatIntervalMs = envVars.OUTPUT_ACTIVITY_HEARTBEAT_INTERVAL_MS;
|
|
50
48
|
export const activityHeartbeatEnabled = envVars.OUTPUT_ACTIVITY_HEARTBEAT_ENABLED;
|
|
51
49
|
export const processFailureShutdownDelay = envVars.OUTPUT_PROCESS_FAILURE_SHUTDOWN_DELAY;
|
|
52
|
-
export const grpcProxy = envVars.TEMPORAL_GRPC_PROXY;
|
package/src/worker/index.js
CHANGED
|
@@ -9,7 +9,6 @@ import { initInterceptors } from './interceptors.js';
|
|
|
9
9
|
import { createChildLogger } from '#logger';
|
|
10
10
|
import { registerShutdown } from './shutdown.js';
|
|
11
11
|
import { startCatalog } from './start_catalog.js';
|
|
12
|
-
import { bootstrapFetchProxy } from './proxy.js';
|
|
13
12
|
import { messageBus } from '#bus';
|
|
14
13
|
import './log_hooks.js';
|
|
15
14
|
import { BusEventType } from '#consts';
|
|
@@ -25,7 +24,6 @@ const callerDir = process.argv[2];
|
|
|
25
24
|
apiKey,
|
|
26
25
|
namespace,
|
|
27
26
|
taskQueue,
|
|
28
|
-
grpcProxy,
|
|
29
27
|
maxConcurrentWorkflowTaskExecutions,
|
|
30
28
|
maxConcurrentActivityTaskExecutions,
|
|
31
29
|
maxCachedWorkflows,
|
|
@@ -43,7 +41,6 @@ const callerDir = process.argv[2];
|
|
|
43
41
|
const activities = await loadActivities( callerDir, workflows );
|
|
44
42
|
|
|
45
43
|
messageBus.emit( BusEventType.WORKER_BEFORE_START );
|
|
46
|
-
bootstrapFetchProxy();
|
|
47
44
|
|
|
48
45
|
log.info( 'Creating worker entry point...' );
|
|
49
46
|
const workflowsPath = createWorkflowsEntryPoint( workflows );
|
|
@@ -55,8 +52,8 @@ const callerDir = process.argv[2];
|
|
|
55
52
|
const catalog = createCatalog( { workflows, activities } );
|
|
56
53
|
|
|
57
54
|
log.info( 'Connecting Temporal...' );
|
|
58
|
-
|
|
59
|
-
const connection = await NativeConnection.connect( { address, tls: Boolean( apiKey ), apiKey
|
|
55
|
+
// Enable TLS when connecting to remote Temporal (API key present)
|
|
56
|
+
const connection = await NativeConnection.connect( { address, tls: Boolean( apiKey ), apiKey } );
|
|
60
57
|
|
|
61
58
|
log.info( 'Creating worker...' );
|
|
62
59
|
const worker = await Worker.create( {
|
package/src/worker/index.spec.js
CHANGED
|
@@ -16,7 +16,6 @@ const configValues = {
|
|
|
16
16
|
namespace: 'default',
|
|
17
17
|
taskQueue: 'test-queue',
|
|
18
18
|
catalogId: 'test-catalog',
|
|
19
|
-
grpcProxy: undefined,
|
|
20
19
|
maxConcurrentWorkflowTaskExecutions: 200,
|
|
21
20
|
maxConcurrentActivityTaskExecutions: 40,
|
|
22
21
|
maxCachedWorkflows: 1000,
|
|
@@ -53,9 +52,6 @@ vi.mock( './interceptors.js', () => ( { initInterceptors: initInterceptorsMock }
|
|
|
53
52
|
const startCatalogMock = vi.fn().mockResolvedValue( undefined );
|
|
54
53
|
vi.mock( './start_catalog.js', () => ( { startCatalog: startCatalogMock } ) );
|
|
55
54
|
|
|
56
|
-
const bootstrapFetchProxyMock = vi.fn();
|
|
57
|
-
vi.mock( './proxy.js', () => ( { bootstrapFetchProxy: bootstrapFetchProxyMock } ) );
|
|
58
|
-
|
|
59
55
|
const registerShutdownMock = vi.fn();
|
|
60
56
|
vi.mock( './shutdown.js', () => ( { registerShutdown: registerShutdownMock } ) );
|
|
61
57
|
|
|
@@ -108,8 +104,7 @@ describe( 'worker/index', () => {
|
|
|
108
104
|
expect( NativeConnection.connect ).toHaveBeenCalledWith( {
|
|
109
105
|
address: configValues.address,
|
|
110
106
|
tls: false,
|
|
111
|
-
apiKey: undefined
|
|
112
|
-
proxy: undefined
|
|
107
|
+
apiKey: undefined
|
|
113
108
|
} );
|
|
114
109
|
expect( Worker.create ).toHaveBeenCalledWith( expect.objectContaining( {
|
|
115
110
|
namespace: configValues.namespace,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Client } from '@temporalio/client';
|
|
1
|
+
import { Client, WorkflowNotFoundError } from '@temporalio/client';
|
|
2
2
|
import { WorkflowIdConflictPolicy } from '@temporalio/common';
|
|
3
3
|
import { WORKFLOW_CATALOG } from '#consts';
|
|
4
4
|
import { catalogId, taskQueue } from './configs.js';
|
|
@@ -8,12 +8,29 @@ const log = createChildLogger( 'Catalog' );
|
|
|
8
8
|
|
|
9
9
|
export const startCatalog = async ( { connection, namespace, catalog } ) => {
|
|
10
10
|
const client = new Client( { connection, namespace } );
|
|
11
|
+
const catalogWorkflowHandle = client.workflow.getHandle( catalogId );
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const catalogWorkflowDescription = await catalogWorkflowHandle.describe();
|
|
15
|
+
if ( !catalogWorkflowDescription.closeTime ) {
|
|
16
|
+
log.info( 'Completing previous catalog workflow...' );
|
|
17
|
+
await catalogWorkflowHandle.executeUpdate( 'complete', { args: [] } );
|
|
18
|
+
}
|
|
19
|
+
} catch ( error ) {
|
|
20
|
+
// When "not found", it's either a cold start or the catalog was already stopped/terminated, ignore it.
|
|
21
|
+
// Otherwise, create a log and try the next operation:
|
|
22
|
+
// A. If the workflow is still running, the start() will fail and throw;
|
|
23
|
+
// B. If the workflow is no running, the start() will succeed, and the error was transient;
|
|
24
|
+
if ( !( error instanceof WorkflowNotFoundError ) ) {
|
|
25
|
+
log.warn( 'Error interacting with previous catalog workflow', { error } );
|
|
26
|
+
}
|
|
27
|
+
}
|
|
11
28
|
|
|
12
29
|
log.info( 'Starting catalog workflow...' );
|
|
13
30
|
await client.workflow.start( WORKFLOW_CATALOG, {
|
|
14
31
|
taskQueue,
|
|
15
|
-
workflowId: catalogId,
|
|
16
|
-
workflowIdConflictPolicy: WorkflowIdConflictPolicy.
|
|
32
|
+
workflowId: catalogId, // use the name of the task queue as the catalog name, ensuring uniqueness
|
|
33
|
+
workflowIdConflictPolicy: WorkflowIdConflictPolicy.FAIL,
|
|
17
34
|
args: [ catalog ]
|
|
18
35
|
} );
|
|
19
36
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { WorkflowNotFoundError } from '@temporalio/client';
|
|
2
3
|
|
|
3
4
|
const mockLog = { info: vi.fn(), warn: vi.fn(), error: vi.fn() };
|
|
4
5
|
vi.mock( '#logger', () => ( { createChildLogger: () => mockLog } ) );
|
|
@@ -9,18 +10,25 @@ const catalogId = 'test-catalog';
|
|
|
9
10
|
const taskQueue = 'test-queue';
|
|
10
11
|
vi.mock( './configs.js', () => ( { catalogId, taskQueue } ) );
|
|
11
12
|
|
|
13
|
+
const describeMock = vi.fn();
|
|
14
|
+
const executeUpdateMock = vi.fn();
|
|
12
15
|
const workflowStartMock = vi.fn().mockResolvedValue( undefined );
|
|
13
16
|
vi.mock( '@temporalio/client', async importOriginal => {
|
|
14
17
|
const actual = await importOriginal();
|
|
15
18
|
return {
|
|
16
19
|
...actual,
|
|
17
20
|
Client: vi.fn().mockImplementation( function () {
|
|
18
|
-
return {
|
|
21
|
+
return {
|
|
22
|
+
workflow: {
|
|
23
|
+
start: workflowStartMock,
|
|
24
|
+
getHandle: () => ( { describe: describeMock, executeUpdate: executeUpdateMock } )
|
|
25
|
+
}
|
|
26
|
+
};
|
|
19
27
|
} )
|
|
20
28
|
};
|
|
21
29
|
} );
|
|
22
30
|
|
|
23
|
-
vi.mock( '@temporalio/common', () => ( { WorkflowIdConflictPolicy: {
|
|
31
|
+
vi.mock( '@temporalio/common', () => ( { WorkflowIdConflictPolicy: { FAIL: 'FAIL' } } ) );
|
|
24
32
|
|
|
25
33
|
describe( 'worker/start_catalog', () => {
|
|
26
34
|
const mockConnection = {};
|
|
@@ -32,24 +40,79 @@ describe( 'worker/start_catalog', () => {
|
|
|
32
40
|
workflowStartMock.mockResolvedValue( undefined );
|
|
33
41
|
} );
|
|
34
42
|
|
|
35
|
-
it( '
|
|
43
|
+
it( 'when previous catalog still running: completes it then starts catalog workflow', async () => {
|
|
44
|
+
describeMock.mockResolvedValue( { closeTime: undefined } );
|
|
45
|
+
executeUpdateMock.mockResolvedValue( undefined );
|
|
46
|
+
|
|
47
|
+
const { startCatalog } = await import( './start_catalog.js' );
|
|
48
|
+
await startCatalog( { connection: mockConnection, namespace, catalog } );
|
|
49
|
+
|
|
50
|
+
expect( describeMock ).toHaveBeenCalled();
|
|
51
|
+
expect( mockLog.info ).toHaveBeenCalledWith( 'Completing previous catalog workflow...' );
|
|
52
|
+
expect( executeUpdateMock ).toHaveBeenCalledWith( 'complete', { args: [] } );
|
|
53
|
+
expect( mockLog.info ).toHaveBeenCalledWith( 'Starting catalog workflow...' );
|
|
54
|
+
expect( workflowStartMock ).toHaveBeenCalledWith( 'catalog', {
|
|
55
|
+
taskQueue,
|
|
56
|
+
workflowId: catalogId,
|
|
57
|
+
workflowIdConflictPolicy: 'FAIL',
|
|
58
|
+
args: [ catalog ]
|
|
59
|
+
} );
|
|
60
|
+
} );
|
|
61
|
+
|
|
62
|
+
it( 'when no previous catalog: ignores and starts catalog workflow', async () => {
|
|
63
|
+
describeMock.mockRejectedValue( new WorkflowNotFoundError( 'not found' ) );
|
|
64
|
+
|
|
65
|
+
const { startCatalog } = await import( './start_catalog.js' );
|
|
66
|
+
await startCatalog( { connection: mockConnection, namespace, catalog } );
|
|
67
|
+
|
|
68
|
+
expect( describeMock ).toHaveBeenCalled();
|
|
69
|
+
expect( mockLog.warn ).not.toHaveBeenCalled();
|
|
70
|
+
expect( mockLog.info ).toHaveBeenCalledWith( 'Starting catalog workflow...' );
|
|
71
|
+
expect( executeUpdateMock ).not.toHaveBeenCalled();
|
|
72
|
+
expect( workflowStartMock ).toHaveBeenCalledWith( 'catalog', {
|
|
73
|
+
taskQueue,
|
|
74
|
+
workflowId: catalogId,
|
|
75
|
+
workflowIdConflictPolicy: 'FAIL',
|
|
76
|
+
args: [ catalog ]
|
|
77
|
+
} );
|
|
78
|
+
} );
|
|
79
|
+
|
|
80
|
+
it( 'when previous catalog already closed: skips complete and starts catalog workflow', async () => {
|
|
81
|
+
describeMock.mockResolvedValue( { closeTime: '2024-01-01T00:00:00Z' } );
|
|
82
|
+
|
|
36
83
|
const { startCatalog } = await import( './start_catalog.js' );
|
|
37
84
|
await startCatalog( { connection: mockConnection, namespace, catalog } );
|
|
38
85
|
|
|
86
|
+
expect( describeMock ).toHaveBeenCalled();
|
|
87
|
+
expect( mockLog.info ).not.toHaveBeenCalledWith( 'Completing previous catalog workflow...' );
|
|
88
|
+
expect( executeUpdateMock ).not.toHaveBeenCalled();
|
|
39
89
|
expect( mockLog.info ).toHaveBeenCalledWith( 'Starting catalog workflow...' );
|
|
40
90
|
expect( workflowStartMock ).toHaveBeenCalledWith( 'catalog', {
|
|
41
91
|
taskQueue,
|
|
42
92
|
workflowId: catalogId,
|
|
43
|
-
workflowIdConflictPolicy: '
|
|
93
|
+
workflowIdConflictPolicy: 'FAIL',
|
|
44
94
|
args: [ catalog ]
|
|
45
95
|
} );
|
|
46
96
|
} );
|
|
47
97
|
|
|
48
|
-
it( '
|
|
49
|
-
|
|
98
|
+
it( 'when describe or complete fails with other error: logs warn and still starts catalog workflow', async () => {
|
|
99
|
+
describeMock.mockResolvedValue( { closeTime: undefined } );
|
|
100
|
+
executeUpdateMock.mockRejectedValue( new Error( 'Connection refused' ) );
|
|
50
101
|
|
|
51
102
|
const { startCatalog } = await import( './start_catalog.js' );
|
|
52
|
-
await
|
|
53
|
-
|
|
103
|
+
await startCatalog( { connection: mockConnection, namespace, catalog } );
|
|
104
|
+
|
|
105
|
+
expect( describeMock ).toHaveBeenCalled();
|
|
106
|
+
expect( executeUpdateMock ).toHaveBeenCalledWith( 'complete', { args: [] } );
|
|
107
|
+
expect( mockLog.warn ).toHaveBeenCalledWith( 'Error interacting with previous catalog workflow', {
|
|
108
|
+
error: expect.any( Error )
|
|
109
|
+
} );
|
|
110
|
+
expect( mockLog.info ).toHaveBeenCalledWith( 'Starting catalog workflow...' );
|
|
111
|
+
expect( workflowStartMock ).toHaveBeenCalledWith( 'catalog', {
|
|
112
|
+
taskQueue,
|
|
113
|
+
workflowId: catalogId,
|
|
114
|
+
workflowIdConflictPolicy: 'FAIL',
|
|
115
|
+
args: [ catalog ]
|
|
116
|
+
} );
|
|
54
117
|
} );
|
|
55
118
|
} );
|
package/src/worker/proxy.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { EnvHttpProxyAgent, setGlobalDispatcher } from 'undici';
|
|
2
|
-
import { createChildLogger } from '#logger';
|
|
3
|
-
|
|
4
|
-
const log = createChildLogger( 'Proxy' );
|
|
5
|
-
|
|
6
|
-
export const bootstrapFetchProxy = () => {
|
|
7
|
-
const proxyUrl = process.env.HTTPS_PROXY || process.env.https_proxy ||
|
|
8
|
-
process.env.HTTP_PROXY || process.env.http_proxy;
|
|
9
|
-
|
|
10
|
-
if ( !proxyUrl ) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
log.info( 'Routing fetch() through HTTP proxy', { proxyUrl } );
|
|
15
|
-
setGlobalDispatcher( new EnvHttpProxyAgent() );
|
|
16
|
-
};
|
package/src/worker/proxy.spec.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
|
|
3
|
-
const mockSetGlobalDispatcher = vi.fn();
|
|
4
|
-
const MockEnvHttpProxyAgent = vi.fn();
|
|
5
|
-
|
|
6
|
-
vi.mock( 'undici', () => ( {
|
|
7
|
-
EnvHttpProxyAgent: MockEnvHttpProxyAgent,
|
|
8
|
-
setGlobalDispatcher: mockSetGlobalDispatcher
|
|
9
|
-
} ) );
|
|
10
|
-
|
|
11
|
-
vi.mock( '#logger', () => ( {
|
|
12
|
-
createChildLogger: () => ( { info: vi.fn(), warn: vi.fn(), error: vi.fn() } )
|
|
13
|
-
} ) );
|
|
14
|
-
|
|
15
|
-
describe( 'worker/proxy', () => {
|
|
16
|
-
const originalEnv = { ...process.env };
|
|
17
|
-
|
|
18
|
-
beforeEach( () => {
|
|
19
|
-
vi.clearAllMocks();
|
|
20
|
-
delete process.env.HTTPS_PROXY;
|
|
21
|
-
delete process.env.https_proxy;
|
|
22
|
-
delete process.env.HTTP_PROXY;
|
|
23
|
-
delete process.env.http_proxy;
|
|
24
|
-
} );
|
|
25
|
-
|
|
26
|
-
afterEach( () => {
|
|
27
|
-
process.env = { ...originalEnv };
|
|
28
|
-
} );
|
|
29
|
-
|
|
30
|
-
it( 'does nothing when no proxy env vars are set', async () => {
|
|
31
|
-
const { bootstrapFetchProxy } = await import( './proxy.js' );
|
|
32
|
-
bootstrapFetchProxy();
|
|
33
|
-
|
|
34
|
-
expect( mockSetGlobalDispatcher ).not.toHaveBeenCalled();
|
|
35
|
-
} );
|
|
36
|
-
|
|
37
|
-
it( 'sets global dispatcher when HTTPS_PROXY is set', async () => {
|
|
38
|
-
process.env.HTTPS_PROXY = 'http://proxy:8080';
|
|
39
|
-
const { bootstrapFetchProxy } = await import( './proxy.js' );
|
|
40
|
-
bootstrapFetchProxy();
|
|
41
|
-
|
|
42
|
-
expect( MockEnvHttpProxyAgent ).toHaveBeenCalled();
|
|
43
|
-
expect( mockSetGlobalDispatcher ).toHaveBeenCalledTimes( 1 );
|
|
44
|
-
} );
|
|
45
|
-
|
|
46
|
-
it( 'sets global dispatcher when HTTP_PROXY is set', async () => {
|
|
47
|
-
process.env.HTTP_PROXY = 'http://proxy:8080';
|
|
48
|
-
const { bootstrapFetchProxy } = await import( './proxy.js' );
|
|
49
|
-
bootstrapFetchProxy();
|
|
50
|
-
|
|
51
|
-
expect( MockEnvHttpProxyAgent ).toHaveBeenCalled();
|
|
52
|
-
expect( mockSetGlobalDispatcher ).toHaveBeenCalledTimes( 1 );
|
|
53
|
-
} );
|
|
54
|
-
|
|
55
|
-
it( 'prefers HTTPS_PROXY over HTTP_PROXY for detection', async () => {
|
|
56
|
-
process.env.HTTPS_PROXY = 'http://secure-proxy:8080';
|
|
57
|
-
process.env.HTTP_PROXY = 'http://plain-proxy:8080';
|
|
58
|
-
const { bootstrapFetchProxy } = await import( './proxy.js' );
|
|
59
|
-
bootstrapFetchProxy();
|
|
60
|
-
|
|
61
|
-
expect( mockSetGlobalDispatcher ).toHaveBeenCalledTimes( 1 );
|
|
62
|
-
} );
|
|
63
|
-
} );
|