@hatchet-dev/typescript-sdk 0.8.0-alpha.3 → 0.8.0-alpha.4
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/clients/admin/admin-client.d.ts +13 -7
- package/clients/admin/admin-client.js +23 -18
- package/clients/dispatcher/heartbeat/heartbeat-controller.d.ts +0 -1
- package/clients/hatchet-client/hatchet-client.js +1 -1
- package/clients/listener/child-listener-client.d.ts +0 -1
- package/clients/listener/listener-client.d.ts +6 -14
- package/clients/listener/listener-client.js +16 -85
- package/clients/rest/generated/Api.d.ts +44 -117
- package/clients/rest/generated/Api.js +34 -112
- package/clients/rest/generated/data-contracts.d.ts +33 -54
- package/clients/rest/generated/http-client.js +2 -2
- package/clients/worker/handler.d.ts +2 -2
- package/clients/worker/handler.js +48 -38
- package/clients/worker/worker.d.ts +1 -2
- package/clients/worker/worker.js +1 -3
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +2 -2
- package/protoc/dispatcher/dispatcher.js +13 -13
- package/protoc/workflows/workflows.js +5 -5
- package/step.d.ts +11 -13
- package/step.js +13 -70
- package/util/config-loader/token.js +2 -3
- package/util/parse.js +1 -2
- package/util/retrier.js +1 -2
- package/util/thread-helper.d.ts +0 -1
- package/util/thread-helper.js +1 -2
- package/util/workflow-run-ref.d.ts +17 -0
- package/util/workflow-run-ref.js +94 -0
|
@@ -2,8 +2,10 @@ import { Channel, ClientFactory } from 'nice-grpc';
|
|
|
2
2
|
import { CreateWorkflowVersionOpts, RateLimitDuration, WorkflowServiceClient } from '../../protoc/workflows';
|
|
3
3
|
import { ClientConfig } from '../hatchet-client/client-config';
|
|
4
4
|
import { Logger } from '../../util/logger';
|
|
5
|
+
import WorkflowRunRef from '../../util/workflow-run-ref';
|
|
5
6
|
import { Api } from '../rest';
|
|
6
7
|
import { WebhookWorkerCreateRequest, WorkflowRunStatus, WorkflowRunStatusList } from '../rest/generated/data-contracts';
|
|
8
|
+
import { ListenerClient } from '../listener/listener-client';
|
|
7
9
|
type WorkflowMetricsQuery = {
|
|
8
10
|
workflowId?: string;
|
|
9
11
|
workflowName?: string;
|
|
@@ -32,7 +34,8 @@ export declare class AdminClient {
|
|
|
32
34
|
api: Api;
|
|
33
35
|
tenantId: string;
|
|
34
36
|
logger: Logger;
|
|
35
|
-
|
|
37
|
+
listenerClient: ListenerClient;
|
|
38
|
+
constructor(config: ClientConfig, channel: Channel, factory: ClientFactory, api: Api, tenantId: string, listenerClient: ListenerClient);
|
|
36
39
|
/**
|
|
37
40
|
* @deprecated use putWorkflow instead
|
|
38
41
|
*/
|
|
@@ -48,7 +51,7 @@ export declare class AdminClient {
|
|
|
48
51
|
*/
|
|
49
52
|
put_rate_limit(key: string, limit: number, duration: RateLimitDuration): Promise<void>;
|
|
50
53
|
putRateLimit(key: string, limit: number, duration?: RateLimitDuration): Promise<void>;
|
|
51
|
-
webhook_create(data: WebhookWorkerCreateRequest): Promise<import("axios").AxiosResponse<import("../rest/generated/data-contracts").
|
|
54
|
+
webhook_create(data: WebhookWorkerCreateRequest): Promise<import("axios").AxiosResponse<import("../rest/generated/data-contracts").WebhookWorkerCreated, any>>;
|
|
52
55
|
/**
|
|
53
56
|
* @deprecated use runWorkflow instead
|
|
54
57
|
*/
|
|
@@ -58,7 +61,7 @@ export declare class AdminClient {
|
|
|
58
61
|
childIndex?: number | undefined;
|
|
59
62
|
childKey?: string | undefined;
|
|
60
63
|
additionalMetadata?: Record<string, string> | undefined;
|
|
61
|
-
}): Promise<
|
|
64
|
+
}): Promise<WorkflowRunRef<object>>;
|
|
62
65
|
/**
|
|
63
66
|
* Run a new instance of a workflow with the given input. This will create a new workflow run and return the ID of the
|
|
64
67
|
* new run.
|
|
@@ -67,13 +70,13 @@ export declare class AdminClient {
|
|
|
67
70
|
* @param options an object containing the options to run the workflow
|
|
68
71
|
* @returns the ID of the new workflow run
|
|
69
72
|
*/
|
|
70
|
-
runWorkflow<
|
|
73
|
+
runWorkflow<Q = object, P = object>(workflowName: string, input: Q, options?: {
|
|
71
74
|
parentId?: string | undefined;
|
|
72
75
|
parentStepRunId?: string | undefined;
|
|
73
76
|
childIndex?: number | undefined;
|
|
74
77
|
childKey?: string | undefined;
|
|
75
78
|
additionalMetadata?: Record<string, string> | undefined;
|
|
76
|
-
}):
|
|
79
|
+
}): WorkflowRunRef<P>;
|
|
77
80
|
/**
|
|
78
81
|
* @deprecated use listWorkflows instead
|
|
79
82
|
*/
|
|
@@ -107,13 +110,13 @@ export declare class AdminClient {
|
|
|
107
110
|
/**
|
|
108
111
|
* @deprecated use getWorkflowRun instead
|
|
109
112
|
*/
|
|
110
|
-
get_workflow_run(workflowRunId: string): Promise<
|
|
113
|
+
get_workflow_run(workflowRunId: string): Promise<WorkflowRunRef<unknown>>;
|
|
111
114
|
/**
|
|
112
115
|
* Get a workflow run.
|
|
113
116
|
* @param workflowRunId the id of the workflow run to get
|
|
114
117
|
* @returns the workflow run
|
|
115
118
|
*/
|
|
116
|
-
getWorkflowRun(workflowRunId: string): Promise<
|
|
119
|
+
getWorkflowRun(workflowRunId: string): Promise<WorkflowRunRef<unknown>>;
|
|
117
120
|
/**
|
|
118
121
|
* @deprecated use listWorkflowRuns instead
|
|
119
122
|
*/
|
|
@@ -147,14 +150,17 @@ export declare class AdminClient {
|
|
|
147
150
|
*/
|
|
148
151
|
schedule_workflow(name: string, options?: {
|
|
149
152
|
schedules?: Date[];
|
|
153
|
+
input?: object;
|
|
150
154
|
}): Promise<void>;
|
|
151
155
|
/**
|
|
152
156
|
* Schedule a workflow to run at a specific time or times.
|
|
153
157
|
* @param name the name of the workflow to schedule
|
|
154
158
|
* @param options an object containing the schedules to set
|
|
159
|
+
* @param input an object containing the input to the workflow
|
|
155
160
|
*/
|
|
156
161
|
scheduleWorkflow(name: string, options?: {
|
|
157
162
|
schedules?: Date[];
|
|
163
|
+
input?: object;
|
|
158
164
|
}): void;
|
|
159
165
|
/**
|
|
160
166
|
* @deprecated use getWorkflowMetrics instead
|
|
@@ -17,6 +17,7 @@ const workflows_1 = require("../../protoc/workflows");
|
|
|
17
17
|
const hatchet_error_1 = __importDefault(require("../../util/errors/hatchet-error"));
|
|
18
18
|
const logger_1 = require("../../util/logger");
|
|
19
19
|
const retrier_1 = require("../../util/retrier");
|
|
20
|
+
const workflow_run_ref_1 = __importDefault(require("../../util/workflow-run-ref"));
|
|
20
21
|
/**
|
|
21
22
|
* AdminClient is a client for interacting with the Hatchet Admin API. This allows you to configure, trigger,
|
|
22
23
|
* and monitor workflows.
|
|
@@ -34,12 +35,13 @@ const retrier_1 = require("../../util/retrier");
|
|
|
34
35
|
* ```
|
|
35
36
|
*/
|
|
36
37
|
class AdminClient {
|
|
37
|
-
constructor(config, channel, factory, api, tenantId) {
|
|
38
|
+
constructor(config, channel, factory, api, tenantId, listenerClient) {
|
|
38
39
|
this.config = config;
|
|
39
40
|
this.client = factory.create(workflows_1.WorkflowServiceDefinition, channel);
|
|
40
41
|
this.api = api;
|
|
41
42
|
this.tenantId = tenantId;
|
|
42
43
|
this.logger = new logger_1.Logger(`Admin`, config.log_level);
|
|
44
|
+
this.listenerClient = listenerClient;
|
|
43
45
|
}
|
|
44
46
|
/**
|
|
45
47
|
* @deprecated use putWorkflow instead
|
|
@@ -110,22 +112,20 @@ class AdminClient {
|
|
|
110
112
|
* @returns the ID of the new workflow run
|
|
111
113
|
*/
|
|
112
114
|
runWorkflow(workflowName, input, options) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
computedName = this.config.namespace + workflowName;
|
|
118
|
-
}
|
|
119
|
-
const inputStr = JSON.stringify(input);
|
|
120
|
-
const resp = yield this.client.triggerWorkflow(Object.assign(Object.assign({ name: computedName, input: inputStr }, options), { additionalMetadata: (options === null || options === void 0 ? void 0 : options.additionalMetadata)
|
|
121
|
-
? JSON.stringify(options === null || options === void 0 ? void 0 : options.additionalMetadata)
|
|
122
|
-
: undefined }));
|
|
123
|
-
return resp.workflowRunId;
|
|
124
|
-
}
|
|
125
|
-
catch (e) {
|
|
126
|
-
throw new hatchet_error_1.default(e.message);
|
|
115
|
+
let computedName = workflowName;
|
|
116
|
+
try {
|
|
117
|
+
if (this.config.namespace && !workflowName.startsWith(this.config.namespace)) {
|
|
118
|
+
computedName = this.config.namespace + workflowName;
|
|
127
119
|
}
|
|
128
|
-
|
|
120
|
+
const inputStr = JSON.stringify(input);
|
|
121
|
+
const resp = this.client.triggerWorkflow(Object.assign(Object.assign({ name: computedName, input: inputStr }, options), { additionalMetadata: (options === null || options === void 0 ? void 0 : options.additionalMetadata)
|
|
122
|
+
? JSON.stringify(options === null || options === void 0 ? void 0 : options.additionalMetadata)
|
|
123
|
+
: undefined }));
|
|
124
|
+
return new workflow_run_ref_1.default(resp, this.listenerClient, options === null || options === void 0 ? void 0 : options.parentId);
|
|
125
|
+
}
|
|
126
|
+
catch (e) {
|
|
127
|
+
throw new hatchet_error_1.default(e.message);
|
|
128
|
+
}
|
|
129
129
|
}
|
|
130
130
|
/**
|
|
131
131
|
* @deprecated use listWorkflows instead
|
|
@@ -201,8 +201,7 @@ class AdminClient {
|
|
|
201
201
|
*/
|
|
202
202
|
getWorkflowRun(workflowRunId) {
|
|
203
203
|
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
-
|
|
205
|
-
return res.data;
|
|
204
|
+
return new workflow_run_ref_1.default(workflowRunId, this.listenerClient);
|
|
206
205
|
});
|
|
207
206
|
}
|
|
208
207
|
/**
|
|
@@ -236,12 +235,18 @@ class AdminClient {
|
|
|
236
235
|
* Schedule a workflow to run at a specific time or times.
|
|
237
236
|
* @param name the name of the workflow to schedule
|
|
238
237
|
* @param options an object containing the schedules to set
|
|
238
|
+
* @param input an object containing the input to the workflow
|
|
239
239
|
*/
|
|
240
240
|
scheduleWorkflow(name, options) {
|
|
241
241
|
try {
|
|
242
|
+
let input;
|
|
243
|
+
if (options === null || options === void 0 ? void 0 : options.input) {
|
|
244
|
+
input = JSON.stringify(options.input);
|
|
245
|
+
}
|
|
242
246
|
this.client.scheduleWorkflow({
|
|
243
247
|
name,
|
|
244
248
|
schedules: options === null || options === void 0 ? void 0 : options.schedules,
|
|
249
|
+
input,
|
|
245
250
|
});
|
|
246
251
|
}
|
|
247
252
|
catch (e) {
|
|
@@ -111,8 +111,8 @@ class HatchetClient {
|
|
|
111
111
|
this.api = (0, rest_1.default)(this.config.api_url, this.config.token, axiosOpts);
|
|
112
112
|
this.event = new event_client_1.EventClient(this.config, (0, exports.channelFactory)(this.config, this.credentials), clientFactory);
|
|
113
113
|
this.dispatcher = new dispatcher_client_1.DispatcherClient(this.config, (0, exports.channelFactory)(this.config, this.credentials), clientFactory);
|
|
114
|
-
this.admin = new admin_client_1.AdminClient(this.config, (0, exports.channelFactory)(this.config, this.credentials), clientFactory, this.api, this.tenantId);
|
|
115
114
|
this.listener = new listener_client_1.ListenerClient(this.config, (0, exports.channelFactory)(this.config, this.credentials), clientFactory, this.api);
|
|
115
|
+
this.admin = new admin_client_1.AdminClient(this.config, (0, exports.channelFactory)(this.config, this.credentials), clientFactory, this.api, this.tenantId, this.listener);
|
|
116
116
|
this.logger = new logger_1.default('HatchetClient', this.config.log_level);
|
|
117
117
|
this.logger.info(`Initialized HatchetClient`);
|
|
118
118
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { Channel, ClientFactory } from 'nice-grpc';
|
|
3
2
|
import { EventEmitter } from 'events';
|
|
4
|
-
import { DispatcherClient as PbDispatcherClient } from '../../protoc/dispatcher';
|
|
3
|
+
import { DispatcherClient as PbDispatcherClient, DispatcherClient } from '../../protoc/dispatcher';
|
|
5
4
|
import { ClientConfig } from '../hatchet-client/client-config';
|
|
6
5
|
import { Logger } from '../../util/logger';
|
|
7
6
|
import { Api } from '../rest';
|
|
@@ -23,21 +22,15 @@ export interface StepRunEvent {
|
|
|
23
22
|
type: RunEventType;
|
|
24
23
|
payload: string;
|
|
25
24
|
}
|
|
26
|
-
export declare class
|
|
27
|
-
client:
|
|
25
|
+
export declare class RunEventListener {
|
|
26
|
+
client: DispatcherClient;
|
|
28
27
|
q: Array<StepRunEvent>;
|
|
29
28
|
eventEmitter: EventEmitter<[never]>;
|
|
30
29
|
pollInterval: any;
|
|
31
|
-
constructor(workflowRunid: string, client:
|
|
30
|
+
constructor(workflowRunid: string, client: DispatcherClient);
|
|
32
31
|
emit(event: StepRunEvent): void;
|
|
33
32
|
listen(workflowRunId: string): Promise<void>;
|
|
34
33
|
retrySubscribe(workflowRunId: string): Promise<AsyncIterable<import("../../protoc/dispatcher").WorkflowEvent>>;
|
|
35
|
-
getWorkflowRun(workflowRunId: string): Promise<{
|
|
36
|
-
type: RunEventType;
|
|
37
|
-
payload: string;
|
|
38
|
-
} | undefined>;
|
|
39
|
-
polling(workflowRunId: string): Promise<void>;
|
|
40
|
-
close(): void;
|
|
41
34
|
stream(): AsyncGenerator<StepRunEvent, void, unknown>;
|
|
42
35
|
}
|
|
43
36
|
export declare class ListenerClient {
|
|
@@ -45,9 +38,8 @@ export declare class ListenerClient {
|
|
|
45
38
|
client: PbDispatcherClient;
|
|
46
39
|
logger: Logger;
|
|
47
40
|
api: Api;
|
|
48
|
-
|
|
41
|
+
pooledListener: GrpcPooledListener | undefined;
|
|
49
42
|
constructor(config: ClientConfig, channel: Channel, factory: ClientFactory, api: Api);
|
|
50
|
-
|
|
51
|
-
get(workflowRunId: string): PollingAsyncListener;
|
|
43
|
+
get(workflowRunId: string): import("./child-listener-client").Streamable;
|
|
52
44
|
stream(workflowRunId: string): Promise<AsyncGenerator<StepRunEvent, void, unknown>>;
|
|
53
45
|
}
|
|
@@ -32,7 +32,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
32
32
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.ListenerClient = exports.
|
|
35
|
+
exports.ListenerClient = exports.RunEventListener = exports.RunEventType = void 0;
|
|
36
36
|
// eslint-disable-next-line max-classes-per-file
|
|
37
37
|
const nice_grpc_1 = require("nice-grpc");
|
|
38
38
|
const events_1 = require("events");
|
|
@@ -94,13 +94,12 @@ const workflowStatusMap = {
|
|
|
94
94
|
[data_contracts_1.WorkflowRunStatus.RUNNING]: undefined,
|
|
95
95
|
[data_contracts_1.WorkflowRunStatus.QUEUED]: undefined,
|
|
96
96
|
};
|
|
97
|
-
class
|
|
97
|
+
class RunEventListener {
|
|
98
98
|
constructor(workflowRunid, client) {
|
|
99
99
|
this.q = [];
|
|
100
100
|
this.eventEmitter = new events_1.EventEmitter();
|
|
101
101
|
this.client = client;
|
|
102
102
|
this.listen(workflowRunid);
|
|
103
|
-
this.polling(workflowRunid);
|
|
104
103
|
}
|
|
105
104
|
emit(event) {
|
|
106
105
|
this.q.push(event);
|
|
@@ -110,14 +109,9 @@ class PollingAsyncListener {
|
|
|
110
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
111
110
|
var _a, e_1, _b, _c;
|
|
112
111
|
var _d;
|
|
113
|
-
let listener = this.client.
|
|
112
|
+
let listener = this.client.subscribeToWorkflowEvents({
|
|
114
113
|
workflowRunId,
|
|
115
114
|
});
|
|
116
|
-
const res = yield this.getWorkflowRun(workflowRunId);
|
|
117
|
-
if (res) {
|
|
118
|
-
this.emit(res);
|
|
119
|
-
this.close();
|
|
120
|
-
}
|
|
121
115
|
try {
|
|
122
116
|
try {
|
|
123
117
|
for (var _e = true, listener_1 = __asyncValues(listener), listener_1_1; listener_1_1 = yield listener_1.next(), _a = listener_1_1.done, !_a; _e = true) {
|
|
@@ -126,19 +120,10 @@ class PollingAsyncListener {
|
|
|
126
120
|
const workflowEvent = _c;
|
|
127
121
|
const eventType = (_d = resourceTypeMap[workflowEvent.resourceType]) === null || _d === void 0 ? void 0 : _d[workflowEvent.eventType];
|
|
128
122
|
if (eventType) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
this.emit(data);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
this.emit({
|
|
138
|
-
type: eventType,
|
|
139
|
-
payload: workflowEvent.eventPayload,
|
|
140
|
-
});
|
|
141
|
-
}
|
|
123
|
+
this.emit({
|
|
124
|
+
type: eventType,
|
|
125
|
+
payload: workflowEvent.eventPayload,
|
|
126
|
+
});
|
|
142
127
|
}
|
|
143
128
|
}
|
|
144
129
|
}
|
|
@@ -158,7 +143,6 @@ class PollingAsyncListener {
|
|
|
158
143
|
listener = yield this.retrySubscribe(workflowRunId);
|
|
159
144
|
}
|
|
160
145
|
}
|
|
161
|
-
setTimeout(() => this.close(), DEFAULT_EVENT_LISTENER_POLL_INTERVAL * 5);
|
|
162
146
|
});
|
|
163
147
|
}
|
|
164
148
|
retrySubscribe(workflowRunId) {
|
|
@@ -167,7 +151,7 @@ class PollingAsyncListener {
|
|
|
167
151
|
while (retries < DEFAULT_EVENT_LISTENER_RETRY_COUNT) {
|
|
168
152
|
try {
|
|
169
153
|
yield (0, sleep_1.default)(DEFAULT_EVENT_LISTENER_RETRY_INTERVAL);
|
|
170
|
-
const listener = this.client.
|
|
154
|
+
const listener = this.client.subscribeToWorkflowEvents({
|
|
171
155
|
workflowRunId,
|
|
172
156
|
});
|
|
173
157
|
return listener;
|
|
@@ -179,54 +163,6 @@ class PollingAsyncListener {
|
|
|
179
163
|
throw new hatchet_error_1.default(`Could not subscribe to the worker after ${DEFAULT_EVENT_LISTENER_RETRY_COUNT} retries`);
|
|
180
164
|
});
|
|
181
165
|
}
|
|
182
|
-
getWorkflowRun(workflowRunId) {
|
|
183
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
184
|
-
var _a, _b, _c;
|
|
185
|
-
try {
|
|
186
|
-
const res = yield this.client.api.workflowRunGet(this.client.config.tenant_id, workflowRunId);
|
|
187
|
-
const stepRuns = (_c = (_b = (_a = res.data.jobRuns) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.stepRuns) !== null && _c !== void 0 ? _c : [];
|
|
188
|
-
const stepRunOutput = stepRuns.reduce((acc, stepRun) => {
|
|
189
|
-
var _a;
|
|
190
|
-
acc[((_a = stepRun.step) === null || _a === void 0 ? void 0 : _a.readableId) || ''] = JSON.parse(stepRun.output || '{}');
|
|
191
|
-
return acc;
|
|
192
|
-
}, {});
|
|
193
|
-
if (Object.keys(workflowStatusMap).includes(res.data.status)) {
|
|
194
|
-
const type = workflowStatusMap[res.data.status];
|
|
195
|
-
if (!type)
|
|
196
|
-
return undefined;
|
|
197
|
-
return {
|
|
198
|
-
type,
|
|
199
|
-
payload: JSON.stringify(stepRunOutput),
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
return undefined;
|
|
203
|
-
}
|
|
204
|
-
catch (e) {
|
|
205
|
-
throw new hatchet_error_1.default(e.message);
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
polling(workflowRunId) {
|
|
210
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
211
|
-
this.pollInterval = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
212
|
-
try {
|
|
213
|
-
const result = yield this.getWorkflowRun(workflowRunId);
|
|
214
|
-
if (result) {
|
|
215
|
-
this.emit(result);
|
|
216
|
-
this.close();
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
catch (e) {
|
|
220
|
-
// TODO error handling
|
|
221
|
-
}
|
|
222
|
-
}), DEFAULT_EVENT_LISTENER_POLL_INTERVAL);
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
close() {
|
|
226
|
-
if (this.pollInterval) {
|
|
227
|
-
clearInterval(this.pollInterval);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
166
|
stream() {
|
|
231
167
|
return __asyncGenerator(this, arguments, function* stream_1() {
|
|
232
168
|
var _a, e_2, _b, _c;
|
|
@@ -253,33 +189,28 @@ class PollingAsyncListener {
|
|
|
253
189
|
});
|
|
254
190
|
}
|
|
255
191
|
}
|
|
256
|
-
exports.
|
|
192
|
+
exports.RunEventListener = RunEventListener;
|
|
257
193
|
class ListenerClient {
|
|
258
194
|
constructor(config, channel, factory, api) {
|
|
259
|
-
this.childListeners = {};
|
|
260
195
|
this.config = config;
|
|
261
196
|
this.client = factory.create(dispatcher_1.DispatcherDefinition, channel);
|
|
262
197
|
this.logger = new logger_1.Logger(`Listener`, config.log_level);
|
|
263
198
|
this.api = api;
|
|
264
199
|
}
|
|
265
|
-
|
|
266
|
-
if (!this.
|
|
267
|
-
this.
|
|
268
|
-
|
|
269
|
-
delete this.childListeners[parentWorkflowRunId];
|
|
200
|
+
get(workflowRunId) {
|
|
201
|
+
if (!this.pooledListener) {
|
|
202
|
+
this.pooledListener = new child_listener_client_1.GrpcPooledListener(this, () => {
|
|
203
|
+
this.pooledListener = undefined;
|
|
270
204
|
});
|
|
271
205
|
}
|
|
272
|
-
return this.
|
|
206
|
+
return this.pooledListener.subscribe({
|
|
273
207
|
workflowRunId,
|
|
274
208
|
});
|
|
275
209
|
}
|
|
276
|
-
get(workflowRunId) {
|
|
277
|
-
const listener = new PollingAsyncListener(workflowRunId, this);
|
|
278
|
-
return listener;
|
|
279
|
-
}
|
|
280
210
|
stream(workflowRunId) {
|
|
281
211
|
return __awaiter(this, void 0, void 0, function* () {
|
|
282
|
-
|
|
212
|
+
const listener = new RunEventListener(workflowRunId, this.client);
|
|
213
|
+
return listener.stream();
|
|
283
214
|
});
|
|
284
215
|
}
|
|
285
216
|
}
|