@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../src/interfaces/services/worker.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,77 @@
|
|
|
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.buildActivitiesProxy = exports.TemporalFailure = exports.TerminatedFailure = exports.CancelledFailure = exports.ActivityFailure = exports.TimeoutFailure = exports.ServerFailure = exports.ChildWorkflowFailure = exports.ApplicationFailure = exports.WorkflowError = exports.DeterminismViolationError = exports.getExternalWorkflowHandle = exports.Trigger = exports.CancellationScope = exports.inWorkflowContext = exports.proxySinks = exports.proxyLocalActivities = exports.proxyActivities = exports.scheduleLocalActivity = exports.scheduleActivity = exports.isCancellation = exports.uuid4 = exports.addDefaultWorkflowOptions = exports.deprecatePatch = exports.patched = exports.upsertSearchAttributes = exports.upsertMemo = exports.extractWorkflowType = exports.startChild = exports.executeChild = exports.defineUpdate = exports.defineSignal = exports.defineQuery = exports.setHandler = exports.sleep = exports.workflowMetadataQuery = exports.currentUpdateInfo = exports.workflowInfo = exports.log = exports.setDefaultSignalHandler = exports.ContinueAsNew = exports.makeContinueAsNewFunc = exports.continueAsNew = exports.condition = exports.allHandlersFinished = void 0;
|
|
18
|
+
exports.isNonRetryableFailure = isNonRetryableFailure;
|
|
19
|
+
const common_1 = require("@temporalio/common");
|
|
20
|
+
var workflow_1 = require("@temporalio/workflow");
|
|
21
|
+
Object.defineProperty(exports, "allHandlersFinished", { enumerable: true, get: function () { return workflow_1.allHandlersFinished; } });
|
|
22
|
+
Object.defineProperty(exports, "condition", { enumerable: true, get: function () { return workflow_1.condition; } });
|
|
23
|
+
Object.defineProperty(exports, "continueAsNew", { enumerable: true, get: function () { return workflow_1.continueAsNew; } });
|
|
24
|
+
Object.defineProperty(exports, "makeContinueAsNewFunc", { enumerable: true, get: function () { return workflow_1.makeContinueAsNewFunc; } });
|
|
25
|
+
Object.defineProperty(exports, "ContinueAsNew", { enumerable: true, get: function () { return workflow_1.ContinueAsNew; } });
|
|
26
|
+
Object.defineProperty(exports, "setDefaultSignalHandler", { enumerable: true, get: function () { return workflow_1.setDefaultSignalHandler; } });
|
|
27
|
+
Object.defineProperty(exports, "log", { enumerable: true, get: function () { return workflow_1.log; } });
|
|
28
|
+
Object.defineProperty(exports, "workflowInfo", { enumerable: true, get: function () { return workflow_1.workflowInfo; } });
|
|
29
|
+
Object.defineProperty(exports, "currentUpdateInfo", { enumerable: true, get: function () { return workflow_1.currentUpdateInfo; } });
|
|
30
|
+
Object.defineProperty(exports, "workflowMetadataQuery", { enumerable: true, get: function () { return workflow_1.workflowMetadataQuery; } });
|
|
31
|
+
Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return workflow_1.sleep; } });
|
|
32
|
+
Object.defineProperty(exports, "setHandler", { enumerable: true, get: function () { return workflow_1.setHandler; } });
|
|
33
|
+
Object.defineProperty(exports, "defineQuery", { enumerable: true, get: function () { return workflow_1.defineQuery; } });
|
|
34
|
+
Object.defineProperty(exports, "defineSignal", { enumerable: true, get: function () { return workflow_1.defineSignal; } });
|
|
35
|
+
Object.defineProperty(exports, "defineUpdate", { enumerable: true, get: function () { return workflow_1.defineUpdate; } });
|
|
36
|
+
Object.defineProperty(exports, "executeChild", { enumerable: true, get: function () { return workflow_1.executeChild; } });
|
|
37
|
+
Object.defineProperty(exports, "startChild", { enumerable: true, get: function () { return workflow_1.startChild; } });
|
|
38
|
+
Object.defineProperty(exports, "extractWorkflowType", { enumerable: true, get: function () { return workflow_1.extractWorkflowType; } });
|
|
39
|
+
Object.defineProperty(exports, "upsertMemo", { enumerable: true, get: function () { return workflow_1.upsertMemo; } });
|
|
40
|
+
Object.defineProperty(exports, "upsertSearchAttributes", { enumerable: true, get: function () { return workflow_1.upsertSearchAttributes; } });
|
|
41
|
+
Object.defineProperty(exports, "patched", { enumerable: true, get: function () { return workflow_1.patched; } });
|
|
42
|
+
Object.defineProperty(exports, "deprecatePatch", { enumerable: true, get: function () { return workflow_1.deprecatePatch; } });
|
|
43
|
+
Object.defineProperty(exports, "addDefaultWorkflowOptions", { enumerable: true, get: function () { return workflow_1.addDefaultWorkflowOptions; } });
|
|
44
|
+
Object.defineProperty(exports, "uuid4", { enumerable: true, get: function () { return workflow_1.uuid4; } });
|
|
45
|
+
Object.defineProperty(exports, "isCancellation", { enumerable: true, get: function () { return workflow_1.isCancellation; } });
|
|
46
|
+
Object.defineProperty(exports, "scheduleActivity", { enumerable: true, get: function () { return workflow_1.scheduleActivity; } });
|
|
47
|
+
Object.defineProperty(exports, "scheduleLocalActivity", { enumerable: true, get: function () { return workflow_1.scheduleLocalActivity; } });
|
|
48
|
+
Object.defineProperty(exports, "proxyActivities", { enumerable: true, get: function () { return workflow_1.proxyActivities; } });
|
|
49
|
+
Object.defineProperty(exports, "proxyLocalActivities", { enumerable: true, get: function () { return workflow_1.proxyLocalActivities; } });
|
|
50
|
+
Object.defineProperty(exports, "proxySinks", { enumerable: true, get: function () { return workflow_1.proxySinks; } });
|
|
51
|
+
Object.defineProperty(exports, "inWorkflowContext", { enumerable: true, get: function () { return workflow_1.inWorkflowContext; } });
|
|
52
|
+
Object.defineProperty(exports, "CancellationScope", { enumerable: true, get: function () { return workflow_1.CancellationScope; } });
|
|
53
|
+
Object.defineProperty(exports, "Trigger", { enumerable: true, get: function () { return workflow_1.Trigger; } });
|
|
54
|
+
Object.defineProperty(exports, "getExternalWorkflowHandle", { enumerable: true, get: function () { return workflow_1.getExternalWorkflowHandle; } });
|
|
55
|
+
Object.defineProperty(exports, "DeterminismViolationError", { enumerable: true, get: function () { return workflow_1.DeterminismViolationError; } });
|
|
56
|
+
Object.defineProperty(exports, "WorkflowError", { enumerable: true, get: function () { return workflow_1.WorkflowError; } });
|
|
57
|
+
Object.defineProperty(exports, "ApplicationFailure", { enumerable: true, get: function () { return workflow_1.ApplicationFailure; } });
|
|
58
|
+
Object.defineProperty(exports, "ChildWorkflowFailure", { enumerable: true, get: function () { return workflow_1.ChildWorkflowFailure; } });
|
|
59
|
+
Object.defineProperty(exports, "ServerFailure", { enumerable: true, get: function () { return workflow_1.ServerFailure; } });
|
|
60
|
+
Object.defineProperty(exports, "TimeoutFailure", { enumerable: true, get: function () { return workflow_1.TimeoutFailure; } });
|
|
61
|
+
Object.defineProperty(exports, "ActivityFailure", { enumerable: true, get: function () { return workflow_1.ActivityFailure; } });
|
|
62
|
+
Object.defineProperty(exports, "CancelledFailure", { enumerable: true, get: function () { return workflow_1.CancelledFailure; } });
|
|
63
|
+
Object.defineProperty(exports, "TerminatedFailure", { enumerable: true, get: function () { return workflow_1.TerminatedFailure; } });
|
|
64
|
+
Object.defineProperty(exports, "TemporalFailure", { enumerable: true, get: function () { return workflow_1.TemporalFailure; } });
|
|
65
|
+
var activities_1 = require("./activities");
|
|
66
|
+
Object.defineProperty(exports, "buildActivitiesProxy", { enumerable: true, get: function () { return activities_1.buildActivitiesProxy; } });
|
|
67
|
+
__exportStar(require("./interceptors"), exports);
|
|
68
|
+
function isNonRetryableFailure(err) {
|
|
69
|
+
if (!(err instanceof common_1.ActivityFailure)) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
if (err.retryState === common_1.RetryState.RETRY_POLICY_NOT_SET || err.retryState === common_1.RetryState.MAXIMUM_ATTEMPTS_REACHED) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return err.cause instanceof common_1.ApplicationFailure && Boolean(err.cause.nonRetryable);
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.js","sourceRoot":"","sources":["../src/operations.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AA4DA,sDAUC;AAtED,+CAAoF;AAEpF,iDAoD6B;AAnDzB,+GAAA,mBAAmB,OAAA;AACnB,qGAAA,SAAS,OAAA;AACT,yGAAA,aAAa,OAAA;AACb,iHAAA,qBAAqB,OAAA;AACrB,yGAAA,aAAa,OAAA;AAEb,mHAAA,uBAAuB,OAAA;AACvB,+FAAA,GAAG,OAAA;AACH,wGAAA,YAAY,OAAA;AAEZ,6GAAA,iBAAiB,OAAA;AACjB,iHAAA,qBAAqB,OAAA;AACrB,iGAAA,KAAK,OAAA;AACL,sGAAA,UAAU,OAAA;AACV,uGAAA,WAAW,OAAA;AACX,wGAAA,YAAY,OAAA;AACZ,wGAAA,YAAY,OAAA;AACZ,wGAAA,YAAY,OAAA;AACZ,sGAAA,UAAU,OAAA;AAGV,+GAAA,mBAAmB,OAAA;AACnB,sGAAA,UAAU,OAAA;AACV,kHAAA,sBAAsB,OAAA;AACtB,mGAAA,OAAO,OAAA;AACP,0GAAA,cAAc,OAAA;AACd,qHAAA,yBAAyB,OAAA;AACzB,iGAAA,KAAK,OAAA;AACL,0GAAA,cAAc,OAAA;AAEd,4GAAA,gBAAgB,OAAA;AAChB,iHAAA,qBAAqB,OAAA;AACrB,2GAAA,eAAe,OAAA;AACf,gHAAA,oBAAoB,OAAA;AACpB,sGAAA,UAAU,OAAA;AACV,6GAAA,iBAAiB,OAAA;AACjB,6GAAA,iBAAiB,OAAA;AAGjB,mGAAA,OAAO,OAAA;AACP,qHAAA,yBAAyB,OAAA;AACzB,qHAAA,yBAAyB,OAAA;AACzB,yGAAA,aAAa,OAAA;AACb,8GAAA,kBAAkB,OAAA;AAClB,gHAAA,oBAAoB,OAAA;AACpB,yGAAA,aAAa,OAAA;AACb,0GAAA,cAAc,OAAA;AACd,2GAAA,eAAe,OAAA;AACf,4GAAA,gBAAgB,OAAA;AAChB,6GAAA,iBAAiB,OAAA;AACjB,2GAAA,eAAe,OAAA;AAGnB,2CAAmD;AAA1C,kHAAA,oBAAoB,OAAA;AAE7B,iDAA8B;AAE9B,SAAgB,qBAAqB,CAAC,GAAY;IAC9C,IAAI,CAAC,CAAC,GAAG,YAAY,wBAAe,CAAC,EAAE,CAAC;QACpC,OAAO,KAAK,CAAA;IAChB,CAAC;IAED,IAAI,GAAG,CAAC,UAAU,KAAK,mBAAU,CAAC,oBAAoB,IAAI,GAAG,CAAC,UAAU,KAAK,mBAAU,CAAC,wBAAwB,EAAE,CAAC;QAC/G,OAAO,IAAI,CAAA;IACf,CAAC;IAED,OAAO,GAAG,CAAC,KAAK,YAAY,2BAAkB,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;AACrF,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TemporalClient = void 0;
|
|
4
|
+
const client_1 = require("@temporalio/client");
|
|
5
|
+
const client_2 = require("@temporalio/interceptors-opentelemetry/lib/client");
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
const env_1 = require("@diia-inhouse/env");
|
|
8
|
+
const dataConverter_1 = require("../encryption/dataConverter");
|
|
9
|
+
class TemporalClient {
|
|
10
|
+
config;
|
|
11
|
+
envService;
|
|
12
|
+
logger;
|
|
13
|
+
nativeClient;
|
|
14
|
+
defaultTimezone = 'Europe/Kyiv';
|
|
15
|
+
constructor(config, envService, logger) {
|
|
16
|
+
this.config = config;
|
|
17
|
+
this.envService = envService;
|
|
18
|
+
this.logger = logger;
|
|
19
|
+
}
|
|
20
|
+
get connection() {
|
|
21
|
+
return this.nativeClient.connection;
|
|
22
|
+
}
|
|
23
|
+
get workflow() {
|
|
24
|
+
return this.nativeClient.workflow;
|
|
25
|
+
}
|
|
26
|
+
get workflowService() {
|
|
27
|
+
return this.nativeClient.workflowService;
|
|
28
|
+
}
|
|
29
|
+
get schedule() {
|
|
30
|
+
return this.nativeClient.schedule;
|
|
31
|
+
}
|
|
32
|
+
get taskQueue() {
|
|
33
|
+
return this.nativeClient.taskQueue;
|
|
34
|
+
}
|
|
35
|
+
async onInit() {
|
|
36
|
+
const { address, tls, connectTimeout, encryptionEnabled, encryptionKeyId, encryptionKeyRefreshInterval, ...clientConfig } = this.config;
|
|
37
|
+
const connection = await client_1.Connection.connect({ address, tls, connectTimeout }).catch((err) => {
|
|
38
|
+
this.logger.error('Failed to connect to Temporal', { err });
|
|
39
|
+
throw new Error('Failed to connect to Temporal', { cause: err });
|
|
40
|
+
});
|
|
41
|
+
const dataConverter = encryptionEnabled
|
|
42
|
+
? await (0, dataConverter_1.getDataConverter)(encryptionKeyId, this.envService, encryptionKeyRefreshInterval)
|
|
43
|
+
: undefined;
|
|
44
|
+
const interceptors = env_1.EnvService.getVar('TRACING_ENABLED', 'boolean', false)
|
|
45
|
+
? { workflow: [new client_2.OpenTelemetryWorkflowClientInterceptor()] }
|
|
46
|
+
: undefined;
|
|
47
|
+
this.nativeClient = new client_1.Client({ ...clientConfig, connection, dataConverter, interceptors });
|
|
48
|
+
}
|
|
49
|
+
async syncSchedules(schedules) {
|
|
50
|
+
const applicationSchedules = Object.entries(schedules).map(([, schedule]) => typeof schedule === 'function' ? schedule(this.config) : schedule);
|
|
51
|
+
const temporalSchedules = [];
|
|
52
|
+
for await (const schedule of this.schedule.list()) {
|
|
53
|
+
if (schedule.memo?.TaskQueue === this.config.taskQueue) {
|
|
54
|
+
temporalSchedules.push(schedule);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const schedulesToCreate = applicationSchedules.filter((scheduleOptions) => !temporalSchedules.some((schedule) => schedule.scheduleId === scheduleOptions.scheduleId));
|
|
58
|
+
for (const scheduleOptions of schedulesToCreate) {
|
|
59
|
+
scheduleOptions.memo = {
|
|
60
|
+
...scheduleOptions.memo,
|
|
61
|
+
TaskQueue: scheduleOptions.action.taskQueue,
|
|
62
|
+
};
|
|
63
|
+
if (!scheduleOptions.spec.timezone) {
|
|
64
|
+
scheduleOptions.spec.timezone = this.defaultTimezone;
|
|
65
|
+
}
|
|
66
|
+
await this.schedule.create(scheduleOptions);
|
|
67
|
+
}
|
|
68
|
+
if (schedulesToCreate.length > 0) {
|
|
69
|
+
this.logger.info(`Schedules created (${schedulesToCreate.length}): ${schedulesToCreate.map((schedule) => schedule.scheduleId).join(', ')}`);
|
|
70
|
+
}
|
|
71
|
+
const schedulesToDelete = temporalSchedules.filter((schedule) => !applicationSchedules.some((scheduleOptions) => scheduleOptions.scheduleId === schedule.scheduleId));
|
|
72
|
+
for (const schedule of schedulesToDelete) {
|
|
73
|
+
const handle = this.schedule.getHandle(schedule.scheduleId);
|
|
74
|
+
await handle.delete();
|
|
75
|
+
}
|
|
76
|
+
if (schedulesToDelete.length > 0) {
|
|
77
|
+
this.logger.info(`Schedules deleted (${schedulesToDelete.length}): ${schedulesToDelete.map((schedule) => schedule.scheduleId).join(', ')}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async updateSchedule(scheduleId, updateData) {
|
|
81
|
+
try {
|
|
82
|
+
const scheduleHandle = this.schedule.getHandle(scheduleId);
|
|
83
|
+
this.logger.info('Schedule update details:', { scheduleId, updateData });
|
|
84
|
+
await scheduleHandle.update((previous) => {
|
|
85
|
+
return (0, lodash_1.merge)(previous, updateData);
|
|
86
|
+
});
|
|
87
|
+
this.logger.info('Successfully updated temporal schedule', { scheduleId });
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
this.logger.error('Failed to update temporal schedule', { err });
|
|
91
|
+
throw err;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.TemporalClient = TemporalClient;
|
|
96
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/services/client.ts"],"names":[],"mappings":";;;AAAA,+CAQ2B;AAC3B,8EAA0G;AAC1G,mCAA8B;AAE9B,2CAA8C;AAG9C,+DAA8D;AAG9D,MAAa,cAAc;IAMF;IACA;IACA;IAPrB,YAAY,CAAS;IAEJ,eAAe,GAAG,aAAa,CAAA;IAEhD,YACqB,MAAsB,EACtB,UAAsB,EACtB,MAAc;QAFd,WAAM,GAAN,MAAM,CAAgB;QACtB,eAAU,GAAV,UAAU,CAAY;QACtB,WAAM,GAAN,MAAM,CAAQ;IAChC,CAAC;IAEJ,IAAI,UAAU;QACV,OAAO,IAAI,CAAC,YAAY,CAAC,UAAU,CAAA;IACvC,CAAC;IAED,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAA;IACrC,CAAC;IAED,IAAI,eAAe;QACf,OAAO,IAAI,CAAC,YAAY,CAAC,eAAe,CAAA;IAC5C,CAAC;IAED,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAA;IACrC,CAAC;IAED,IAAI,SAAS;QACT,OAAO,IAAI,CAAC,YAAY,CAAC,SAAS,CAAA;IACtC,CAAC;IAED,KAAK,CAAC,MAAM;QACR,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,iBAAiB,EAAE,eAAe,EAAE,4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,CAAC;CACJ;AAvHD,wCAuHC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
__exportStar(require("./client"), exports);
|
|
18
|
+
__exportStar(require("./worker"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AAExB,2CAAwB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildWorkerIdentity = buildWorkerIdentity;
|
|
4
|
+
const node_os_1 = require("node:os");
|
|
5
|
+
function buildWorkerIdentity(taskQueue, identityOverride) {
|
|
6
|
+
if (identityOverride) {
|
|
7
|
+
return identityOverride;
|
|
8
|
+
}
|
|
9
|
+
return `${(0, node_os_1.hostname)()}-${process.pid}-${taskQueue}`;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../../../src/services/worker/identity.ts"],"names":[],"mappings":";;AAEA,kDAMC;AARD,qCAAkC;AAElC,SAAgB,mBAAmB,CAAC,SAAiB,EAAE,gBAAyB;IAC5E,IAAI,gBAAgB,EAAE,CAAC;QACnB,OAAO,gBAAgB,CAAA;IAC3B,CAAC;IAED,OAAO,GAAG,IAAA,kBAAQ,GAAE,IAAI,OAAO,CAAC,GAAG,IAAI,SAAS,EAAE,CAAA;AACtD,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
__exportStar(require("./identity"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/worker/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA0B"}
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkerHealthService = exports.buildWorkerIdentity = void 0;
|
|
4
|
+
exports.applyServiceProcessConfig = applyServiceProcessConfig;
|
|
5
|
+
exports.applyWorkerProcessConfig = applyWorkerProcessConfig;
|
|
6
|
+
exports.instantiateActivities = instantiateActivities;
|
|
7
|
+
exports.initTemporalWorker = initTemporalWorker;
|
|
8
|
+
exports.bootstrapWorker = bootstrapWorker;
|
|
9
|
+
exports.initWorker = initWorker;
|
|
10
|
+
const resources_1 = require("@opentelemetry/resources");
|
|
11
|
+
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
12
|
+
const worker_1 = require("@temporalio/interceptors-opentelemetry/lib/worker");
|
|
13
|
+
const worker_2 = require("@temporalio/worker");
|
|
14
|
+
const env_1 = require("@diia-inhouse/env");
|
|
15
|
+
const encryption_1 = require("../encryption");
|
|
16
|
+
const instrumentation_1 = require("../instrumentation");
|
|
17
|
+
const asyncLocalStorageBridge_1 = require("../interceptors/asyncLocalStorageBridge");
|
|
18
|
+
const identity_1 = require("./worker/identity");
|
|
19
|
+
const workerHealth_1 = require("./workerHealth");
|
|
20
|
+
var identity_2 = require("./worker/identity");
|
|
21
|
+
Object.defineProperty(exports, "buildWorkerIdentity", { enumerable: true, get: function () { return identity_2.buildWorkerIdentity; } });
|
|
22
|
+
var workerHealth_2 = require("./workerHealth");
|
|
23
|
+
Object.defineProperty(exports, "WorkerHealthService", { enumerable: true, get: function () { return workerHealth_2.WorkerHealthService; } });
|
|
24
|
+
/**
|
|
25
|
+
* Applies service process configuration overrides when the worker runs separately.
|
|
26
|
+
*
|
|
27
|
+
* When `temporal.workerInProcess` is `false`, disables `temporal` and `temporal-worker` scrapers
|
|
28
|
+
* so the main service does not scrape metrics that the worker process handles.
|
|
29
|
+
*
|
|
30
|
+
* Mutates the config object in place. Safe to call when scrapers are absent.
|
|
31
|
+
*/
|
|
32
|
+
function applyServiceProcessConfig(config) {
|
|
33
|
+
const { workerInProcess = true } = config.temporal;
|
|
34
|
+
if (workerInProcess) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
for (const scraper of config.metrics.custom.scrapers ?? []) {
|
|
38
|
+
if (scraper.name === 'temporal' || scraper.name === 'temporal-worker') {
|
|
39
|
+
scraper.disabled = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Applies worker process configuration overrides.
|
|
45
|
+
*
|
|
46
|
+
* - Disables queue consumers on all rabbit connections (unless `temporal.disableQueueConsumers` is `false`)
|
|
47
|
+
* - Overrides `metrics.custom.port` with the `'temporal-worker'` scraper port and disables that scraper to prevent self-scraping
|
|
48
|
+
*
|
|
49
|
+
* Mutates the config object in place. Safe to call when queue config is absent.
|
|
50
|
+
*/
|
|
51
|
+
function applyWorkerProcessConfig(config) {
|
|
52
|
+
const { disableQueueConsumers = true } = config.temporal;
|
|
53
|
+
if (disableQueueConsumers && config.rabbit) {
|
|
54
|
+
for (const value of Object.values(config.rabbit)) {
|
|
55
|
+
if (value && typeof value === 'object' && 'consumerEnabled' in value) {
|
|
56
|
+
value.consumerEnabled = false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const workerScraper = config.metrics.custom.scrapers?.find((s) => s.name === 'temporal-worker');
|
|
61
|
+
if (workerScraper?.port !== undefined) {
|
|
62
|
+
config.metrics.custom.port = workerScraper.port;
|
|
63
|
+
workerScraper.disabled = true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Builds worker interceptors with OpenTelemetry and AsyncLocalStorage support.
|
|
68
|
+
* OpenTelemetry creates span first, then AsyncLocalStorage bridge extracts traceId.
|
|
69
|
+
*/
|
|
70
|
+
function buildWorkerInterceptors(tracingEnabled, asyncLocalStorage, logger, workflowsPath) {
|
|
71
|
+
if (tracingEnabled) {
|
|
72
|
+
return {
|
|
73
|
+
activity: [
|
|
74
|
+
(ctx) => ({
|
|
75
|
+
inbound: new worker_1.OpenTelemetryActivityInboundInterceptor(ctx),
|
|
76
|
+
outbound: new worker_1.OpenTelemetryActivityOutboundInterceptor(ctx),
|
|
77
|
+
}),
|
|
78
|
+
...(asyncLocalStorage && logger
|
|
79
|
+
? [
|
|
80
|
+
(ctx) => ({
|
|
81
|
+
inbound: new asyncLocalStorageBridge_1.AsyncLocalStorageBridgeInterceptor(ctx, asyncLocalStorage, logger),
|
|
82
|
+
}),
|
|
83
|
+
]
|
|
84
|
+
: []),
|
|
85
|
+
],
|
|
86
|
+
workflowModules: workflowsPath ? [workflowsPath] : [],
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (asyncLocalStorage && logger) {
|
|
90
|
+
return {
|
|
91
|
+
activity: [
|
|
92
|
+
(ctx) => ({
|
|
93
|
+
inbound: new asyncLocalStorageBridge_1.AsyncLocalStorageBridgeInterceptor(ctx, asyncLocalStorage, logger),
|
|
94
|
+
outbound: new worker_1.OpenTelemetryActivityOutboundInterceptor(ctx),
|
|
95
|
+
}),
|
|
96
|
+
],
|
|
97
|
+
workflowModules: workflowsPath ? [workflowsPath] : [],
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Merges built-in interceptors with custom interceptors from options.
|
|
104
|
+
*/
|
|
105
|
+
function mergeInterceptors(builtIn, custom) {
|
|
106
|
+
if (!builtIn && !custom) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
activity: [...(builtIn?.activity || []), ...(custom?.activity || [])],
|
|
111
|
+
workflowModules: [...(builtIn?.workflowModules || []), ...(custom?.workflowModules || [])],
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function buildActivities(app, activities) {
|
|
115
|
+
const instances = {};
|
|
116
|
+
for (const [key, value] of Object.entries(activities)) {
|
|
117
|
+
instances[key] = app.container.build(value);
|
|
118
|
+
}
|
|
119
|
+
return instances;
|
|
120
|
+
}
|
|
121
|
+
function bindActivities(key, instance) {
|
|
122
|
+
const methods = Object.getOwnPropertyNames(Object.getPrototypeOf(instance)).filter((name) => name !== 'constructor');
|
|
123
|
+
const boundActivities = {};
|
|
124
|
+
for (const method of methods) {
|
|
125
|
+
const fn = instance[method];
|
|
126
|
+
const token = `${key}.${String(method)}`;
|
|
127
|
+
boundActivities[token] = fn.bind(instance);
|
|
128
|
+
}
|
|
129
|
+
return boundActivities;
|
|
130
|
+
}
|
|
131
|
+
function instantiateActivities(app, workerActivities) {
|
|
132
|
+
const activitiesInstances = buildActivities(app, workerActivities);
|
|
133
|
+
const activities = {};
|
|
134
|
+
for (const [key, value] of Object.entries(activitiesInstances)) {
|
|
135
|
+
Object.assign(activities, bindActivities(key, value));
|
|
136
|
+
}
|
|
137
|
+
return activities;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Initializes and starts Temporal worker with full dependency injection support.
|
|
141
|
+
*
|
|
142
|
+
* This is the recommended way to initialize Temporal workers. It handles:
|
|
143
|
+
* - Automatic dependency injection for activities
|
|
144
|
+
* - AsyncLocalStorage setup for distributed tracing
|
|
145
|
+
* - OpenTelemetry integration
|
|
146
|
+
* - Activity instantiation and binding
|
|
147
|
+
*
|
|
148
|
+
* @param app - App instance for DI container and config access
|
|
149
|
+
* @param options - Worker configuration options
|
|
150
|
+
* @param options.nodeTracerProvider - OpenTelemetry tracer provider
|
|
151
|
+
* @param options.workflowsPath - Path to workflows module
|
|
152
|
+
* @param options.activities - Activity classes to instantiate
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* // Define your activities
|
|
157
|
+
* const workerActivities = {
|
|
158
|
+
* userActivity: UserActivity,
|
|
159
|
+
* notificationActivity: NotificationActivity,
|
|
160
|
+
* }
|
|
161
|
+
*
|
|
162
|
+
* // Initialize and start the worker
|
|
163
|
+
* await initTemporalWorker(app, {
|
|
164
|
+
* nodeTracerProvider,
|
|
165
|
+
* workflowsPath: require.resolve('./worker/workflows'),
|
|
166
|
+
* activities: workerActivities,
|
|
167
|
+
* })
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
async function initTemporalWorker(app, options) {
|
|
171
|
+
const config = app.getConfig?.();
|
|
172
|
+
const { nodeTracerProvider, workflowsPath, activities, ...workerOptions } = options;
|
|
173
|
+
const envService = app.container.resolve('envService');
|
|
174
|
+
const logger = app.container.resolve('logger');
|
|
175
|
+
const asyncLocalStorage = app.container.resolve('asyncLocalStorage');
|
|
176
|
+
const instantiatedActivities = instantiateActivities(app, activities);
|
|
177
|
+
const worker = await initWorker(config, { ...workerOptions, workflowsPath, activities: instantiatedActivities }, envService, logger, nodeTracerProvider, asyncLocalStorage);
|
|
178
|
+
await worker.run();
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Bootstraps and runs Temporal worker with graceful shutdown.
|
|
182
|
+
*
|
|
183
|
+
* Handles both in-process and separate-process worker topologies:
|
|
184
|
+
*
|
|
185
|
+
* - **In-process** (`workerInProcess` is `true` or unset): initializes and runs the worker.
|
|
186
|
+
* - **Separate process** (called from a dedicated worker entry with `configFactory`/`deps`):
|
|
187
|
+
* manages the full application lifecycle: setConfig → apply worker overrides → setDeps →
|
|
188
|
+
* initialize → start → run worker.
|
|
189
|
+
* - **Service-only** (`workerInProcess` is `false`, no `configFactory`): disables temporal
|
|
190
|
+
* scrapers on the main service (worker handles them separately) and returns immediately.
|
|
191
|
+
*
|
|
192
|
+
* Automatically integrates worker health with the app's centralized health check
|
|
193
|
+
* system via `HealthCheck.addHealthCheckable()`.
|
|
194
|
+
*
|
|
195
|
+
* @param app - App instance for DI container and config access
|
|
196
|
+
* @param options - Worker bootstrap options
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* // Separate worker process with full lifecycle management
|
|
201
|
+
* const app = new Application(serviceName, nodeTracerProvider, loggerConfig)
|
|
202
|
+
*
|
|
203
|
+
* await bootstrapWorker(app, {
|
|
204
|
+
* configFactory,
|
|
205
|
+
* deps,
|
|
206
|
+
* workflowsPath: require.resolve('./worker/workflows'),
|
|
207
|
+
* activities: workerActivities,
|
|
208
|
+
* nodeTracerProvider,
|
|
209
|
+
* })
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
async function bootstrapWorker(app, options) {
|
|
213
|
+
const { configFactory, deps, workflowsPath, activities, nodeTracerProvider, shutdownSignals = ['SIGTERM', 'SIGINT'], ...workerOptions } = options;
|
|
214
|
+
if (configFactory && deps) {
|
|
215
|
+
await app.setConfig(configFactory);
|
|
216
|
+
applyWorkerProcessConfig(app.getConfig());
|
|
217
|
+
await app.setDeps(deps);
|
|
218
|
+
const appOperator = await app.initialize();
|
|
219
|
+
await appOperator.start();
|
|
220
|
+
}
|
|
221
|
+
const config = app.getConfig?.();
|
|
222
|
+
if (!configFactory && config.temporal.workerInProcess === false) {
|
|
223
|
+
applyServiceProcessConfig(config);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const envService = app.container.resolve('envService');
|
|
227
|
+
const logger = app.container.resolve('logger');
|
|
228
|
+
const asyncLocalStorage = app.container.resolve('asyncLocalStorage');
|
|
229
|
+
const taskQueue = config.temporal.taskQueue;
|
|
230
|
+
const identity = (0, identity_1.buildWorkerIdentity)(taskQueue, workerOptions.identity);
|
|
231
|
+
const instantiatedActivities = instantiateActivities(app, activities);
|
|
232
|
+
const worker = await initWorker(config, {
|
|
233
|
+
...workerOptions,
|
|
234
|
+
workflowsPath,
|
|
235
|
+
activities: instantiatedActivities,
|
|
236
|
+
identity,
|
|
237
|
+
}, envService, logger, nodeTracerProvider, asyncLocalStorage);
|
|
238
|
+
logger.info('Starting Temporal worker', { taskQueue, identity });
|
|
239
|
+
const healthCheck = tryResolve(app.container, 'healthCheck');
|
|
240
|
+
if (healthCheck) {
|
|
241
|
+
const workerHealthService = new workerHealth_1.WorkerHealthService();
|
|
242
|
+
workerHealthService.setStatusProvider(() => worker.getStatus());
|
|
243
|
+
healthCheck.addHealthCheckable(workerHealthService);
|
|
244
|
+
}
|
|
245
|
+
const signalHandler = () => {
|
|
246
|
+
worker.shutdown();
|
|
247
|
+
};
|
|
248
|
+
for (const signal of shutdownSignals) {
|
|
249
|
+
process.once(signal, signalHandler);
|
|
250
|
+
}
|
|
251
|
+
try {
|
|
252
|
+
await worker.run();
|
|
253
|
+
}
|
|
254
|
+
finally {
|
|
255
|
+
for (const signal of shutdownSignals) {
|
|
256
|
+
process.off(signal, signalHandler);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function tryResolve(container, key) {
|
|
261
|
+
try {
|
|
262
|
+
return container.resolve(key);
|
|
263
|
+
}
|
|
264
|
+
catch {
|
|
265
|
+
return undefined;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Initializes Temporal worker.
|
|
270
|
+
*
|
|
271
|
+
* @param config - Application configuration
|
|
272
|
+
* @param options - Worker options including workflows path
|
|
273
|
+
* @param envService - Environment service instance
|
|
274
|
+
* @param logger - Logger instance (optional)
|
|
275
|
+
* @param nodeTracerProvider - OpenTelemetry tracer provider (optional)
|
|
276
|
+
* @param asyncLocalStorage - AsyncLocalStorage instance for tracing context (optional)
|
|
277
|
+
* @returns Configured Temporal worker
|
|
278
|
+
*/
|
|
279
|
+
async function initWorker({ temporal: temporalConfig, metrics: { custom: metricsConfig } }, options, envService, logger, nodeTracerProvider, asyncLocalStorage) {
|
|
280
|
+
const { encryptionEnabled, encryptionKeyId, encryptionKeyRefreshInterval, namespace = 'default', address, taskQueue } = temporalConfig;
|
|
281
|
+
const runtimeParams = {};
|
|
282
|
+
if (logger) {
|
|
283
|
+
runtimeParams.logger = logger.child({ taskQueue });
|
|
284
|
+
}
|
|
285
|
+
const temporalMetrics = metricsConfig.scrapers?.find((s) => s.name === 'temporal');
|
|
286
|
+
if (temporalMetrics && !temporalMetrics.disabled) {
|
|
287
|
+
runtimeParams.telemetryOptions = {
|
|
288
|
+
metrics: {
|
|
289
|
+
prometheus: {
|
|
290
|
+
bindAddress: `0.0.0.0:${temporalMetrics.port}`,
|
|
291
|
+
useSecondsForDurations: true,
|
|
292
|
+
countersTotalSuffix: true,
|
|
293
|
+
unitSuffix: true,
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
worker_2.Runtime.install(runtimeParams);
|
|
299
|
+
const resource = new resources_1.Resource({
|
|
300
|
+
[semantic_conventions_1.ATTR_SERVICE_NAME]: nodeTracerProvider?.resource.attributes[semantic_conventions_1.ATTR_SERVICE_NAME],
|
|
301
|
+
});
|
|
302
|
+
const tracingEnabled = env_1.EnvService.getVar('TRACING_ENABLED', 'boolean', false);
|
|
303
|
+
const builtInInterceptors = buildWorkerInterceptors(tracingEnabled, asyncLocalStorage, logger, options.workflowsPath);
|
|
304
|
+
const mergedInterceptors = mergeInterceptors(builtInInterceptors, options.interceptors);
|
|
305
|
+
try {
|
|
306
|
+
const worker = await worker_2.Worker.create({
|
|
307
|
+
namespace,
|
|
308
|
+
taskQueue,
|
|
309
|
+
connection: await worker_2.NativeConnection.connect({ address }),
|
|
310
|
+
dataConverter: encryptionEnabled
|
|
311
|
+
? await (0, encryption_1.getDataConverter)(encryptionKeyId, envService, encryptionKeyRefreshInterval)
|
|
312
|
+
: undefined,
|
|
313
|
+
...options,
|
|
314
|
+
sinks: tracingEnabled ? { exporter: (0, worker_1.makeWorkflowExporter)(instrumentation_1.traceExporter, resource) } : undefined,
|
|
315
|
+
interceptors: mergedInterceptors,
|
|
316
|
+
});
|
|
317
|
+
return worker;
|
|
318
|
+
}
|
|
319
|
+
catch (err) {
|
|
320
|
+
logger?.error('Failed to create Temporal worker', { err });
|
|
321
|
+
throw new Error('Failed to create Temporal worker', { cause: err });
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
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E1D,MAAM,IAAI,KAAK,CAAC,kCAAkC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAA;IACvE,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkerHealthService = void 0;
|
|
4
|
+
const types_1 = require("@diia-inhouse/types");
|
|
5
|
+
function isPollerHealthy(state) {
|
|
6
|
+
return state === 'POLLING';
|
|
7
|
+
}
|
|
8
|
+
function isWorkerHealthy(status) {
|
|
9
|
+
const { runState, workflowPollerState, activityPollerState } = status;
|
|
10
|
+
if (runState !== 'RUNNING') {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
if (!isPollerHealthy(workflowPollerState) || !isPollerHealthy(activityPollerState)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
class WorkerHealthService {
|
|
19
|
+
statusProvider;
|
|
20
|
+
setStatusProvider(provider) {
|
|
21
|
+
this.statusProvider = provider;
|
|
22
|
+
}
|
|
23
|
+
async onHealthCheck() {
|
|
24
|
+
if (!this.statusProvider) {
|
|
25
|
+
return {
|
|
26
|
+
status: types_1.HttpStatusCode.SERVICE_UNAVAILABLE,
|
|
27
|
+
details: { worker: 'NOT_INITIALIZED' },
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const workerStatus = this.statusProvider();
|
|
31
|
+
const isHealthy = isWorkerHealthy(workerStatus);
|
|
32
|
+
return {
|
|
33
|
+
status: isHealthy ? types_1.HttpStatusCode.OK : types_1.HttpStatusCode.SERVICE_UNAVAILABLE,
|
|
34
|
+
details: { worker: workerStatus },
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.WorkerHealthService = WorkerHealthService;
|
|
39
|
+
//# sourceMappingURL=workerHealth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workerHealth.js","sourceRoot":"","sources":["../../src/services/workerHealth.ts"],"names":[],"mappings":";;;AAGA,+CAAsF;AAQtF,SAAS,eAAe,CAAC,KAAkB;IACvC,OAAO,KAAK,KAAK,SAAS,CAAA;AAC9B,CAAC;AAED,SAAS,eAAe,CAAC,MAAoB;IACzC,MAAM,EAAE,QAAQ,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,GAAG,MAAM,CAAA;IAErE,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,KAAK,CAAA;IAChB,CAAC;IAED,IAAI,CAAC,eAAe,CAAC,mBAAmB,CAAC,IAAI,CAAC,eAAe,CAAC,mBAAmB,CAAC,EAAE,CAAC;QACjF,OAAO,KAAK,CAAA;IAChB,CAAC;IAED,OAAO,IAAI,CAAA;AACf,CAAC;AAED,MAAa,mBAAmB;IACpB,cAAc,CAAuB;IAE7C,iBAAiB,CAAC,QAA8B;QAC5C,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAA;IAClC,CAAC;IAED,KAAK,CAAC,aAAa;QACf,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACvB,OAAO;gBACH,MAAM,EAAE,sBAAc,CAAC,mBAAmB;gBAC1C,OAAO,EAAE,EAAE,MAAM,EAAE,iBAAiB,EAAE;aACzC,CAAA;QACL,CAAC;QAED,MAAM,YAAY,GAAG,IAAI,CAAC,cAAc,EAAE,CAAA;QAC1C,MAAM,SAAS,GAAG,eAAe,CAAC,YAAY,CAAC,CAAA;QAE/C,OAAO;YACH,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,sBAAc,CAAC,EAAE,CAAC,CAAC,CAAC,sBAAc,CAAC,mBAAmB;YAC1E,OAAO,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE;SACpC,CAAA;IACL,CAAC;CACJ;AAvBD,kDAuBC"}
|