@camunda8/sdk 8.9.0-alpha.16 → 8.9.0-alpha.18
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/.eslintrc.json +79 -0
- package/AGENT.md +9 -0
- package/AGENTS.md +22 -0
- package/CHANGELOG.md +14 -0
- package/MAINTAINER.md +2 -1
- package/README.md +10 -1
- package/dist/zeebe/index.d.ts +1 -0
- package/dist/zeebe/index.js.map +1 -1
- package/dist/zeebe/lib/GrpcClient.d.ts +6 -0
- package/dist/zeebe/lib/GrpcClient.js +93 -85
- package/dist/zeebe/lib/GrpcClient.js.map +1 -1
- package/dist/zeebe/lib/StreamLifecycle.d.ts +189 -0
- package/dist/zeebe/lib/StreamLifecycle.js +142 -0
- package/dist/zeebe/lib/StreamLifecycle.js.map +1 -0
- package/dist/zeebe/lib/ZBStreamWorker.d.ts +17 -3
- package/dist/zeebe/lib/ZBStreamWorker.js +364 -137
- package/dist/zeebe/lib/ZBStreamWorker.js.map +1 -1
- package/dist/zeebe/zb/ZeebeGrpcClient.d.ts +6 -3
- package/dist/zeebe/zb/ZeebeGrpcClient.js +4 -0
- package/dist/zeebe/zb/ZeebeGrpcClient.js.map +1 -1
- package/package.json +6 -1
- package/scripts/assert-no-skipped-tests.d.ts +17 -0
- package/scripts/assert-no-skipped-tests.js +118 -0
- package/scripts/required-integration-specs.json +4 -0
- package/stryker.config.json +20 -0
- package/vitest.mutation.config.js +18 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import type { ClientReadableStream } from '@grpc/grpc-js';
|
|
2
|
+
/**
|
|
3
|
+
* Stream lifecycle adapter.
|
|
4
|
+
*
|
|
5
|
+
* A long-lived gRPC stream has four ways to stop delivering: it errors, the
|
|
6
|
+
* server ends it, the connection hangs silently, or it cannot be opened. This
|
|
7
|
+
* module exists so that none of them can go unobserved:
|
|
8
|
+
*
|
|
9
|
+
* - `attachStream` is the ONLY code in the SDK's stream workers that attaches
|
|
10
|
+
* listeners to a raw gRPC stream. Its handler contract, `StreamHandlers`,
|
|
11
|
+
* requires a handler for every event. Omitting `error` (the classic
|
|
12
|
+
* `stream.on('data', ...)` with a `console.error` on the side) does not
|
|
13
|
+
* compile. ESLint rules (see `.eslintrc.json`) forbid attaching listeners to
|
|
14
|
+
* a stream anywhere else in the stream modules.
|
|
15
|
+
* - `StreamHandle` is the branded value that a streaming API returns. It has a
|
|
16
|
+
* failure channel: `state` (a discriminated union) and `done` (a promise of
|
|
17
|
+
* the terminal reason). An API whose return type is not a `StreamHandle`
|
|
18
|
+
* is not a streaming API as far as the conformance registry is concerned.
|
|
19
|
+
*
|
|
20
|
+
* The conformance registry in `src/__tests__/zeebe/conformance` derives the set
|
|
21
|
+
* of streaming operations from the return types of `ZeebeGrpcClient`, so
|
|
22
|
+
* adding a streaming method without registering it fails `tsc`.
|
|
23
|
+
*/
|
|
24
|
+
/** Why a stream stopped delivering. */
|
|
25
|
+
export type StreamFailure =
|
|
26
|
+
/** The stream emitted an `error` event. */
|
|
27
|
+
{
|
|
28
|
+
readonly kind: 'error';
|
|
29
|
+
readonly error: Error;
|
|
30
|
+
}
|
|
31
|
+
/** The server ended or closed the stream without an error. */
|
|
32
|
+
| {
|
|
33
|
+
readonly kind: 'end';
|
|
34
|
+
}
|
|
35
|
+
/** The stream could not be opened. */
|
|
36
|
+
| {
|
|
37
|
+
readonly kind: 'open-failed';
|
|
38
|
+
readonly error: Error;
|
|
39
|
+
};
|
|
40
|
+
/** Why a handle reached its terminal `closed` state. */
|
|
41
|
+
export type StreamClosedReason =
|
|
42
|
+
/** `close()` was called on the handle. */
|
|
43
|
+
{
|
|
44
|
+
readonly kind: 'closed-by-caller';
|
|
45
|
+
}
|
|
46
|
+
/** The owning client was closed. */
|
|
47
|
+
| {
|
|
48
|
+
readonly kind: 'client-closed';
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The stream failed and reconnection is disabled, so it will not be
|
|
52
|
+
* re-opened. Other work owned by the handle (for example `streamJobs`'
|
|
53
|
+
* sidecar poll) keeps running until `close()` is called.
|
|
54
|
+
*/
|
|
55
|
+
| {
|
|
56
|
+
readonly kind: 'stream-failed';
|
|
57
|
+
readonly failure: StreamFailure;
|
|
58
|
+
};
|
|
59
|
+
/** The observable state of a stream handle. */
|
|
60
|
+
export type StreamState =
|
|
61
|
+
/** The stream is established. */
|
|
62
|
+
{
|
|
63
|
+
readonly status: 'open';
|
|
64
|
+
}
|
|
65
|
+
/** The stream is down and a re-open attempt is scheduled or in flight. */
|
|
66
|
+
| {
|
|
67
|
+
readonly status: 'reconnecting';
|
|
68
|
+
/** Consecutive failed streams or open attempts, starting at 1. */
|
|
69
|
+
readonly attempt: number;
|
|
70
|
+
readonly cause: StreamFailure;
|
|
71
|
+
}
|
|
72
|
+
/** Terminal: the stream is down and will not be re-opened. */
|
|
73
|
+
| {
|
|
74
|
+
readonly status: 'closed';
|
|
75
|
+
readonly reason: StreamClosedReason;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* The listener contract for a raw stream. Every key is required: leaving one
|
|
79
|
+
* out is a compile error, so "forgot to handle `error`" cannot be written.
|
|
80
|
+
*/
|
|
81
|
+
export interface StreamHandlers<T> {
|
|
82
|
+
/** One item was received. Must not throw; if it does it is treated as a stream `error`. */
|
|
83
|
+
readonly data: (item: T) => void;
|
|
84
|
+
/**
|
|
85
|
+
* The stream failed. Called at most once per stream, and never after `end`
|
|
86
|
+
* for the same stream.
|
|
87
|
+
*/
|
|
88
|
+
readonly error: (error: Error) => void;
|
|
89
|
+
/**
|
|
90
|
+
* The server ended the stream (an `end` event, or a `close` with no prior
|
|
91
|
+
* `end` or `error`). Called at most once per stream, and never after `error`
|
|
92
|
+
* for the same stream.
|
|
93
|
+
*/
|
|
94
|
+
readonly end: () => void;
|
|
95
|
+
/**
|
|
96
|
+
* Called exactly once per stream, immediately after the `error` or `end`
|
|
97
|
+
* handler, so that the stream's resources can be released and recovery
|
|
98
|
+
* scheduled in one place. Not called after `dispose()`.
|
|
99
|
+
*/
|
|
100
|
+
readonly close: () => void;
|
|
101
|
+
}
|
|
102
|
+
export interface StreamAttachment {
|
|
103
|
+
/**
|
|
104
|
+
* Cancel and destroy the stream and suppress all further handler calls.
|
|
105
|
+
* The adapter's own listeners stay attached on purpose: removing the
|
|
106
|
+
* `error` listener from a stream that is then cancelled would turn the
|
|
107
|
+
* resulting CANCELLED `error` event into an uncaught exception.
|
|
108
|
+
*/
|
|
109
|
+
readonly dispose: () => void;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Narrow the value that a stream-opening call resolved to (after
|
|
113
|
+
* `getOpenError` found no error) to a stream. Lives here so that stream workers
|
|
114
|
+
* never need to name, and therefore never hold a typed reference to, the raw
|
|
115
|
+
* gRPC stream type.
|
|
116
|
+
*/
|
|
117
|
+
export declare const asStream: <T>(opened: unknown) => ClientReadableStream<T>;
|
|
118
|
+
/**
|
|
119
|
+
* Cancel and destroy a raw stream. Also used for a stream that was never
|
|
120
|
+
* attached (for example one that finished opening after its handle was
|
|
121
|
+
* closed): cancelling reports CANCELLED as an `error` event, which with no
|
|
122
|
+
* listener would be an uncaught exception, so a listener for that expected
|
|
123
|
+
* error is added first.
|
|
124
|
+
*/
|
|
125
|
+
export declare const cancelStream: (stream: ClientReadableStream<unknown>) => void;
|
|
126
|
+
export declare const toError: (e: unknown) => Error;
|
|
127
|
+
/**
|
|
128
|
+
* Attach the lifecycle handlers to a raw gRPC stream. The only place in the
|
|
129
|
+
* stream modules that calls `.on(...)` on a stream.
|
|
130
|
+
*
|
|
131
|
+
* `error`, `end` and `close` events can all fire for one dead stream; the first
|
|
132
|
+
* one decides which handler runs, and the `close` handler runs exactly once.
|
|
133
|
+
*/
|
|
134
|
+
export declare function attachStream<T>(stream: ClientReadableStream<T>, handlers: StreamHandlers<T>): StreamAttachment;
|
|
135
|
+
/**
|
|
136
|
+
* `streamActivatedJobsStream` resolves to `{ error }` (or `undefined` when the
|
|
137
|
+
* client is closing) instead of a stream when the stream cannot be opened.
|
|
138
|
+
* Returns the open error, or `undefined` when `result` is a usable stream.
|
|
139
|
+
*/
|
|
140
|
+
export declare const getOpenError: (result: unknown) => Error | undefined;
|
|
141
|
+
/** Delay before reconnect `attempt` (1-based): exponential, capped. */
|
|
142
|
+
export declare const backoffDelayMs: (attempt: number, initialDelayMs: number, maxDelayMs: number) => number;
|
|
143
|
+
export declare const STREAM_HANDLE_BRAND: unique symbol;
|
|
144
|
+
/**
|
|
145
|
+
* The value returned by every streaming API in the SDK. Extends the original
|
|
146
|
+
* `{ close }` return type backward-compatibly with a failure channel.
|
|
147
|
+
*
|
|
148
|
+
* - `state` is the current state; read it any time.
|
|
149
|
+
* - `done` resolves (never rejects) with the terminal reason when the handle
|
|
150
|
+
* reaches `closed`.
|
|
151
|
+
*
|
|
152
|
+
* Handle states are only ever produced by `createStreamHandle`; the brand
|
|
153
|
+
* stops a structural `{ close }` literal from passing as a stream handle.
|
|
154
|
+
*/
|
|
155
|
+
export interface StreamHandle {
|
|
156
|
+
readonly [STREAM_HANDLE_BRAND]: true;
|
|
157
|
+
/** Stop the stream and any reconnection. Idempotent. */
|
|
158
|
+
close(): void;
|
|
159
|
+
/** The current state of the stream. */
|
|
160
|
+
readonly state: StreamState;
|
|
161
|
+
/** Resolves with the terminal reason when the handle becomes `closed`. */
|
|
162
|
+
readonly done: Promise<StreamClosedReason>;
|
|
163
|
+
}
|
|
164
|
+
export interface StreamStateMachine {
|
|
165
|
+
readonly state: StreamState;
|
|
166
|
+
readonly done: Promise<StreamClosedReason>;
|
|
167
|
+
/**
|
|
168
|
+
* Move to `next`. `closed` is terminal: transitions after it are ignored
|
|
169
|
+
* and return `false`.
|
|
170
|
+
*/
|
|
171
|
+
readonly transition: (next: StreamState) => boolean;
|
|
172
|
+
}
|
|
173
|
+
export declare function createStreamStateMachine(initial?: StreamState): StreamStateMachine;
|
|
174
|
+
export declare function createStreamHandle(machine: Pick<StreamStateMachine, 'state' | 'done'>, close: () => void): StreamHandle;
|
|
175
|
+
/** Human-readable description of a state, for logs. */
|
|
176
|
+
export declare const describeStreamState: (state: StreamState) => string;
|
|
177
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
178
|
+
/**
|
|
179
|
+
* The names of the methods of `Client` that return (or resolve to) a
|
|
180
|
+
* `StreamHandle`: its streaming operations. Type-level only.
|
|
181
|
+
*
|
|
182
|
+
* The conformance registry is keyed by this type, so a new streaming method on
|
|
183
|
+
* the client cannot be added without a registry entry (and therefore the
|
|
184
|
+
* conformance suite) or `tsc` fails.
|
|
185
|
+
*/
|
|
186
|
+
export type StreamingOpsOf<Client> = {
|
|
187
|
+
[K in keyof Client & string]: Client[K] extends (...args: never[]) => infer R ? IsAny<Awaited<R>> extends true ? never : Awaited<R> extends StreamHandle ? K : never : never;
|
|
188
|
+
}[keyof Client & string];
|
|
189
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.describeStreamState = exports.STREAM_HANDLE_BRAND = exports.backoffDelayMs = exports.getOpenError = exports.toError = exports.cancelStream = exports.asStream = void 0;
|
|
4
|
+
exports.attachStream = attachStream;
|
|
5
|
+
exports.createStreamStateMachine = createStreamStateMachine;
|
|
6
|
+
exports.createStreamHandle = createStreamHandle;
|
|
7
|
+
/**
|
|
8
|
+
* Narrow the value that a stream-opening call resolved to (after
|
|
9
|
+
* `getOpenError` found no error) to a stream. Lives here so that stream workers
|
|
10
|
+
* never need to name, and therefore never hold a typed reference to, the raw
|
|
11
|
+
* gRPC stream type.
|
|
12
|
+
*/
|
|
13
|
+
const asStream = (opened) => opened;
|
|
14
|
+
exports.asStream = asStream;
|
|
15
|
+
/**
|
|
16
|
+
* Cancel and destroy a raw stream. Also used for a stream that was never
|
|
17
|
+
* attached (for example one that finished opening after its handle was
|
|
18
|
+
* closed): cancelling reports CANCELLED as an `error` event, which with no
|
|
19
|
+
* listener would be an uncaught exception, so a listener for that expected
|
|
20
|
+
* error is added first.
|
|
21
|
+
*/
|
|
22
|
+
const cancelStream = (stream) => {
|
|
23
|
+
stream.on('error', () => undefined);
|
|
24
|
+
stream.cancel();
|
|
25
|
+
stream.destroy();
|
|
26
|
+
};
|
|
27
|
+
exports.cancelStream = cancelStream;
|
|
28
|
+
const toError = (e) => e instanceof Error ? e : new Error(String(e));
|
|
29
|
+
exports.toError = toError;
|
|
30
|
+
/**
|
|
31
|
+
* Attach the lifecycle handlers to a raw gRPC stream. The only place in the
|
|
32
|
+
* stream modules that calls `.on(...)` on a stream.
|
|
33
|
+
*
|
|
34
|
+
* `error`, `end` and `close` events can all fire for one dead stream; the first
|
|
35
|
+
* one decides which handler runs, and the `close` handler runs exactly once.
|
|
36
|
+
*/
|
|
37
|
+
function attachStream(stream, handlers) {
|
|
38
|
+
let settled = false;
|
|
39
|
+
const settle = (deliverCause) => {
|
|
40
|
+
if (settled) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
settled = true;
|
|
44
|
+
try {
|
|
45
|
+
deliverCause();
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
handlers.close();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
stream.on('data', (item) => {
|
|
52
|
+
if (settled) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
handlers.data(item);
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
// A throwing data handler is a bug, but it must not be silent and it
|
|
60
|
+
// must not leave a stream running that nobody is processing.
|
|
61
|
+
(0, exports.cancelStream)(stream);
|
|
62
|
+
settle(() => handlers.error((0, exports.toError)(e)));
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
stream.on('error', (e) => settle(() => handlers.error((0, exports.toError)(e))));
|
|
66
|
+
stream.on('end', () => settle(() => handlers.end()));
|
|
67
|
+
stream.on('close', () => settle(() => handlers.end()));
|
|
68
|
+
return {
|
|
69
|
+
dispose: () => {
|
|
70
|
+
settled = true;
|
|
71
|
+
(0, exports.cancelStream)(stream);
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* `streamActivatedJobsStream` resolves to `{ error }` (or `undefined` when the
|
|
77
|
+
* client is closing) instead of a stream when the stream cannot be opened.
|
|
78
|
+
* Returns the open error, or `undefined` when `result` is a usable stream.
|
|
79
|
+
*/
|
|
80
|
+
const getOpenError = (result) => {
|
|
81
|
+
if (!result)
|
|
82
|
+
return new Error('Stream could not be opened');
|
|
83
|
+
if (typeof result === 'object' && 'error' in result) {
|
|
84
|
+
return (0, exports.toError)(result.error);
|
|
85
|
+
}
|
|
86
|
+
return undefined;
|
|
87
|
+
};
|
|
88
|
+
exports.getOpenError = getOpenError;
|
|
89
|
+
/** Delay before reconnect `attempt` (1-based): exponential, capped. */
|
|
90
|
+
const backoffDelayMs = (attempt, initialDelayMs, maxDelayMs) => Math.min(initialDelayMs * 2 ** (attempt - 1), maxDelayMs);
|
|
91
|
+
exports.backoffDelayMs = backoffDelayMs;
|
|
92
|
+
exports.STREAM_HANDLE_BRAND = Symbol('StreamHandle');
|
|
93
|
+
function createStreamStateMachine(initial = { status: 'open' }) {
|
|
94
|
+
let state = initial;
|
|
95
|
+
let resolveDone = () => { };
|
|
96
|
+
const done = new Promise((resolve) => {
|
|
97
|
+
resolveDone = resolve;
|
|
98
|
+
});
|
|
99
|
+
return {
|
|
100
|
+
get state() {
|
|
101
|
+
return state;
|
|
102
|
+
},
|
|
103
|
+
done,
|
|
104
|
+
transition: (next) => {
|
|
105
|
+
if (state.status === 'closed') {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
state = next;
|
|
109
|
+
if (next.status === 'closed') {
|
|
110
|
+
resolveDone(next.reason);
|
|
111
|
+
}
|
|
112
|
+
return true;
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function createStreamHandle(machine, close) {
|
|
117
|
+
return {
|
|
118
|
+
[exports.STREAM_HANDLE_BRAND]: true,
|
|
119
|
+
close,
|
|
120
|
+
get state() {
|
|
121
|
+
return machine.state;
|
|
122
|
+
},
|
|
123
|
+
done: machine.done,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
const describeFailure = (failure) => failure.kind === 'end'
|
|
127
|
+
? 'stream ended'
|
|
128
|
+
: `${failure.kind}: ${failure.error.message}`;
|
|
129
|
+
const describeReason = (reason) => reason.kind === 'stream-failed'
|
|
130
|
+
? `stream failed (${describeFailure(reason.failure)})`
|
|
131
|
+
: reason.kind;
|
|
132
|
+
// An exhaustive lookup rather than a `switch` (see STYLE.md): adding a state
|
|
133
|
+
// to `StreamState` without describing it here fails `tsc`.
|
|
134
|
+
const describers = {
|
|
135
|
+
open: () => 'open',
|
|
136
|
+
reconnecting: (s) => `reconnecting (attempt ${s.attempt}, ${describeFailure(s.cause)})`,
|
|
137
|
+
closed: (s) => `closed (${describeReason(s.reason)})`,
|
|
138
|
+
};
|
|
139
|
+
/** Human-readable description of a state, for logs. */
|
|
140
|
+
const describeStreamState = (state) => describers[state.status](state);
|
|
141
|
+
exports.describeStreamState = describeStreamState;
|
|
142
|
+
//# sourceMappingURL=StreamLifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StreamLifecycle.js","sourceRoot":"","sources":["../../../src/zeebe/lib/StreamLifecycle.ts"],"names":[],"mappings":";;;AAiIA,oCAyCC;AAuDD,4DAwBC;AAED,gDAYC;AAtKD;;;;;GAKG;AACI,MAAM,QAAQ,GAAG,CAAI,MAAe,EAA2B,EAAE,CACvE,MAAiC,CAAA;AADrB,QAAA,QAAQ,YACa;AAElC;;;;;;GAMG;AACI,MAAM,YAAY,GAAG,CAAC,MAAqC,EAAQ,EAAE;IAC3E,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;IACnC,MAAM,C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,MAAM,UAAU,GAAoB;IACnC,IAAI,EAAE,GAAG,EAAE,CAAC,MAAM;IAClB,YAAY,EAAE,CAAC,CAAC,EAAE,EAAE,CACnB,yBAAyB,CAAC,CAAC,OAAO,KAAK,eAAe,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG;IACnE,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG;CACrD,CAAA;AAED,uDAAuD;AAChD,MAAM,mBAAmB,GAAG,CAAC,KAAkB,EAAU,EAAE,CAChE,UAAU,CAAC,KAAK,CAAC,MAAM,CAAgC,CAAC,KAAK,CAAC,CAAA;AADnD,QAAA,mBAAmB,uBACgC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ZeebeGrpcClient } from '../zb/ZeebeGrpcClient';
|
|
2
2
|
import { StatefulLogInterceptor } from './StatefulLogInterceptor';
|
|
3
|
+
import { StreamHandle } from './StreamLifecycle';
|
|
3
4
|
import { IZBJobWorker, Job, JobCompletionInterface, ZBGrpc, ZBWorkerTaskHandler } from './interfaces-1.0';
|
|
4
5
|
import { StreamActivatedJobsRequest } from './interfaces-grpc-1.0';
|
|
5
6
|
/**
|
|
@@ -39,14 +40,29 @@ export interface StreamJobsRecoveryOptions {
|
|
|
39
40
|
maxDelayMs?: number;
|
|
40
41
|
};
|
|
41
42
|
}
|
|
43
|
+
export declare const DRAIN_RETRY_MIN_DELAY_MS = 50;
|
|
44
|
+
export declare const DRAIN_RETRY_MAX_DELAY_MS = 5000;
|
|
45
|
+
/**
|
|
46
|
+
* Whether an activation error is temporary (broker backpressure, gateway
|
|
47
|
+
* unavailable, deadline exceeded) and the activation should be retried.
|
|
48
|
+
*/
|
|
49
|
+
export declare const isTransientActivationError: (e: unknown) => boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Delay before the `attempt`-th retry (1-based) of a failed backlog
|
|
52
|
+
* activation: exponential from 50ms by a factor of 1.6, capped at 5s, with
|
|
53
|
+
* +/-10% jitter.
|
|
54
|
+
*/
|
|
55
|
+
export declare const drainRetryDelayMs: (attempt: number, random?: () => number) => number;
|
|
42
56
|
export declare class ZBStreamWorker implements IZBJobWorker {
|
|
43
57
|
private grpcClient;
|
|
44
58
|
private logger;
|
|
45
59
|
private zbClient;
|
|
46
60
|
private streams;
|
|
61
|
+
private machines;
|
|
47
62
|
private closed;
|
|
48
63
|
private pollTimers;
|
|
49
64
|
private reconnectTimers;
|
|
65
|
+
private retryWaits;
|
|
50
66
|
constructor({ grpcClient, log, zbClient, }: {
|
|
51
67
|
grpcClient: ZBGrpc;
|
|
52
68
|
log: StatefulLogInterceptor;
|
|
@@ -81,9 +97,7 @@ export declare class ZBStreamWorker implements IZBJobWorker {
|
|
|
81
97
|
* polling (the initial backfill poll still runs).
|
|
82
98
|
*/
|
|
83
99
|
pollInterval?: number;
|
|
84
|
-
} & StreamJobsRecoveryOptions): Promise<
|
|
85
|
-
close: () => void;
|
|
86
|
-
}>;
|
|
100
|
+
} & StreamJobsRecoveryOptions): Promise<StreamHandle>;
|
|
87
101
|
close(): Promise<void>;
|
|
88
102
|
log(msg: JSON): void;
|
|
89
103
|
debug(msg: JSON): void;
|