@diia-inhouse/workflow 1.15.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/LICENCE.md +287 -0
- package/README.md +93 -0
- package/dist/activities/index.js +18 -0
- package/dist/activities/index.js.map +1 -0
- package/dist/activities/proxy.js +26 -0
- package/dist/activities/proxy.js.map +1 -0
- package/dist/activity.js +15 -0
- package/dist/activity.js.map +1 -0
- package/dist/cli/checkWorkflowDeterminism.js +443 -0
- package/dist/cli/checkWorkflowDeterminism.js.map +1 -0
- package/dist/cli/index.js +111 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/syncTemporalSchedules.js +92 -0
- package/dist/cli/syncTemporalSchedules.js.map +1 -0
- package/dist/cli/updateTemporalSchedule.js +53 -0
- package/dist/cli/updateTemporalSchedule.js.map +1 -0
- package/dist/client.js +19 -0
- package/dist/client.js.map +1 -0
- package/dist/common.js +13 -0
- package/dist/common.js.map +1 -0
- package/dist/encryption/crypto.js +28 -0
- package/dist/encryption/crypto.js.map +1 -0
- package/dist/encryption/dataConverter.js +27 -0
- package/dist/encryption/dataConverter.js.map +1 -0
- package/dist/encryption/encryptionCodec.js +125 -0
- package/dist/encryption/encryptionCodec.js.map +1 -0
- package/dist/encryption/index.js +20 -0
- package/dist/encryption/index.js.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/instrumentation.js +10 -0
- package/dist/instrumentation.js.map +1 -0
- package/dist/interceptors/asyncLocalStorageBridge.js +67 -0
- package/dist/interceptors/asyncLocalStorageBridge.js.map +1 -0
- package/dist/interceptors/index.js +6 -0
- package/dist/interceptors/index.js.map +1 -0
- package/dist/interceptors.js +10 -0
- package/dist/interceptors.js.map +1 -0
- package/dist/interfaces/config.js +3 -0
- package/dist/interfaces/config.js.map +1 -0
- package/dist/interfaces/index.js +18 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/services/worker.js +3 -0
- package/dist/interfaces/services/worker.js.map +1 -0
- package/dist/operations.js +77 -0
- package/dist/operations.js.map +1 -0
- package/dist/services/client.js +96 -0
- package/dist/services/client.js.map +1 -0
- package/dist/services/index.js +19 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/worker/identity.js +11 -0
- package/dist/services/worker/identity.js.map +1 -0
- package/dist/services/worker/index.js +18 -0
- package/dist/services/worker/index.js.map +1 -0
- package/dist/services/worker.js +324 -0
- package/dist/services/worker.js.map +1 -0
- package/dist/services/workerHealth.js +39 -0
- package/dist/services/workerHealth.js.map +1 -0
- package/dist/testing.js +57 -0
- package/dist/testing.js.map +1 -0
- package/dist/types/activities/index.d.ts +1 -0
- package/dist/types/activities/proxy.d.ts +35 -0
- package/dist/types/activity.d.ts +1 -0
- package/dist/types/cli/checkWorkflowDeterminism.d.ts +22 -0
- package/dist/types/cli/index.d.ts +2 -0
- package/dist/types/cli/syncTemporalSchedules.d.ts +12 -0
- package/dist/types/cli/updateTemporalSchedule.d.ts +9 -0
- package/dist/types/client.d.ts +2 -0
- package/dist/types/common.d.ts +1 -0
- package/dist/types/encryption/crypto.d.ts +3 -0
- package/dist/types/encryption/dataConverter.d.ts +3 -0
- package/dist/types/encryption/encryptionCodec.d.ts +27 -0
- package/dist/types/encryption/index.d.ts +3 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/instrumentation.d.ts +2 -0
- package/dist/types/interceptors/asyncLocalStorageBridge.d.ts +21 -0
- package/dist/types/interceptors/index.d.ts +1 -0
- package/dist/types/interceptors.d.ts +2 -0
- package/dist/types/interfaces/config.d.ts +38 -0
- package/dist/types/interfaces/index.d.ts +1 -0
- package/dist/types/interfaces/services/worker.d.ts +37 -0
- package/dist/types/operations.d.ts +5 -0
- package/dist/types/services/client.d.ts +20 -0
- package/dist/types/services/index.d.ts +2 -0
- package/dist/types/services/worker/identity.d.ts +1 -0
- package/dist/types/services/worker/index.d.ts +1 -0
- package/dist/types/services/worker.d.ts +113 -0
- package/dist/types/services/workerHealth.d.ts +11 -0
- package/dist/types/testing.d.ts +42 -0
- package/dist/types/worker.d.ts +3 -0
- package/dist/worker.js +25 -0
- package/dist/worker.js.map +1 -0
- package/package.json +139 -0
package/dist/testing.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.workflowInterceptorModules = exports.TimeSkippingWorkflowClient = exports.TestWorkflowEnvironment = exports.MockActivityEnvironment = exports.defaultActivityInfo = void 0;
|
|
4
|
+
exports.mockActivities = mockActivities;
|
|
5
|
+
var testing_1 = require("@temporalio/testing");
|
|
6
|
+
Object.defineProperty(exports, "defaultActivityInfo", { enumerable: true, get: function () { return testing_1.defaultActivityInfo; } });
|
|
7
|
+
Object.defineProperty(exports, "MockActivityEnvironment", { enumerable: true, get: function () { return testing_1.MockActivityEnvironment; } });
|
|
8
|
+
Object.defineProperty(exports, "TestWorkflowEnvironment", { enumerable: true, get: function () { return testing_1.TestWorkflowEnvironment; } });
|
|
9
|
+
Object.defineProperty(exports, "TimeSkippingWorkflowClient", { enumerable: true, get: function () { return testing_1.TimeSkippingWorkflowClient; } });
|
|
10
|
+
Object.defineProperty(exports, "workflowInterceptorModules", { enumerable: true, get: function () { return testing_1.workflowInterceptorModules; } });
|
|
11
|
+
/**
|
|
12
|
+
* Redefines instantiated activities for use in test environments.
|
|
13
|
+
*
|
|
14
|
+
* This function allows to override specific activity methods with mock implementations
|
|
15
|
+
* while preserving the overall activity structure.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // Original activities object
|
|
19
|
+
* const activities = instantiateActivities(app, workerActivities)
|
|
20
|
+
*
|
|
21
|
+
* // Mock specific methods for testing
|
|
22
|
+
* const mockedActivities = {
|
|
23
|
+
* ...activities,
|
|
24
|
+
* ...mockActivities<typeof workerActivities>({
|
|
25
|
+
* user: {
|
|
26
|
+
* getProfile: async (userId) => ({ id: userId, name: 'Test User' }),
|
|
27
|
+
* },
|
|
28
|
+
* payment: {
|
|
29
|
+
* process: async () => ({ success: true, transactionId: 'mock-123' })
|
|
30
|
+
* }
|
|
31
|
+
* })
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* // Using with test runner
|
|
36
|
+
* await runWorkflow({
|
|
37
|
+
* workflow: myWorkflow,
|
|
38
|
+
* args: [workflowInput],
|
|
39
|
+
* activities: mockedActivities
|
|
40
|
+
* })
|
|
41
|
+
*/
|
|
42
|
+
function mockActivities(activities) {
|
|
43
|
+
const result = {};
|
|
44
|
+
for (const activityName in activities) {
|
|
45
|
+
const methods = activities[activityName];
|
|
46
|
+
if (methods) {
|
|
47
|
+
for (const [methodName, method] of Object.entries(methods)) {
|
|
48
|
+
const fullKey = `${activityName}.${methodName}`;
|
|
49
|
+
if (typeof method === 'function') {
|
|
50
|
+
result[fullKey] = method;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":";;;AA4CA,wCAoBC;AAhED,+CAM4B;AALxB,8GAAA,mBAAmB,OAAA;AACnB,kHAAA,uBAAuB,OAAA;AACvB,kHAAA,uBAAuB,OAAA;AACvB,qHAAA,0BAA0B,OAAA;AAC1B,qHAAA,0BAA0B,OAAA;AAQ9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,SAAgB,cAAc,CAA6D,UAE1F;IACG,MAAM,MAAM,GAAoD,EAAE,CAAA;IAElE,KAAK,MAAM,YAAY,IAAI,UAAU,EAAE,CAAC;QACpC,MAAM,OAAO,GAAG,UAAU,CAAC,YAAY,CAAC,CAAA;QAExC,IAAI,OAAO,EAAE,CAAC;YACV,KAAK,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;gBACzD,MAAM,OAAO,GAAG,GAAG,YAAY,IAAI,UAAU,EAAE,CAAA;gBAE/C,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;oBAC/B,MAAM,CAAC,OAAO,CAAC,GAAG,MAAyC,CAAA;gBAC/D,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAA;AACjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './proxy';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ActivityInterfaceFor, ActivityOptions, proxyLocalActivities } from '@temporalio/workflow';
|
|
2
|
+
type ActivityClass<T> = T extends {
|
|
3
|
+
prototype: infer P;
|
|
4
|
+
} ? P : never;
|
|
5
|
+
type LocalActivityOptions = Parameters<typeof proxyLocalActivities>[0];
|
|
6
|
+
/**
|
|
7
|
+
* Enhances Temporal activities by prefixing method names with their class name.
|
|
8
|
+
*
|
|
9
|
+
* Wraps Temporal's proxy functions to provide namespacing (e.g., `orderProcessing.processOrder`),
|
|
10
|
+
* improving organization in Temporal's UI and avoiding naming conflicts.
|
|
11
|
+
*
|
|
12
|
+
* @param {boolean} useLocalActivitiesProxy - Use local activities (true) or regular activities (false, default)
|
|
13
|
+
* @returns {Object} Proxy with class name prefixing for activity methods
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* import type { workerActivities } from '../activities'
|
|
17
|
+
*
|
|
18
|
+
* const activities = buildActivitiesProxy<typeof workerActivities>();
|
|
19
|
+
*
|
|
20
|
+
* // In workflow
|
|
21
|
+
* const payment = activities.payment({ startToCloseTimeout: '30s' });
|
|
22
|
+
* const order = activities.order({ startToCloseTimeout: '30s' });
|
|
23
|
+
*
|
|
24
|
+
* const success = await payment.processPayment(orderId, amount); // Calls "payment.processPayment" activity
|
|
25
|
+
* if (success) {
|
|
26
|
+
* return await order.process(orderId); // Calls "order.process" activity
|
|
27
|
+
* }
|
|
28
|
+
*/
|
|
29
|
+
export declare function buildActivitiesProxy<TActivity extends Record<string, unknown>>(useLocalActivitiesProxy: true): {
|
|
30
|
+
[K in keyof TActivity]: (options: LocalActivityOptions) => ActivityInterfaceFor<ActivityClass<TActivity[K]>>;
|
|
31
|
+
};
|
|
32
|
+
export declare function buildActivitiesProxy<TActivity extends Record<string, unknown>>(useLocalActivitiesProxy?: false): {
|
|
33
|
+
[K in keyof TActivity]: (options: ActivityOptions) => ActivityInterfaceFor<ActivityClass<TActivity[K]>>;
|
|
34
|
+
};
|
|
35
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { type Info as ActivityInfo, ApplicationFailure, CancelledFailure, CompleteAsyncError, activityInfo, sleep, heartbeat, log, Context, cancellationSignal, cancelled, } from '@temporalio/activity';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EnvService } from '@diia-inhouse/env';
|
|
2
|
+
import { Logger } from '@diia-inhouse/types';
|
|
3
|
+
export declare class CheckWorkflowDeterminismCommand {
|
|
4
|
+
private readonly logger;
|
|
5
|
+
private readonly envService;
|
|
6
|
+
private temporalConfig;
|
|
7
|
+
private report;
|
|
8
|
+
private readonly maxWorkflowsPerType;
|
|
9
|
+
private readonly maxRetries;
|
|
10
|
+
private readonly retryDelay;
|
|
11
|
+
constructor(logger: Logger, envService: EnvService);
|
|
12
|
+
run(workflowsPath?: string, taskQueueParam?: string, workflowId?: string): Promise<void>;
|
|
13
|
+
private checkWorkflowDeterminism;
|
|
14
|
+
private runReplayHistory;
|
|
15
|
+
private runReplayHistoryWithRetry;
|
|
16
|
+
private checkSingleWorkflow;
|
|
17
|
+
private loadWorkflows;
|
|
18
|
+
private listCompletedOrFailedWorkflows;
|
|
19
|
+
private resolveWorkflowsPath;
|
|
20
|
+
private getTaskQueue;
|
|
21
|
+
private printBeautifulResults;
|
|
22
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EnvService } from '@diia-inhouse/env';
|
|
2
|
+
import { Logger } from '@diia-inhouse/types';
|
|
3
|
+
export declare class SyncTemporalSchedulesCommand {
|
|
4
|
+
private readonly logger;
|
|
5
|
+
private readonly envService;
|
|
6
|
+
constructor(logger: Logger, envService: EnvService);
|
|
7
|
+
run(schedulesPath?: string, taskQueueParam?: string): Promise<void>;
|
|
8
|
+
private loadSchedules;
|
|
9
|
+
private resolveSchedulesPath;
|
|
10
|
+
private syncSchedules;
|
|
11
|
+
private getTaskQueue;
|
|
12
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EnvService } from '@diia-inhouse/env';
|
|
2
|
+
import { Logger } from '@diia-inhouse/types';
|
|
3
|
+
export declare class UpdateTemporalScheduleCommand {
|
|
4
|
+
private readonly logger;
|
|
5
|
+
private readonly envService;
|
|
6
|
+
constructor(logger: Logger, envService: EnvService);
|
|
7
|
+
run(scheduleId: string, updateData: Record<string, unknown>): Promise<void>;
|
|
8
|
+
private getTaskQueue;
|
|
9
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { Client, ScheduleOptions, DAYS_OF_WEEK, type DayOfWeek, MONTHS, type Month, WorkflowClient, ActivityFailure, ProtoFailure, ServerFailure, TimeoutFailure, TemporalFailure, CancelledFailure, TerminatedFailure, ApplicationFailure, ChildWorkflowFailure, WorkflowHandleWithFirstExecutionRunId, } from '@temporalio/client';
|
|
2
|
+
export { TemporalClient } from './services/client';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { type DataConverter, arrayFromPayloads, cutoffStackTrace, ensureApplicationFailure, ensureTemporalFailure, extractWorkflowType, defaultFailureConverter, rootCause, WorkflowExecutionAlreadyStartedError, } from '@temporalio/common';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { webcrypto as crypto } from 'node:crypto';
|
|
2
|
+
import { Payload, PayloadCodec } from '@temporalio/common';
|
|
3
|
+
import { EnvService } from '@diia-inhouse/env';
|
|
4
|
+
import { Logger } from '@diia-inhouse/types';
|
|
5
|
+
export declare class EncryptionCodec implements PayloadCodec {
|
|
6
|
+
private readonly keys;
|
|
7
|
+
private defaultKeyId;
|
|
8
|
+
private readonly envService;
|
|
9
|
+
private readonly logger;
|
|
10
|
+
private readonly batchSize;
|
|
11
|
+
private readonly encoding;
|
|
12
|
+
private readonly metadataEncryptionKeyId;
|
|
13
|
+
constructor(keys: Map<string, crypto.CryptoKey>, defaultKeyId: string, envService: EnvService, logger: Logger, options?: {
|
|
14
|
+
batchSize?: number;
|
|
15
|
+
vaultEnabled?: boolean;
|
|
16
|
+
});
|
|
17
|
+
static create(keyId: string, envService: EnvService, options: {
|
|
18
|
+
batchSize?: number;
|
|
19
|
+
vaultEnabled?: boolean;
|
|
20
|
+
}, logger?: Logger): Promise<EncryptionCodec>;
|
|
21
|
+
private static createCryptoKey;
|
|
22
|
+
refreshDefaultKey(): Promise<void>;
|
|
23
|
+
encode(payloads: Payload[]): Promise<Payload[]>;
|
|
24
|
+
decode(payloads: Payload[]): Promise<Payload[]>;
|
|
25
|
+
private processBatch;
|
|
26
|
+
private splitKeyId;
|
|
27
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { Context as ActivityContext } from '@temporalio/activity';
|
|
3
|
+
import { ActivityExecuteInput, ActivityInboundCallsInterceptor, Next } from '@temporalio/worker';
|
|
4
|
+
import { AlsData, Logger } from '@diia-inhouse/types';
|
|
5
|
+
/**
|
|
6
|
+
* Bridges OpenTelemetry trace context to AsyncLocalStorage for Temporal activities.
|
|
7
|
+
*
|
|
8
|
+
* Extracts trace_id from OpenTelemetry span and injects it into AsyncLocalStorage,
|
|
9
|
+
* making it available to services.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // In a service called from an activity:
|
|
13
|
+
* const traceId = this.asyncLocalStorage.getStore()?.logData?.traceId
|
|
14
|
+
*/
|
|
15
|
+
export declare class AsyncLocalStorageBridgeInterceptor implements ActivityInboundCallsInterceptor {
|
|
16
|
+
protected readonly ctx: ActivityContext;
|
|
17
|
+
private readonly asyncLocalStorage;
|
|
18
|
+
private readonly logger;
|
|
19
|
+
constructor(ctx: ActivityContext, asyncLocalStorage: AsyncLocalStorage<AlsData>, logger: Logger);
|
|
20
|
+
execute(input: ActivityExecuteInput, next: Next<ActivityInboundCallsInterceptor, 'execute'>): Promise<unknown>;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AsyncLocalStorageBridgeInterceptor } from './asyncLocalStorageBridge';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ClientOptions, ConnectionOptions } from '@temporalio/client';
|
|
2
|
+
import { MetricsConfig } from '@diia-inhouse/diia-metrics';
|
|
3
|
+
import type { QueueConnectionConfig } from '@diia-inhouse/diia-queue';
|
|
4
|
+
export interface TemporalConfig extends Omit<ClientOptions, 'dataConverter'> {
|
|
5
|
+
taskQueue: string;
|
|
6
|
+
encryptionEnabled: boolean;
|
|
7
|
+
encryptionKeyId: string;
|
|
8
|
+
encryptionKeyRefreshInterval?: number;
|
|
9
|
+
address?: string;
|
|
10
|
+
tls?: ConnectionOptions['tls'];
|
|
11
|
+
connectTimeout?: ConnectionOptions['connectTimeout'];
|
|
12
|
+
/**
|
|
13
|
+
* Controls whether the Temporal worker runs in the same process as the service.
|
|
14
|
+
*
|
|
15
|
+
* - `true` (default): Worker is bootstrapped together with the service in the same process.
|
|
16
|
+
* - `false`: Service starts without bootstrapping the worker. The worker should be run
|
|
17
|
+
* as a separate process using `bootstrapWorker()`.
|
|
18
|
+
*
|
|
19
|
+
* This is configured at the service level to enable flexible deployment topologies
|
|
20
|
+
* where workers can be scaled independently from the main service.
|
|
21
|
+
*/
|
|
22
|
+
workerInProcess?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Whether to disable message queue consumers when running as a separate worker process.
|
|
25
|
+
* Applies to all queue connection types (internal, external, etc.).
|
|
26
|
+
*
|
|
27
|
+
* Defaults to `true` when `bootstrapWorker` manages the full application lifecycle
|
|
28
|
+
* (i.e. when `configFactory` and `deps` are provided).
|
|
29
|
+
*/
|
|
30
|
+
disableQueueConsumers?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface AppConfig {
|
|
33
|
+
temporal: TemporalConfig;
|
|
34
|
+
metrics: {
|
|
35
|
+
custom: MetricsConfig;
|
|
36
|
+
};
|
|
37
|
+
rabbit?: QueueConnectionConfig;
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './config';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
|
|
2
|
+
import { WorkerOptions, WorkerStatus } from '@temporalio/worker';
|
|
3
|
+
export type { State, WorkerStatus } from '@temporalio/worker';
|
|
4
|
+
export type WorkerStatusProvider = () => WorkerStatus;
|
|
5
|
+
export type ActivityInstance = Record<string, (...args: any[]) => any>;
|
|
6
|
+
export type BoundActivities<T extends ActivityInstance> = {
|
|
7
|
+
[K in keyof T as `${string}.${string & K}`]: ReturnType<T[K]> extends Promise<any> ? T[K] : (...args: Parameters<T[K]>) => Promise<ReturnType<T[K]>>;
|
|
8
|
+
};
|
|
9
|
+
export type ActivityClass = new (...args: any[]) => any;
|
|
10
|
+
export interface WorkerBootstrapOptions extends Omit<WorkerOptions, 'taskQueue' | 'activities' | 'workflowsPath'> {
|
|
11
|
+
workflowsPath: string;
|
|
12
|
+
activities: Record<string, ActivityClass>;
|
|
13
|
+
nodeTracerProvider?: NodeTracerProvider;
|
|
14
|
+
shutdownSignals?: NodeJS.Signals[];
|
|
15
|
+
/**
|
|
16
|
+
* When provided together with `deps`, `bootstrapWorker` manages the full application
|
|
17
|
+
* lifecycle: setConfig → apply worker overrides → setDeps → initialize → start → run worker.
|
|
18
|
+
*/
|
|
19
|
+
configFactory?: (...args: any[]) => Promise<any>;
|
|
20
|
+
/**
|
|
21
|
+
* Dependency factory passed to `app.setDeps()`. Required when `configFactory` is provided.
|
|
22
|
+
*/
|
|
23
|
+
deps?: (...args: any[]) => Promise<any>;
|
|
24
|
+
}
|
|
25
|
+
interface Container {
|
|
26
|
+
build(constructor: new (...args: unknown[]) => unknown): unknown;
|
|
27
|
+
resolve<T = unknown>(key: string): T;
|
|
28
|
+
}
|
|
29
|
+
export interface App {
|
|
30
|
+
container?: Container;
|
|
31
|
+
getConfig?(): unknown;
|
|
32
|
+
setConfig?(factory: (...args: any[]) => Promise<any>): Promise<any>;
|
|
33
|
+
setDeps?(factory: (...args: any[]) => Promise<any>): Promise<any>;
|
|
34
|
+
initialize?(...args: any[]): Promise<{
|
|
35
|
+
start(): Promise<any>;
|
|
36
|
+
}>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ActivityFailure } from '@temporalio/common';
|
|
2
|
+
export { allHandlersFinished, condition, continueAsNew, makeContinueAsNewFunc, ContinueAsNew, type ContinueAsNewOptions, setDefaultSignalHandler, log, workflowInfo, type WorkflowInfo, currentUpdateInfo, workflowMetadataQuery, sleep, setHandler, defineQuery, defineSignal, defineUpdate, executeChild, startChild, type ChildWorkflowHandle, type ChildWorkflowOptions, extractWorkflowType, upsertMemo, upsertSearchAttributes, patched, deprecatePatch, addDefaultWorkflowOptions, uuid4, isCancellation, type CommonWorkflowOptions, scheduleActivity, scheduleLocalActivity, proxyActivities, proxyLocalActivities, proxySinks, inWorkflowContext, CancellationScope, type CancellationScopeOptions, type WorkflowInterceptorsFactory, Trigger, getExternalWorkflowHandle, DeterminismViolationError, WorkflowError, ApplicationFailure, ChildWorkflowFailure, ServerFailure, TimeoutFailure, ActivityFailure, CancelledFailure, TerminatedFailure, TemporalFailure, } from '@temporalio/workflow';
|
|
3
|
+
export { buildActivitiesProxy } from './activities';
|
|
4
|
+
export * from './interceptors';
|
|
5
|
+
export declare function isNonRetryableFailure(err: unknown): err is ActivityFailure;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Client, ScheduleOptions, ScheduleUpdateOptions } from '@temporalio/client';
|
|
2
|
+
import { EnvService } from '@diia-inhouse/env';
|
|
3
|
+
import { Logger, OnInit } from '@diia-inhouse/types';
|
|
4
|
+
import { TemporalConfig } from '../interfaces/config';
|
|
5
|
+
export declare class TemporalClient implements OnInit {
|
|
6
|
+
private readonly config;
|
|
7
|
+
private readonly envService;
|
|
8
|
+
private readonly logger;
|
|
9
|
+
nativeClient: Client;
|
|
10
|
+
private readonly defaultTimezone;
|
|
11
|
+
constructor(config: TemporalConfig, envService: EnvService, logger: Logger);
|
|
12
|
+
get connection(): Client['connection'];
|
|
13
|
+
get workflow(): Client['workflow'];
|
|
14
|
+
get workflowService(): Client['workflowService'];
|
|
15
|
+
get schedule(): Client['schedule'];
|
|
16
|
+
get taskQueue(): Client['taskQueue'];
|
|
17
|
+
onInit(): Promise<void>;
|
|
18
|
+
syncSchedules(schedules: Record<string, ((config: TemporalConfig) => ScheduleOptions) | ScheduleOptions>): Promise<void>;
|
|
19
|
+
updateSchedule(scheduleId: string, updateData: ScheduleUpdateOptions): Promise<void>;
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function buildWorkerIdentity(taskQueue: string, identityOverride?: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './identity';
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
|
|
3
|
+
import { Worker, WorkerOptions } from '@temporalio/worker';
|
|
4
|
+
import { EnvService } from '@diia-inhouse/env';
|
|
5
|
+
import { AlsData, Logger } from '@diia-inhouse/types';
|
|
6
|
+
import { AppConfig } from '../interfaces/config';
|
|
7
|
+
import type { ActivityClass, App, WorkerBootstrapOptions } from '../interfaces/services/worker';
|
|
8
|
+
export type { ActivityClass, App, State, WorkerBootstrapOptions } from '../interfaces/services/worker';
|
|
9
|
+
export type { WorkerHealthDetails } from './workerHealth';
|
|
10
|
+
export { buildWorkerIdentity } from './worker/identity';
|
|
11
|
+
export { WorkerHealthService } from './workerHealth';
|
|
12
|
+
/**
|
|
13
|
+
* Applies service process configuration overrides when the worker runs separately.
|
|
14
|
+
*
|
|
15
|
+
* When `temporal.workerInProcess` is `false`, disables `temporal` and `temporal-worker` scrapers
|
|
16
|
+
* so the main service does not scrape metrics that the worker process handles.
|
|
17
|
+
*
|
|
18
|
+
* Mutates the config object in place. Safe to call when scrapers are absent.
|
|
19
|
+
*/
|
|
20
|
+
export declare function applyServiceProcessConfig(config: AppConfig): void;
|
|
21
|
+
/**
|
|
22
|
+
* Applies worker process configuration overrides.
|
|
23
|
+
*
|
|
24
|
+
* - Disables queue consumers on all rabbit connections (unless `temporal.disableQueueConsumers` is `false`)
|
|
25
|
+
* - Overrides `metrics.custom.port` with the `'temporal-worker'` scraper port and disables that scraper to prevent self-scraping
|
|
26
|
+
*
|
|
27
|
+
* Mutates the config object in place. Safe to call when queue config is absent.
|
|
28
|
+
*/
|
|
29
|
+
export declare function applyWorkerProcessConfig(config: AppConfig): void;
|
|
30
|
+
export declare function instantiateActivities(app: App, workerActivities: Record<string, ActivityClass>): Record<string, (...args: unknown[]) => Promise<unknown>>;
|
|
31
|
+
/**
|
|
32
|
+
* Initializes and starts Temporal worker with full dependency injection support.
|
|
33
|
+
*
|
|
34
|
+
* This is the recommended way to initialize Temporal workers. It handles:
|
|
35
|
+
* - Automatic dependency injection for activities
|
|
36
|
+
* - AsyncLocalStorage setup for distributed tracing
|
|
37
|
+
* - OpenTelemetry integration
|
|
38
|
+
* - Activity instantiation and binding
|
|
39
|
+
*
|
|
40
|
+
* @param app - App instance for DI container and config access
|
|
41
|
+
* @param options - Worker configuration options
|
|
42
|
+
* @param options.nodeTracerProvider - OpenTelemetry tracer provider
|
|
43
|
+
* @param options.workflowsPath - Path to workflows module
|
|
44
|
+
* @param options.activities - Activity classes to instantiate
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Define your activities
|
|
49
|
+
* const workerActivities = {
|
|
50
|
+
* userActivity: UserActivity,
|
|
51
|
+
* notificationActivity: NotificationActivity,
|
|
52
|
+
* }
|
|
53
|
+
*
|
|
54
|
+
* // Initialize and start the worker
|
|
55
|
+
* await initTemporalWorker(app, {
|
|
56
|
+
* nodeTracerProvider,
|
|
57
|
+
* workflowsPath: require.resolve('./worker/workflows'),
|
|
58
|
+
* activities: workerActivities,
|
|
59
|
+
* })
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function initTemporalWorker(app: App, options: {
|
|
63
|
+
nodeTracerProvider: NodeTracerProvider;
|
|
64
|
+
workflowsPath: string;
|
|
65
|
+
activities: Record<string, ActivityClass>;
|
|
66
|
+
} & Omit<WorkerOptions, 'taskQueue' | 'activities' | 'workflowsPath'>): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Bootstraps and runs Temporal worker with graceful shutdown.
|
|
69
|
+
*
|
|
70
|
+
* Handles both in-process and separate-process worker topologies:
|
|
71
|
+
*
|
|
72
|
+
* - **In-process** (`workerInProcess` is `true` or unset): initializes and runs the worker.
|
|
73
|
+
* - **Separate process** (called from a dedicated worker entry with `configFactory`/`deps`):
|
|
74
|
+
* manages the full application lifecycle: setConfig → apply worker overrides → setDeps →
|
|
75
|
+
* initialize → start → run worker.
|
|
76
|
+
* - **Service-only** (`workerInProcess` is `false`, no `configFactory`): disables temporal
|
|
77
|
+
* scrapers on the main service (worker handles them separately) and returns immediately.
|
|
78
|
+
*
|
|
79
|
+
* Automatically integrates worker health with the app's centralized health check
|
|
80
|
+
* system via `HealthCheck.addHealthCheckable()`.
|
|
81
|
+
*
|
|
82
|
+
* @param app - App instance for DI container and config access
|
|
83
|
+
* @param options - Worker bootstrap options
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* // Separate worker process with full lifecycle management
|
|
88
|
+
* const app = new Application(serviceName, nodeTracerProvider, loggerConfig)
|
|
89
|
+
*
|
|
90
|
+
* await bootstrapWorker(app, {
|
|
91
|
+
* configFactory,
|
|
92
|
+
* deps,
|
|
93
|
+
* workflowsPath: require.resolve('./worker/workflows'),
|
|
94
|
+
* activities: workerActivities,
|
|
95
|
+
* nodeTracerProvider,
|
|
96
|
+
* })
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare function bootstrapWorker(app: App, options: WorkerBootstrapOptions): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Initializes Temporal worker.
|
|
102
|
+
*
|
|
103
|
+
* @param config - Application configuration
|
|
104
|
+
* @param options - Worker options including workflows path
|
|
105
|
+
* @param envService - Environment service instance
|
|
106
|
+
* @param logger - Logger instance (optional)
|
|
107
|
+
* @param nodeTracerProvider - OpenTelemetry tracer provider (optional)
|
|
108
|
+
* @param asyncLocalStorage - AsyncLocalStorage instance for tracing context (optional)
|
|
109
|
+
* @returns Configured Temporal worker
|
|
110
|
+
*/
|
|
111
|
+
export declare function initWorker({ temporal: temporalConfig, metrics: { custom: metricsConfig } }: AppConfig, options: Omit<WorkerOptions, 'taskQueue'> & {
|
|
112
|
+
taskQueue?: string;
|
|
113
|
+
}, envService: EnvService, logger?: Logger, nodeTracerProvider?: NodeTracerProvider, asyncLocalStorage?: AsyncLocalStorage<AlsData>): Promise<Worker>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { WorkerStatus } from '@temporalio/worker';
|
|
2
|
+
import { HealthCheckResult, OnHealthCheck } from '@diia-inhouse/types';
|
|
3
|
+
import { WorkerStatusProvider } from '../interfaces/services/worker';
|
|
4
|
+
export interface WorkerHealthDetails {
|
|
5
|
+
worker: WorkerStatus | 'NOT_INITIALIZED';
|
|
6
|
+
}
|
|
7
|
+
export declare class WorkerHealthService implements OnHealthCheck {
|
|
8
|
+
private statusProvider?;
|
|
9
|
+
setStatusProvider(provider: WorkerStatusProvider): void;
|
|
10
|
+
onHealthCheck(): Promise<HealthCheckResult<WorkerHealthDetails>>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export { defaultActivityInfo, MockActivityEnvironment, TestWorkflowEnvironment, TimeSkippingWorkflowClient, workflowInterceptorModules, } from '@temporalio/testing';
|
|
2
|
+
type ActivityMethods<T> = T extends {
|
|
3
|
+
prototype: infer P;
|
|
4
|
+
} ? {
|
|
5
|
+
[K in keyof P]?: P[K] extends (...args: any[]) => any ? (...args: Parameters<P[K]>) => ReturnType<P[K]> : never;
|
|
6
|
+
} : never;
|
|
7
|
+
/**
|
|
8
|
+
* Redefines instantiated activities for use in test environments.
|
|
9
|
+
*
|
|
10
|
+
* This function allows to override specific activity methods with mock implementations
|
|
11
|
+
* while preserving the overall activity structure.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Original activities object
|
|
15
|
+
* const activities = instantiateActivities(app, workerActivities)
|
|
16
|
+
*
|
|
17
|
+
* // Mock specific methods for testing
|
|
18
|
+
* const mockedActivities = {
|
|
19
|
+
* ...activities,
|
|
20
|
+
* ...mockActivities<typeof workerActivities>({
|
|
21
|
+
* user: {
|
|
22
|
+
* getProfile: async (userId) => ({ id: userId, name: 'Test User' }),
|
|
23
|
+
* },
|
|
24
|
+
* payment: {
|
|
25
|
+
* process: async () => ({ success: true, transactionId: 'mock-123' })
|
|
26
|
+
* }
|
|
27
|
+
* })
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // Using with test runner
|
|
32
|
+
* await runWorkflow({
|
|
33
|
+
* workflow: myWorkflow,
|
|
34
|
+
* args: [workflowInput],
|
|
35
|
+
* activities: mockedActivities
|
|
36
|
+
* })
|
|
37
|
+
*/
|
|
38
|
+
export declare function mockActivities<TActivities extends Record<string, {
|
|
39
|
+
prototype: unknown;
|
|
40
|
+
}>>(activities: {
|
|
41
|
+
[K in keyof TActivities]?: ActivityMethods<TActivities[K]>;
|
|
42
|
+
}): Record<string, (...args: unknown[]) => unknown>;
|
package/dist/worker.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Worker = exports.bundleWorkflowCode = exports.Runtime = exports.NativeConnection = void 0;
|
|
18
|
+
var worker_1 = require("@temporalio/worker");
|
|
19
|
+
Object.defineProperty(exports, "NativeConnection", { enumerable: true, get: function () { return worker_1.NativeConnection; } });
|
|
20
|
+
Object.defineProperty(exports, "Runtime", { enumerable: true, get: function () { return worker_1.Runtime; } });
|
|
21
|
+
Object.defineProperty(exports, "bundleWorkflowCode", { enumerable: true, get: function () { return worker_1.bundleWorkflowCode; } });
|
|
22
|
+
Object.defineProperty(exports, "Worker", { enumerable: true, get: function () { return worker_1.Worker; } });
|
|
23
|
+
__exportStar(require("./interceptors"), exports);
|
|
24
|
+
__exportStar(require("./services/worker"), exports);
|
|
25
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6CAS2B;AALvB,0GAAA,gBAAgB,OAAA;AAChB,iGAAA,OAAO,OAAA;AAEP,4GAAA,kBAAkB,OAAA;AAClB,gGAAA,MAAM,OAAA;AAGV,iDAA8B;AAE9B,oDAAiC"}
|