@diia-inhouse/workflow 3.4.23 → 3.4.25
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.
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { getDataConverter } from "../../encryption/dataConverter.js";
|
|
2
2
|
import "../../encryption/index.js";
|
|
3
|
+
import { workflowInterceptorModules } from "../../interceptors/workflowModules.js";
|
|
4
|
+
import { EnvService } from "@diia-inhouse/env";
|
|
3
5
|
import path from "node:path";
|
|
4
6
|
//#region src/cli/determinism/replayOptions.ts
|
|
5
7
|
function resolveWorkflowsPath(workflowsPath) {
|
|
@@ -9,7 +11,11 @@ function resolveWorkflowsPath(workflowsPath) {
|
|
|
9
11
|
return fullPath;
|
|
10
12
|
}
|
|
11
13
|
async function buildReplayOptions(workflowsPath, encryption, envService) {
|
|
12
|
-
const
|
|
14
|
+
const fullPath = resolveWorkflowsPath(workflowsPath);
|
|
15
|
+
const options = {
|
|
16
|
+
workflowsPath: fullPath,
|
|
17
|
+
interceptors: { workflowModules: workflowInterceptorModules(fullPath, EnvService.getVar("TRACING_ENABLED", "boolean", false)) }
|
|
18
|
+
};
|
|
13
19
|
if (encryption.enabled && envService) options.dataConverter = await getDataConverter(encryption.keyId, envService);
|
|
14
20
|
return options;
|
|
15
21
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
//#region src/interceptors/workflowModules.ts
|
|
3
|
+
const traceLogAttributesModulePath = path.resolve(import.meta.dirname, "traceLogAttributes");
|
|
4
|
+
/** Workflow interceptor modules the worker loads. Replay uses the same list. */
|
|
5
|
+
function workflowInterceptorModules(workflowsPath, tracingEnabled) {
|
|
6
|
+
const modules = workflowsPath ? [workflowsPath] : [];
|
|
7
|
+
return tracingEnabled ? [...modules, traceLogAttributesModulePath] : modules;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { workflowInterceptorModules };
|
package/dist/services/worker.js
CHANGED
|
@@ -3,13 +3,13 @@ import "../encryption/index.js";
|
|
|
3
3
|
import { traceExporter } from "../instrumentation.js";
|
|
4
4
|
import { ActivityTraceLogAttributesInterceptor } from "../interceptors/activityTraceLogAttributes.js";
|
|
5
5
|
import { AsyncLocalStorageBridgeInterceptor } from "../interceptors/asyncLocalStorageBridge.js";
|
|
6
|
+
import { workflowInterceptorModules } from "../interceptors/workflowModules.js";
|
|
6
7
|
import { buildWorkerIdentity } from "./worker/identity.js";
|
|
7
8
|
import { deriveWorkflowTypes, registerWorkerInfo } from "./worker/info.js";
|
|
8
9
|
import { toTemporalRuntimeLogger } from "./worker/runtimeLogger.js";
|
|
9
10
|
import { WorkerHealthService } from "./workerHealth.js";
|
|
10
11
|
import { EnvService } from "@diia-inhouse/env";
|
|
11
12
|
import { NativeConnection, Runtime, Worker } from "@temporalio/worker";
|
|
12
|
-
import path from "node:path";
|
|
13
13
|
import { fileURLToPath } from "node:url";
|
|
14
14
|
import { Resource } from "@opentelemetry/resources";
|
|
15
15
|
import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
|
|
@@ -63,7 +63,6 @@ function toWorkflowsPath(input) {
|
|
|
63
63
|
*
|
|
64
64
|
* Order matters: the first factory is the outermost, so the ones after it see an open span.
|
|
65
65
|
*/
|
|
66
|
-
const traceLogAttributesModulePath = path.resolve(import.meta.dirname, "../interceptors/traceLogAttributes");
|
|
67
66
|
function traceLogAttributesInterceptor() {
|
|
68
67
|
const interceptor = new ActivityTraceLogAttributesInterceptor();
|
|
69
68
|
return {
|
|
@@ -72,27 +71,23 @@ function traceLogAttributesInterceptor() {
|
|
|
72
71
|
};
|
|
73
72
|
}
|
|
74
73
|
function buildWorkerInterceptors(tracingEnabled, asyncLocalStorage, logger, workflowsPath) {
|
|
75
|
-
if (tracingEnabled) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
],
|
|
87
|
-
workflowModules
|
|
88
|
-
};
|
|
89
|
-
}
|
|
74
|
+
if (tracingEnabled) return {
|
|
75
|
+
activity: [
|
|
76
|
+
(ctx) => ({
|
|
77
|
+
inbound: new OpenTelemetryActivityInboundInterceptor(ctx),
|
|
78
|
+
outbound: new OpenTelemetryActivityOutboundInterceptor(ctx)
|
|
79
|
+
}),
|
|
80
|
+
traceLogAttributesInterceptor,
|
|
81
|
+
...asyncLocalStorage && logger ? [(ctx) => ({ inbound: new AsyncLocalStorageBridgeInterceptor(ctx, asyncLocalStorage, logger) })] : []
|
|
82
|
+
],
|
|
83
|
+
workflowModules: workflowInterceptorModules(workflowsPath, true)
|
|
84
|
+
};
|
|
90
85
|
if (asyncLocalStorage && logger) return {
|
|
91
86
|
activity: [(ctx) => ({
|
|
92
87
|
inbound: new AsyncLocalStorageBridgeInterceptor(ctx, asyncLocalStorage, logger),
|
|
93
88
|
outbound: new OpenTelemetryActivityOutboundInterceptor(ctx)
|
|
94
89
|
}), traceLogAttributesInterceptor],
|
|
95
|
-
workflowModules: workflowsPath
|
|
90
|
+
workflowModules: workflowInterceptorModules(workflowsPath, false)
|
|
96
91
|
};
|
|
97
92
|
}
|
|
98
93
|
/**
|
|
@@ -257,7 +252,7 @@ async function runWorker(app, options) {
|
|
|
257
252
|
});
|
|
258
253
|
const healthCheck = tryResolve(app.container, "healthCheck");
|
|
259
254
|
if (healthCheck) {
|
|
260
|
-
const workerHealthService = new WorkerHealthService();
|
|
255
|
+
const workerHealthService = new WorkerHealthService(Object.keys(instantiatedActivities).length > 0);
|
|
261
256
|
workerHealthService.setStatusProvider(() => worker.getStatus());
|
|
262
257
|
healthCheck.addHealthCheckable(workerHealthService);
|
|
263
258
|
}
|
|
@@ -7,7 +7,9 @@ interface WorkerHealthDetails {
|
|
|
7
7
|
worker: WorkerStatus | "NOT_INITIALIZED";
|
|
8
8
|
}
|
|
9
9
|
declare class WorkerHealthService implements OnHealthCheck {
|
|
10
|
+
private readonly hasActivities;
|
|
10
11
|
private statusProvider?;
|
|
12
|
+
constructor(hasActivities?: boolean);
|
|
11
13
|
setStatusProvider(provider: WorkerStatusProvider): void;
|
|
12
14
|
onHealthCheck(): Promise<HealthCheckResult<WorkerHealthDetails>>;
|
|
13
15
|
}
|
|
@@ -3,14 +3,18 @@ import { HttpStatusCode } from "@diia-inhouse/types";
|
|
|
3
3
|
function isPollerHealthy(state) {
|
|
4
4
|
return state === "POLLING";
|
|
5
5
|
}
|
|
6
|
-
function isWorkerHealthy(status) {
|
|
6
|
+
function isWorkerHealthy(status, hasActivities) {
|
|
7
7
|
const { runState, workflowPollerState, activityPollerState } = status;
|
|
8
8
|
if (runState !== "RUNNING") return false;
|
|
9
|
-
if (!isPollerHealthy(workflowPollerState)
|
|
10
|
-
return
|
|
9
|
+
if (!isPollerHealthy(workflowPollerState)) return false;
|
|
10
|
+
return !hasActivities || isPollerHealthy(activityPollerState);
|
|
11
11
|
}
|
|
12
12
|
var WorkerHealthService = class {
|
|
13
|
+
hasActivities;
|
|
13
14
|
statusProvider;
|
|
15
|
+
constructor(hasActivities = true) {
|
|
16
|
+
this.hasActivities = hasActivities;
|
|
17
|
+
}
|
|
14
18
|
setStatusProvider(provider) {
|
|
15
19
|
this.statusProvider = provider;
|
|
16
20
|
}
|
|
@@ -21,7 +25,7 @@ var WorkerHealthService = class {
|
|
|
21
25
|
};
|
|
22
26
|
const workerStatus = this.statusProvider();
|
|
23
27
|
return {
|
|
24
|
-
status: isWorkerHealthy(workerStatus) ? HttpStatusCode.OK : HttpStatusCode.SERVICE_UNAVAILABLE,
|
|
28
|
+
status: isWorkerHealthy(workerStatus, this.hasActivities) ? HttpStatusCode.OK : HttpStatusCode.SERVICE_UNAVAILABLE,
|
|
25
29
|
details: { worker: workerStatus }
|
|
26
30
|
};
|
|
27
31
|
}
|