@btravstack/temporal-worker 0.6.0 → 0.7.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/README.md +9 -9
- package/dist/index.cjs +24 -18
- package/dist/index.d.cts +33 -20
- package/dist/index.d.mts +33 -20
- package/dist/index.mjs +24 -18
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -142,15 +142,15 @@ and the module lists (`imports`, `provides`, `exports`, `needs`). The
|
|
|
142
142
|
the activities provider on its own port, which is how the composition root
|
|
143
143
|
supplies it:
|
|
144
144
|
|
|
145
|
-
| Option | What it is
|
|
146
|
-
| ------------- |
|
|
147
|
-
| `contract` | the `temporal-contract` contract; the task queue this worker polls is read off it
|
|
148
|
-
| `activities` | the activities provider — what `TemporalActivities(contract)(...)` returns for this contract
|
|
149
|
-
| `workflows` | where the sandbox's code comes from: `{ workflowsPath }` or `{ workflowBundle }`
|
|
150
|
-
| `address` | pins the service instead of reading `TEMPORAL_ADDRESS`
|
|
151
|
-
| `namespace` | pins the namespace instead of reading `TEMPORAL_NAMESPACE`
|
|
152
|
-
| `gracePeriod` | Temporal's `shutdownGraceTime`, a `Duration` (default `
|
|
153
|
-
| `forceAfter` | Temporal's `shutdownForceTime
|
|
145
|
+
| Option | What it is |
|
|
146
|
+
| ------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
|
147
|
+
| `contract` | the `temporal-contract` contract; the task queue this worker polls is read off it |
|
|
148
|
+
| `activities` | the activities provider — what `TemporalActivities(contract)(...)` returns for this contract |
|
|
149
|
+
| `workflows` | where the sandbox's code comes from: `{ workflowsPath }` or `{ workflowBundle }` |
|
|
150
|
+
| `address` | pins the service instead of reading `TEMPORAL_ADDRESS` |
|
|
151
|
+
| `namespace` | pins the namespace instead of reading `TEMPORAL_NAMESPACE` |
|
|
152
|
+
| `gracePeriod` | pins `TEMPORAL_GRACE_PERIOD_MS` — Temporal's `shutdownGraceTime`, a `Duration` (default `10_000` ms) |
|
|
153
|
+
| `forceAfter` | pins `TEMPORAL_FORCE_AFTER_MS` — Temporal's `shutdownForceTime` (default `15_000` ms); keep it under `DRAIN_TIMEOUT_MS` |
|
|
154
154
|
|
|
155
155
|
The full table — required/optional, defaults, and the reasoning — lives on
|
|
156
156
|
[the reference page](https://btravstack.github.io/btravstack/reference/temporal-worker),
|
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@ let _btravstack_di = require("@btravstack/di");
|
|
|
3
3
|
let _btravstack_config = require("@btravstack/config");
|
|
4
4
|
let _btravstack_core = require("@btravstack/core");
|
|
5
5
|
let _temporal_contract_worker_activity = require("@temporal-contract/worker/activity");
|
|
6
|
+
let _temporalio_common = require("@temporalio/common");
|
|
6
7
|
let _temporalio_worker = require("@temporalio/worker");
|
|
7
8
|
let unthrown = require("unthrown");
|
|
8
9
|
let _temporalio_activity = require("@temporalio/activity");
|
|
@@ -71,8 +72,15 @@ var TemporalRuntime = class extends _btravstack_core.RuntimePort {};
|
|
|
71
72
|
* tests, not from `index.ts`.
|
|
72
73
|
*/
|
|
73
74
|
const TemporalActivitiesPort = (0, _btravstack_di.Port)("TemporalActivities");
|
|
74
|
-
const
|
|
75
|
-
const
|
|
75
|
+
const DEFAULT_GRACE_MS = 1e4;
|
|
76
|
+
const DEFAULT_FORCE_MS = 15e3;
|
|
77
|
+
/**
|
|
78
|
+
* A `Duration` as the milliseconds a config field holds. Temporal's own
|
|
79
|
+
* `msToNumber` is what parses its string form, and it is exported for exactly
|
|
80
|
+
* this — a pin of `"10 seconds"` and a `TEMPORAL_GRACE_PERIOD_MS` of `10000`
|
|
81
|
+
* have to reach the worker as the same number.
|
|
82
|
+
*/
|
|
83
|
+
const durationMs = (duration) => duration === void 0 ? void 0 : (0, _temporalio_common.msToNumber)(duration);
|
|
76
84
|
/**
|
|
77
85
|
* The Temporal starter: a module providing the runtime, its configuration
|
|
78
86
|
* (bound from `TEMPORAL_ADDRESS` / `TEMPORAL_NAMESPACE` unless pinned) and the
|
|
@@ -87,12 +95,17 @@ const DEFAULT_FORCE = "15 seconds";
|
|
|
87
95
|
const temporal = (options) => {
|
|
88
96
|
const { address, namespace } = options;
|
|
89
97
|
const activities = TemporalActivitiesPort;
|
|
90
|
-
const config =
|
|
91
|
-
address,
|
|
92
|
-
namespace
|
|
93
|
-
} }) : _btravstack_config.Config.provider(TemporalConfig)(_btravstack_config.Config.object({
|
|
98
|
+
const config = _btravstack_config.Config.provider(TemporalConfig)(_btravstack_config.Config.object({
|
|
94
99
|
address: _btravstack_config.Config.pinned(address, _btravstack_config.Config.string("TEMPORAL_ADDRESS", { default: "127.0.0.1:7233" })),
|
|
95
|
-
namespace: _btravstack_config.Config.pinned(namespace, _btravstack_config.Config.string("TEMPORAL_NAMESPACE", { default: "default" }))
|
|
100
|
+
namespace: _btravstack_config.Config.pinned(namespace, _btravstack_config.Config.string("TEMPORAL_NAMESPACE", { default: "default" })),
|
|
101
|
+
gracePeriodMs: _btravstack_config.Config.pinned(durationMs(options.gracePeriod), _btravstack_config.Config.integer("TEMPORAL_GRACE_PERIOD_MS", {
|
|
102
|
+
default: DEFAULT_GRACE_MS,
|
|
103
|
+
min: 0
|
|
104
|
+
})),
|
|
105
|
+
forceAfterMs: _btravstack_config.Config.pinned(durationMs(options.forceAfter), _btravstack_config.Config.integer("TEMPORAL_FORCE_AFTER_MS", {
|
|
106
|
+
default: DEFAULT_FORCE_MS,
|
|
107
|
+
min: 0
|
|
108
|
+
}))
|
|
96
109
|
}));
|
|
97
110
|
return (0, _btravstack_di.Module)("Temporal")({
|
|
98
111
|
needs: [_btravstack_config.Env, activities],
|
|
@@ -140,8 +153,8 @@ const createWorker = (host, connection, config, activities, options) => {
|
|
|
140
153
|
taskQueue,
|
|
141
154
|
...options.workflows,
|
|
142
155
|
activities: handler,
|
|
143
|
-
shutdownGraceTime:
|
|
144
|
-
shutdownForceTime:
|
|
156
|
+
shutdownGraceTime: config.gracePeriodMs,
|
|
157
|
+
shutdownForceTime: config.forceAfterMs
|
|
145
158
|
}), startFailed)).map((worker) => poll(worker, taskQueue, namespace));
|
|
146
159
|
};
|
|
147
160
|
const poll = (worker, taskQueue, namespace) => {
|
|
@@ -211,18 +224,11 @@ const TemporalWorkflowActivities = (contract, key) => {
|
|
|
211
224
|
* ```
|
|
212
225
|
*/
|
|
213
226
|
const TemporalModule = (name) => (options) => {
|
|
214
|
-
const {
|
|
227
|
+
const { activities } = options;
|
|
215
228
|
const imports = options.imports ?? [];
|
|
216
229
|
const provides = options.provides ?? [];
|
|
217
230
|
const exports = options.exports ?? [];
|
|
218
|
-
const starter = temporal(
|
|
219
|
-
contract,
|
|
220
|
-
workflows,
|
|
221
|
-
...address === void 0 ? {} : { address },
|
|
222
|
-
...namespace === void 0 ? {} : { namespace },
|
|
223
|
-
...gracePeriod === void 0 ? {} : { gracePeriod },
|
|
224
|
-
...forceAfter === void 0 ? {} : { forceAfter }
|
|
225
|
-
});
|
|
231
|
+
const starter = temporal(options);
|
|
226
232
|
return (0, _btravstack_di.Module)(name)({
|
|
227
233
|
imports: [...imports, starter],
|
|
228
234
|
provides: [activities, ...provides],
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ConfigInvalid, Env } from "@btravstack/config";
|
|
2
2
|
import { AnyModule, AnyPort, AnyProvider, Exportable, Module, NeedsGate, PortClassOf, PortInstance, Provider, Scope } from "@btravstack/di";
|
|
3
3
|
import { ContractDefinition } from "@temporal-contract/contract";
|
|
4
|
-
import { Duration } from "@temporalio/common";
|
|
5
4
|
import { Runtime, RuntimePort } from "@btravstack/core";
|
|
6
5
|
import { DeclareActivitiesHandlerOptions } from "@temporal-contract/worker/activity";
|
|
6
|
+
import { Duration } from "@temporalio/common";
|
|
7
7
|
import { NativeConnection, WorkflowBundleWithSourceMap } from "@temporalio/worker";
|
|
8
8
|
//#region src/temporal-runtime.d.ts
|
|
9
9
|
/** What the worker publishes once it is polling, read back through `RunningApp.runtimeInfo()`. */
|
|
@@ -32,6 +32,10 @@ declare const TemporalConfig_base: import("@btravstack/di").PortClass<"TemporalC
|
|
|
32
32
|
declare class TemporalConfig extends TemporalConfig_base<{
|
|
33
33
|
readonly address: string;
|
|
34
34
|
readonly namespace: string;
|
|
35
|
+
/** Temporal's `shutdownGraceTime`, in milliseconds. */
|
|
36
|
+
readonly gracePeriodMs: number;
|
|
37
|
+
/** Temporal's `shutdownForceTime`, in milliseconds. */
|
|
38
|
+
readonly forceAfterMs: number;
|
|
35
39
|
}> {}
|
|
36
40
|
declare const TemporalConnection_base: import("@btravstack/di").PortClass<"TemporalConnection">;
|
|
37
41
|
/**
|
|
@@ -60,7 +64,32 @@ type ActivitiesOf<C extends ContractDefinition> = DeclareActivitiesHandlerOption
|
|
|
60
64
|
type ActivitiesPortOf<C extends ContractDefinition> = PortClassOf<"TemporalActivities", ActivitiesOf<C>>;
|
|
61
65
|
/** The activities port's instance for `C` — the module's one need. */
|
|
62
66
|
type ActivitiesInstanceOf<C extends ContractDefinition> = PortInstance<"TemporalActivities", ActivitiesOf<C>>;
|
|
63
|
-
|
|
67
|
+
/**
|
|
68
|
+
* What a Temporal deployment tunes, shared verbatim by `temporal()` and
|
|
69
|
+
* `TemporalModule` — spelled once so the two cannot drift, which is what a
|
|
70
|
+
* second copy of an option list always eventually does.
|
|
71
|
+
*/
|
|
72
|
+
type TemporalTuning = {
|
|
73
|
+
/** Pins `TemporalConfig.address` instead of reading `TEMPORAL_ADDRESS`. */
|
|
74
|
+
readonly address?: string;
|
|
75
|
+
/** Pins `TemporalConfig.namespace` instead of reading `TEMPORAL_NAMESPACE`. */
|
|
76
|
+
readonly namespace?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Pins `TemporalConfig.forceAfterMs` instead of reading
|
|
79
|
+
* `TEMPORAL_FORCE_AFTER_MS` (default `15_000`) — Temporal's
|
|
80
|
+
* `shutdownForceTime`. Keep it at or below the kernel's `drainTimeoutMs`,
|
|
81
|
+
* which is why it reads the environment: the two are set together, in the
|
|
82
|
+
* same manifest.
|
|
83
|
+
*/
|
|
84
|
+
readonly forceAfter?: Duration;
|
|
85
|
+
/**
|
|
86
|
+
* Pins `TemporalConfig.gracePeriodMs` instead of reading
|
|
87
|
+
* `TEMPORAL_GRACE_PERIOD_MS` (default `10_000`) — Temporal's
|
|
88
|
+
* `shutdownGraceTime`.
|
|
89
|
+
*/
|
|
90
|
+
readonly gracePeriod?: Duration;
|
|
91
|
+
};
|
|
92
|
+
type TemporalOptions<C extends ContractDefinition> = TemporalTuning & {
|
|
64
93
|
/**
|
|
65
94
|
* The contract; the task queue this worker polls is read off it, and the
|
|
66
95
|
* activities port is typed by it. The starter calls
|
|
@@ -68,14 +97,6 @@ type TemporalOptions<C extends ContractDefinition> = {
|
|
|
68
97
|
*/
|
|
69
98
|
readonly contract: C;
|
|
70
99
|
readonly workflows: WorkflowSource;
|
|
71
|
-
/** Pins `TemporalConfig.address` instead of reading `TEMPORAL_ADDRESS`. */
|
|
72
|
-
readonly address?: string;
|
|
73
|
-
/** Pins `TemporalConfig.namespace` instead of reading `TEMPORAL_NAMESPACE`. */
|
|
74
|
-
readonly namespace?: string;
|
|
75
|
-
/** Temporal's `shutdownForceTime`. Default `15 seconds`. Keep it at or below the kernel's `drainTimeoutMs`. */
|
|
76
|
-
readonly forceAfter?: Duration;
|
|
77
|
-
/** Temporal's `shutdownGraceTime`. Default `10 seconds`. */
|
|
78
|
-
readonly gracePeriod?: Duration;
|
|
79
100
|
};
|
|
80
101
|
type Provided = TemporalRuntime | TemporalConfig | TemporalConnection;
|
|
81
102
|
/**
|
|
@@ -133,20 +154,12 @@ type TemporalStarter<C extends ContractDefinition> = Module<TemporalRuntime | Te
|
|
|
133
154
|
type Imports<I extends readonly AnyModule[], C extends ContractDefinition> = readonly [...I, TemporalStarter<C>];
|
|
134
155
|
/** The activities provider plus the application's own — the tuple `Module(name)` is handed. */
|
|
135
156
|
type Provides<P extends readonly AnyProvider[], C extends ContractDefinition, ActivitiesError, ActivitiesNeeds> = readonly [Provider<ActivitiesInstanceOf<C>, ActivitiesError, ActivitiesNeeds>, ...P];
|
|
136
|
-
type TemporalModuleOptions<C extends ContractDefinition, ActivitiesError, ActivitiesNeeds, I extends readonly AnyModule[], P extends readonly AnyProvider[], X extends readonly Exportable<Imports<I, C>, Provides<P, C, ActivitiesError, ActivitiesNeeds>>[], N extends readonly AnyPort[]> = {
|
|
157
|
+
type TemporalModuleOptions<C extends ContractDefinition, ActivitiesError, ActivitiesNeeds, I extends readonly AnyModule[], P extends readonly AnyProvider[], X extends readonly Exportable<Imports<I, C>, Provides<P, C, ActivitiesError, ActivitiesNeeds>>[], N extends readonly AnyPort[]> = TemporalTuning & {
|
|
137
158
|
/** The `temporal-contract` contract; the task queue this worker polls is read off it. */
|
|
138
159
|
readonly contract: C;
|
|
160
|
+
readonly workflows: WorkflowSource;
|
|
139
161
|
/** The application's activity implementations — what `TemporalActivities(contract)(…)` returns. */
|
|
140
162
|
readonly activities: Provider<ActivitiesInstanceOf<C>, ActivitiesError, ActivitiesNeeds>;
|
|
141
|
-
readonly workflows: WorkflowSource;
|
|
142
|
-
/** Pins `TemporalConfig.address` instead of reading `TEMPORAL_ADDRESS`. */
|
|
143
|
-
readonly address?: string;
|
|
144
|
-
/** Pins `TemporalConfig.namespace` instead of reading `TEMPORAL_NAMESPACE`. */
|
|
145
|
-
readonly namespace?: string;
|
|
146
|
-
/** Temporal's `shutdownGraceTime`. Default `10 seconds`. */
|
|
147
|
-
readonly gracePeriod?: Duration;
|
|
148
|
-
/** Temporal's `shutdownForceTime`. Default `15 seconds`. Keep it at or below the kernel's `drainTimeoutMs`. */
|
|
149
|
-
readonly forceAfter?: Duration;
|
|
150
163
|
readonly imports?: I;
|
|
151
164
|
readonly provides?: P;
|
|
152
165
|
/** The application's own exports; `TemporalRuntime` is added, since `start` resolves it. */
|
package/dist/index.d.mts
CHANGED
|
@@ -2,9 +2,9 @@ import { AnyModule, AnyPort, AnyProvider, Exportable, Module, NeedsGate, PortCla
|
|
|
2
2
|
import { ConfigInvalid, Env } from "@btravstack/config";
|
|
3
3
|
import { Runtime, RuntimePort } from "@btravstack/core";
|
|
4
4
|
import { DeclareActivitiesHandlerOptions } from "@temporal-contract/worker/activity";
|
|
5
|
+
import { Duration } from "@temporalio/common";
|
|
5
6
|
import { NativeConnection, WorkflowBundleWithSourceMap } from "@temporalio/worker";
|
|
6
7
|
import { ContractDefinition } from "@temporal-contract/contract";
|
|
7
|
-
import { Duration } from "@temporalio/common";
|
|
8
8
|
//#region src/temporal-runtime.d.ts
|
|
9
9
|
/** What the worker publishes once it is polling, read back through `RunningApp.runtimeInfo()`. */
|
|
10
10
|
type TemporalInfo = {
|
|
@@ -32,6 +32,10 @@ declare const TemporalConfig_base: import("@btravstack/di").PortClass<"TemporalC
|
|
|
32
32
|
declare class TemporalConfig extends TemporalConfig_base<{
|
|
33
33
|
readonly address: string;
|
|
34
34
|
readonly namespace: string;
|
|
35
|
+
/** Temporal's `shutdownGraceTime`, in milliseconds. */
|
|
36
|
+
readonly gracePeriodMs: number;
|
|
37
|
+
/** Temporal's `shutdownForceTime`, in milliseconds. */
|
|
38
|
+
readonly forceAfterMs: number;
|
|
35
39
|
}> {}
|
|
36
40
|
declare const TemporalConnection_base: import("@btravstack/di").PortClass<"TemporalConnection">;
|
|
37
41
|
/**
|
|
@@ -60,7 +64,32 @@ type ActivitiesOf<C extends ContractDefinition> = DeclareActivitiesHandlerOption
|
|
|
60
64
|
type ActivitiesPortOf<C extends ContractDefinition> = PortClassOf<"TemporalActivities", ActivitiesOf<C>>;
|
|
61
65
|
/** The activities port's instance for `C` — the module's one need. */
|
|
62
66
|
type ActivitiesInstanceOf<C extends ContractDefinition> = PortInstance<"TemporalActivities", ActivitiesOf<C>>;
|
|
63
|
-
|
|
67
|
+
/**
|
|
68
|
+
* What a Temporal deployment tunes, shared verbatim by `temporal()` and
|
|
69
|
+
* `TemporalModule` — spelled once so the two cannot drift, which is what a
|
|
70
|
+
* second copy of an option list always eventually does.
|
|
71
|
+
*/
|
|
72
|
+
type TemporalTuning = {
|
|
73
|
+
/** Pins `TemporalConfig.address` instead of reading `TEMPORAL_ADDRESS`. */
|
|
74
|
+
readonly address?: string;
|
|
75
|
+
/** Pins `TemporalConfig.namespace` instead of reading `TEMPORAL_NAMESPACE`. */
|
|
76
|
+
readonly namespace?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Pins `TemporalConfig.forceAfterMs` instead of reading
|
|
79
|
+
* `TEMPORAL_FORCE_AFTER_MS` (default `15_000`) — Temporal's
|
|
80
|
+
* `shutdownForceTime`. Keep it at or below the kernel's `drainTimeoutMs`,
|
|
81
|
+
* which is why it reads the environment: the two are set together, in the
|
|
82
|
+
* same manifest.
|
|
83
|
+
*/
|
|
84
|
+
readonly forceAfter?: Duration;
|
|
85
|
+
/**
|
|
86
|
+
* Pins `TemporalConfig.gracePeriodMs` instead of reading
|
|
87
|
+
* `TEMPORAL_GRACE_PERIOD_MS` (default `10_000`) — Temporal's
|
|
88
|
+
* `shutdownGraceTime`.
|
|
89
|
+
*/
|
|
90
|
+
readonly gracePeriod?: Duration;
|
|
91
|
+
};
|
|
92
|
+
type TemporalOptions<C extends ContractDefinition> = TemporalTuning & {
|
|
64
93
|
/**
|
|
65
94
|
* The contract; the task queue this worker polls is read off it, and the
|
|
66
95
|
* activities port is typed by it. The starter calls
|
|
@@ -68,14 +97,6 @@ type TemporalOptions<C extends ContractDefinition> = {
|
|
|
68
97
|
*/
|
|
69
98
|
readonly contract: C;
|
|
70
99
|
readonly workflows: WorkflowSource;
|
|
71
|
-
/** Pins `TemporalConfig.address` instead of reading `TEMPORAL_ADDRESS`. */
|
|
72
|
-
readonly address?: string;
|
|
73
|
-
/** Pins `TemporalConfig.namespace` instead of reading `TEMPORAL_NAMESPACE`. */
|
|
74
|
-
readonly namespace?: string;
|
|
75
|
-
/** Temporal's `shutdownForceTime`. Default `15 seconds`. Keep it at or below the kernel's `drainTimeoutMs`. */
|
|
76
|
-
readonly forceAfter?: Duration;
|
|
77
|
-
/** Temporal's `shutdownGraceTime`. Default `10 seconds`. */
|
|
78
|
-
readonly gracePeriod?: Duration;
|
|
79
100
|
};
|
|
80
101
|
type Provided = TemporalRuntime | TemporalConfig | TemporalConnection;
|
|
81
102
|
/**
|
|
@@ -133,20 +154,12 @@ type TemporalStarter<C extends ContractDefinition> = Module<TemporalRuntime | Te
|
|
|
133
154
|
type Imports<I extends readonly AnyModule[], C extends ContractDefinition> = readonly [...I, TemporalStarter<C>];
|
|
134
155
|
/** The activities provider plus the application's own — the tuple `Module(name)` is handed. */
|
|
135
156
|
type Provides<P extends readonly AnyProvider[], C extends ContractDefinition, ActivitiesError, ActivitiesNeeds> = readonly [Provider<ActivitiesInstanceOf<C>, ActivitiesError, ActivitiesNeeds>, ...P];
|
|
136
|
-
type TemporalModuleOptions<C extends ContractDefinition, ActivitiesError, ActivitiesNeeds, I extends readonly AnyModule[], P extends readonly AnyProvider[], X extends readonly Exportable<Imports<I, C>, Provides<P, C, ActivitiesError, ActivitiesNeeds>>[], N extends readonly AnyPort[]> = {
|
|
157
|
+
type TemporalModuleOptions<C extends ContractDefinition, ActivitiesError, ActivitiesNeeds, I extends readonly AnyModule[], P extends readonly AnyProvider[], X extends readonly Exportable<Imports<I, C>, Provides<P, C, ActivitiesError, ActivitiesNeeds>>[], N extends readonly AnyPort[]> = TemporalTuning & {
|
|
137
158
|
/** The `temporal-contract` contract; the task queue this worker polls is read off it. */
|
|
138
159
|
readonly contract: C;
|
|
160
|
+
readonly workflows: WorkflowSource;
|
|
139
161
|
/** The application's activity implementations — what `TemporalActivities(contract)(…)` returns. */
|
|
140
162
|
readonly activities: Provider<ActivitiesInstanceOf<C>, ActivitiesError, ActivitiesNeeds>;
|
|
141
|
-
readonly workflows: WorkflowSource;
|
|
142
|
-
/** Pins `TemporalConfig.address` instead of reading `TEMPORAL_ADDRESS`. */
|
|
143
|
-
readonly address?: string;
|
|
144
|
-
/** Pins `TemporalConfig.namespace` instead of reading `TEMPORAL_NAMESPACE`. */
|
|
145
|
-
readonly namespace?: string;
|
|
146
|
-
/** Temporal's `shutdownGraceTime`. Default `10 seconds`. */
|
|
147
|
-
readonly gracePeriod?: Duration;
|
|
148
|
-
/** Temporal's `shutdownForceTime`. Default `15 seconds`. Keep it at or below the kernel's `drainTimeoutMs`. */
|
|
149
|
-
readonly forceAfter?: Duration;
|
|
150
163
|
readonly imports?: I;
|
|
151
164
|
readonly provides?: P;
|
|
152
165
|
/** The application's own exports; `TemporalRuntime` is added, since `start` resolves it. */
|
package/dist/index.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { Module, Port, Provider } from "@btravstack/di";
|
|
|
2
2
|
import { Config, Env } from "@btravstack/config";
|
|
3
3
|
import { RuntimePort, RuntimeStartFailed, releasedBy } from "@btravstack/core";
|
|
4
4
|
import { declareActivitiesHandler } from "@temporal-contract/worker/activity";
|
|
5
|
+
import { msToNumber } from "@temporalio/common";
|
|
5
6
|
import { NativeConnection, Worker } from "@temporalio/worker";
|
|
6
7
|
import { TaggedError, fromPromise, fromSafePromise, fromThrowable } from "unthrown";
|
|
7
8
|
import { activityInfo } from "@temporalio/activity";
|
|
@@ -70,8 +71,15 @@ var TemporalRuntime = class extends RuntimePort {};
|
|
|
70
71
|
* tests, not from `index.ts`.
|
|
71
72
|
*/
|
|
72
73
|
const TemporalActivitiesPort = Port("TemporalActivities");
|
|
73
|
-
const
|
|
74
|
-
const
|
|
74
|
+
const DEFAULT_GRACE_MS = 1e4;
|
|
75
|
+
const DEFAULT_FORCE_MS = 15e3;
|
|
76
|
+
/**
|
|
77
|
+
* A `Duration` as the milliseconds a config field holds. Temporal's own
|
|
78
|
+
* `msToNumber` is what parses its string form, and it is exported for exactly
|
|
79
|
+
* this — a pin of `"10 seconds"` and a `TEMPORAL_GRACE_PERIOD_MS` of `10000`
|
|
80
|
+
* have to reach the worker as the same number.
|
|
81
|
+
*/
|
|
82
|
+
const durationMs = (duration) => duration === void 0 ? void 0 : msToNumber(duration);
|
|
75
83
|
/**
|
|
76
84
|
* The Temporal starter: a module providing the runtime, its configuration
|
|
77
85
|
* (bound from `TEMPORAL_ADDRESS` / `TEMPORAL_NAMESPACE` unless pinned) and the
|
|
@@ -86,12 +94,17 @@ const DEFAULT_FORCE = "15 seconds";
|
|
|
86
94
|
const temporal = (options) => {
|
|
87
95
|
const { address, namespace } = options;
|
|
88
96
|
const activities = TemporalActivitiesPort;
|
|
89
|
-
const config =
|
|
90
|
-
address,
|
|
91
|
-
namespace
|
|
92
|
-
} }) : Config.provider(TemporalConfig)(Config.object({
|
|
97
|
+
const config = Config.provider(TemporalConfig)(Config.object({
|
|
93
98
|
address: Config.pinned(address, Config.string("TEMPORAL_ADDRESS", { default: "127.0.0.1:7233" })),
|
|
94
|
-
namespace: Config.pinned(namespace, Config.string("TEMPORAL_NAMESPACE", { default: "default" }))
|
|
99
|
+
namespace: Config.pinned(namespace, Config.string("TEMPORAL_NAMESPACE", { default: "default" })),
|
|
100
|
+
gracePeriodMs: Config.pinned(durationMs(options.gracePeriod), Config.integer("TEMPORAL_GRACE_PERIOD_MS", {
|
|
101
|
+
default: DEFAULT_GRACE_MS,
|
|
102
|
+
min: 0
|
|
103
|
+
})),
|
|
104
|
+
forceAfterMs: Config.pinned(durationMs(options.forceAfter), Config.integer("TEMPORAL_FORCE_AFTER_MS", {
|
|
105
|
+
default: DEFAULT_FORCE_MS,
|
|
106
|
+
min: 0
|
|
107
|
+
}))
|
|
95
108
|
}));
|
|
96
109
|
return Module("Temporal")({
|
|
97
110
|
needs: [Env, activities],
|
|
@@ -139,8 +152,8 @@ const createWorker = (host, connection, config, activities, options) => {
|
|
|
139
152
|
taskQueue,
|
|
140
153
|
...options.workflows,
|
|
141
154
|
activities: handler,
|
|
142
|
-
shutdownGraceTime:
|
|
143
|
-
shutdownForceTime:
|
|
155
|
+
shutdownGraceTime: config.gracePeriodMs,
|
|
156
|
+
shutdownForceTime: config.forceAfterMs
|
|
144
157
|
}), startFailed)).map((worker) => poll(worker, taskQueue, namespace));
|
|
145
158
|
};
|
|
146
159
|
const poll = (worker, taskQueue, namespace) => {
|
|
@@ -210,18 +223,11 @@ const TemporalWorkflowActivities = (contract, key) => {
|
|
|
210
223
|
* ```
|
|
211
224
|
*/
|
|
212
225
|
const TemporalModule = (name) => (options) => {
|
|
213
|
-
const {
|
|
226
|
+
const { activities } = options;
|
|
214
227
|
const imports = options.imports ?? [];
|
|
215
228
|
const provides = options.provides ?? [];
|
|
216
229
|
const exports = options.exports ?? [];
|
|
217
|
-
const starter = temporal(
|
|
218
|
-
contract,
|
|
219
|
-
workflows,
|
|
220
|
-
...address === void 0 ? {} : { address },
|
|
221
|
-
...namespace === void 0 ? {} : { namespace },
|
|
222
|
-
...gracePeriod === void 0 ? {} : { gracePeriod },
|
|
223
|
-
...forceAfter === void 0 ? {} : { forceAfter }
|
|
224
|
-
});
|
|
230
|
+
const starter = temporal(options);
|
|
225
231
|
return Module(name)({
|
|
226
232
|
imports: [...imports, starter],
|
|
227
233
|
provides: [activities, ...provides],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@btravstack/temporal-worker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "The Temporal worker runtime for @btravstack/core: one unit per activity attempt, and a drain that honours the kernel's deadline",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graceful-shutdown",
|
|
@@ -60,11 +60,11 @@
|
|
|
60
60
|
"unthrown": "5.7.0",
|
|
61
61
|
"vitest": "4.1.11",
|
|
62
62
|
"zod": "4.4.3",
|
|
63
|
-
"@btravstack/
|
|
64
|
-
"@btravstack/
|
|
65
|
-
"@btravstack/
|
|
63
|
+
"@btravstack/config": "0.7.0",
|
|
64
|
+
"@btravstack/core": "0.7.0",
|
|
65
|
+
"@btravstack/di": "0.7.0",
|
|
66
66
|
"@btravstack/internal-test-infra": "0.0.0",
|
|
67
|
-
"@btravstack/testing": "0.
|
|
67
|
+
"@btravstack/testing": "0.7.0"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"@temporal-contract/contract": "^8.0.0-beta",
|
|
@@ -73,9 +73,9 @@
|
|
|
73
73
|
"@temporalio/common": "^1.22.0",
|
|
74
74
|
"@temporalio/worker": "^1.22.0",
|
|
75
75
|
"unthrown": "^5.0.0",
|
|
76
|
-
"@btravstack/config": "^0.
|
|
77
|
-
"@btravstack/
|
|
78
|
-
"@btravstack/
|
|
76
|
+
"@btravstack/config": "^0.7.0",
|
|
77
|
+
"@btravstack/core": "^0.7.0",
|
|
78
|
+
"@btravstack/di": "^0.7.0"
|
|
79
79
|
},
|
|
80
80
|
"engines": {
|
|
81
81
|
"node": ">=22"
|