@hatchet-dev/typescript-sdk 0.0.1
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 +36 -0
- package/.prettierrc.json +6 -0
- package/README.md +4 -0
- package/dist/hatchet/clients/admin/admin-client.d.ts +14 -0
- package/dist/hatchet/clients/admin/admin-client.js +50 -0
- package/dist/hatchet/clients/admin/admin-client.test.d.ts +1 -0
- package/dist/hatchet/clients/admin/admin-client.test.js +101 -0
- package/dist/hatchet/clients/dispatcher/action-listener.d.ts +24 -0
- package/dist/hatchet/clients/dispatcher/action-listener.js +113 -0
- package/dist/hatchet/clients/dispatcher/action-listener.test.d.ts +4 -0
- package/dist/hatchet/clients/dispatcher/action-listener.test.js +277 -0
- package/dist/hatchet/clients/dispatcher/dispatcher-client.d.ts +17 -0
- package/dist/hatchet/clients/dispatcher/dispatcher-client.js +46 -0
- package/dist/hatchet/clients/dispatcher/dispatcher-client.test.d.ts +1 -0
- package/dist/hatchet/clients/dispatcher/dispatcher-client.test.js +99 -0
- package/dist/hatchet/clients/event/event-client.d.ts +9 -0
- package/dist/hatchet/clients/event/event-client.js +28 -0
- package/dist/hatchet/clients/event/event-client.test.d.ts +1 -0
- package/dist/hatchet/clients/event/event-client.test.js +60 -0
- package/dist/hatchet/clients/hatchet-client/client-config.d.ts +72 -0
- package/dist/hatchet/clients/hatchet-client/client-config.js +17 -0
- package/dist/hatchet/clients/hatchet-client/hatchet-client.d.ts +26 -0
- package/dist/hatchet/clients/hatchet-client/hatchet-client.js +133 -0
- package/dist/hatchet/clients/hatchet-client/hatchet-client.test.d.ts +2 -0
- package/dist/hatchet/clients/hatchet-client/hatchet-client.test.js +135 -0
- package/dist/hatchet/clients/hatchet-client/index.d.ts +2 -0
- package/dist/hatchet/clients/hatchet-client/index.js +18 -0
- package/dist/hatchet/clients/worker/index.d.ts +1 -0
- package/dist/hatchet/clients/worker/index.js +17 -0
- package/dist/hatchet/clients/worker/worker.d.ts +31 -0
- package/dist/hatchet/clients/worker/worker.js +228 -0
- package/dist/hatchet/clients/worker/worker.test.d.ts +1 -0
- package/dist/hatchet/clients/worker/worker.test.js +256 -0
- package/dist/hatchet/index.d.ts +2 -0
- package/dist/hatchet/index.js +4 -0
- package/dist/hatchet/sdk.d.ts +2 -0
- package/dist/hatchet/sdk.js +4 -0
- package/dist/hatchet/step.d.ts +30 -0
- package/dist/hatchet/step.js +63 -0
- package/dist/hatchet/util/config-loader/config-loader.d.ts +13 -0
- package/dist/hatchet/util/config-loader/config-loader.js +85 -0
- package/dist/hatchet/util/config-loader/config-loader.test.d.ts +1 -0
- package/dist/hatchet/util/config-loader/config-loader.test.js +72 -0
- package/dist/hatchet/util/config-loader/index.d.ts +1 -0
- package/dist/hatchet/util/config-loader/index.js +17 -0
- package/dist/hatchet/util/errors/hatchet-error.d.ts +4 -0
- package/dist/hatchet/util/errors/hatchet-error.js +9 -0
- package/dist/hatchet/util/hatchet-promise/hatchet-promise.d.ts +6 -0
- package/dist/hatchet/util/hatchet-promise/hatchet-promise.js +12 -0
- package/dist/hatchet/util/hatchet-promise/hatchet-promise.test.d.ts +1 -0
- package/dist/hatchet/util/hatchet-promise/hatchet-promise.test.js +40 -0
- package/dist/hatchet/util/logger/index.d.ts +1 -0
- package/dist/hatchet/util/logger/index.js +17 -0
- package/dist/hatchet/util/logger/logger.d.ts +12 -0
- package/dist/hatchet/util/logger/logger.js +37 -0
- package/dist/hatchet/util/sleep.d.ts +2 -0
- package/dist/hatchet/util/sleep.js +6 -0
- package/dist/hatchet/workflow.d.ts +78 -0
- package/dist/hatchet/workflow.js +44 -0
- package/dist/protoc/dispatcher/dispatcher.d.ts +273 -0
- package/dist/protoc/dispatcher/dispatcher.js +918 -0
- package/dist/protoc/dispatcher/index.d.ts +1 -0
- package/dist/protoc/dispatcher/index.js +17 -0
- package/dist/protoc/events/events.d.ts +165 -0
- package/dist/protoc/events/events.js +443 -0
- package/dist/protoc/google/protobuf/timestamp.d.ts +121 -0
- package/dist/protoc/google/protobuf/timestamp.js +110 -0
- package/dist/protoc/google/protobuf/wrappers.d.ts +160 -0
- package/dist/protoc/google/protobuf/wrappers.js +527 -0
- package/dist/protoc/workflows/index.d.ts +1 -0
- package/dist/protoc/workflows/index.js +17 -0
- package/dist/protoc/workflows/workflows.d.ts +438 -0
- package/dist/protoc/workflows/workflows.js +1814 -0
- package/examples/dag-worker.ts +55 -0
- package/examples/example-event.ts +7 -0
- package/examples/simple-worker.ts +39 -0
- package/generate-protoc.sh +10 -0
- package/hatchet/clients/admin/admin-client.test.ts +116 -0
- package/hatchet/clients/admin/admin-client.ts +43 -0
- package/hatchet/clients/dispatcher/action-listener.test.ts +270 -0
- package/hatchet/clients/dispatcher/action-listener.ts +91 -0
- package/hatchet/clients/dispatcher/dispatcher-client.test.ts +111 -0
- package/hatchet/clients/dispatcher/dispatcher-client.ts +47 -0
- package/hatchet/clients/event/event-client.test.ts +72 -0
- package/hatchet/clients/event/event-client.ts +32 -0
- package/hatchet/clients/hatchet-client/client-config.ts +22 -0
- package/hatchet/clients/hatchet-client/fixtures/.hatchet-invalid.yaml +6 -0
- package/hatchet/clients/hatchet-client/fixtures/.hatchet.yaml +8 -0
- package/hatchet/clients/hatchet-client/hatchet-client.test.ts +162 -0
- package/hatchet/clients/hatchet-client/hatchet-client.ts +136 -0
- package/hatchet/clients/hatchet-client/index.ts +2 -0
- package/hatchet/clients/worker/index.ts +1 -0
- package/hatchet/clients/worker/worker.test.ts +347 -0
- package/hatchet/clients/worker/worker.ts +229 -0
- package/hatchet/index.ts +3 -0
- package/hatchet/sdk.ts +3 -0
- package/hatchet/step.ts +48 -0
- package/hatchet/util/config-loader/config-loader.test.ts +79 -0
- package/hatchet/util/config-loader/config-loader.ts +91 -0
- package/hatchet/util/config-loader/fixtures/.hatchet-invalid.yaml +6 -0
- package/hatchet/util/config-loader/fixtures/.hatchet.yaml +8 -0
- package/hatchet/util/config-loader/index.ts +1 -0
- package/hatchet/util/errors/hatchet-error.ts +8 -0
- package/hatchet/util/hatchet-promise/hatchet-promise.test.ts +32 -0
- package/hatchet/util/hatchet-promise/hatchet-promise.ts +13 -0
- package/hatchet/util/logger/index.ts +1 -0
- package/hatchet/util/logger/logger.ts +44 -0
- package/hatchet/util/sleep.ts +6 -0
- package/hatchet/workflow.ts +30 -0
- package/jest.config.ts +205 -0
- package/package.json +65 -0
- package/protoc/dispatcher/dispatcher.ts +1101 -0
- package/protoc/dispatcher/index.ts +1 -0
- package/protoc/events/events.ts +519 -0
- package/protoc/events/index.ts +1 -0
- package/protoc/google/protobuf/timestamp.ts +210 -0
- package/protoc/google/protobuf/wrappers.ts +657 -0
- package/protoc/workflows/index.ts +1 -0
- package/protoc/workflows/workflows.ts +2158 -0
- package/tsconfig.json +120 -0
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"es6": true,
|
|
4
|
+
"node": true,
|
|
5
|
+
"jest": true
|
|
6
|
+
},
|
|
7
|
+
"extends": ["airbnb-base", "prettier", "plugin:prettier/recommended"],
|
|
8
|
+
"globals": {
|
|
9
|
+
"Atomics": "readonly",
|
|
10
|
+
"SharedArrayBuffer": "readonly"
|
|
11
|
+
},
|
|
12
|
+
"parser": "@typescript-eslint/parser",
|
|
13
|
+
"parserOptions": {
|
|
14
|
+
"ecmaVersion": 11,
|
|
15
|
+
"sourceType": "module"
|
|
16
|
+
},
|
|
17
|
+
"plugins": ["@typescript-eslint", "import", "unused-imports", "prettier", "eslint-plugin-jest"],
|
|
18
|
+
"rules": {
|
|
19
|
+
"@typescript-eslint/no-shadow": "off",
|
|
20
|
+
"@typescript-eslint/no-throw-literal": "off",
|
|
21
|
+
"no-use-before-define": "off",
|
|
22
|
+
"@typescript-eslint/no-use-before-define": "off",
|
|
23
|
+
"import/extensions": "off",
|
|
24
|
+
"unused-imports/no-unused-imports": "error",
|
|
25
|
+
"no-unused-vars": "off",
|
|
26
|
+
"prettier/prettier": "error",
|
|
27
|
+
"@typescript-eslint/no-unused-vars": "warn",
|
|
28
|
+
"curly": "error",
|
|
29
|
+
"import/prefer-default-export": "off",
|
|
30
|
+
"import/no-unresolved": "off",
|
|
31
|
+
"lines-between-class-members": "off",
|
|
32
|
+
"class-methods-use-this": "off",
|
|
33
|
+
"no-await-in-loop": "off",
|
|
34
|
+
"no-restricted-syntax": "off"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/.prettierrc.json
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Channel, ClientFactory } from 'nice-grpc';
|
|
2
|
+
import { CreateWorkflowVersionOpts, WorkflowServiceClient } from '@protoc/workflows';
|
|
3
|
+
import { ClientConfig } from '@clients/hatchet-client/client-config';
|
|
4
|
+
export declare class AdminClient {
|
|
5
|
+
config: ClientConfig;
|
|
6
|
+
client: WorkflowServiceClient;
|
|
7
|
+
constructor(config: ClientConfig, channel: Channel, factory: ClientFactory);
|
|
8
|
+
put_workflow(workflow: CreateWorkflowVersionOpts, options?: {
|
|
9
|
+
autoVersion?: boolean;
|
|
10
|
+
}): Promise<void>;
|
|
11
|
+
schedule_workflow(workflowId: string, options?: {
|
|
12
|
+
schedules?: Date[];
|
|
13
|
+
}): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AdminClient = void 0;
|
|
16
|
+
const workflows_1 = require("@protoc/workflows");
|
|
17
|
+
const hatchet_error_1 = __importDefault(require("@util/errors/hatchet-error"));
|
|
18
|
+
class AdminClient {
|
|
19
|
+
constructor(config, channel, factory) {
|
|
20
|
+
this.config = config;
|
|
21
|
+
this.client = factory.create(workflows_1.WorkflowServiceDefinition, channel);
|
|
22
|
+
}
|
|
23
|
+
put_workflow(workflow, options) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
if (workflow.version === '' && !(options === null || options === void 0 ? void 0 : options.autoVersion)) {
|
|
26
|
+
throw new hatchet_error_1.default('PutWorkflow error: workflow version is required, or use autoVersion');
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
yield this.client.putWorkflow({
|
|
30
|
+
opts: workflow,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
throw new hatchet_error_1.default(e.message);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
schedule_workflow(workflowId, options) {
|
|
39
|
+
try {
|
|
40
|
+
this.client.scheduleWorkflow({
|
|
41
|
+
workflowId,
|
|
42
|
+
schedules: options === null || options === void 0 ? void 0 : options.schedules,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
throw new hatchet_error_1.default(e.message);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.AdminClient = AdminClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const admin_client_1 = require("./admin-client");
|
|
13
|
+
const hatchet_client_test_1 = require("../hatchet-client/hatchet-client.test");
|
|
14
|
+
describe('AdminClient', () => {
|
|
15
|
+
let client;
|
|
16
|
+
it('should create a client', () => {
|
|
17
|
+
const x = new admin_client_1.AdminClient({
|
|
18
|
+
token: 'TOKEN',
|
|
19
|
+
host_port: 'HOST_PORT',
|
|
20
|
+
tls_config: {
|
|
21
|
+
cert_file: 'TLS_CERT_FILE',
|
|
22
|
+
key_file: 'TLS_KEY_FILE',
|
|
23
|
+
ca_file: 'TLS_ROOT_CA_FILE',
|
|
24
|
+
server_name: 'TLS_SERVER_NAME',
|
|
25
|
+
},
|
|
26
|
+
}, hatchet_client_test_1.mockChannel, hatchet_client_test_1.mockFactory);
|
|
27
|
+
expect(x).toBeDefined();
|
|
28
|
+
});
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
client = new admin_client_1.AdminClient({
|
|
31
|
+
token: 'TOKEN',
|
|
32
|
+
host_port: 'HOST_PORT',
|
|
33
|
+
tls_config: {
|
|
34
|
+
cert_file: 'TLS_CERT_FILE',
|
|
35
|
+
key_file: 'TLS_KEY_FILE',
|
|
36
|
+
ca_file: 'TLS_ROOT_CA_FILE',
|
|
37
|
+
server_name: 'TLS_SERVER_NAME',
|
|
38
|
+
},
|
|
39
|
+
}, hatchet_client_test_1.mockChannel, hatchet_client_test_1.mockFactory);
|
|
40
|
+
});
|
|
41
|
+
describe('put_workflow', () => {
|
|
42
|
+
it('should throw an error if no version and not auto version', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
const workflow = {
|
|
44
|
+
name: 'workflow1',
|
|
45
|
+
version: '',
|
|
46
|
+
description: 'description1',
|
|
47
|
+
eventTriggers: [],
|
|
48
|
+
cronTriggers: [],
|
|
49
|
+
scheduledTriggers: [],
|
|
50
|
+
jobs: [],
|
|
51
|
+
};
|
|
52
|
+
expect(() => client.put_workflow(workflow, { autoVersion: false })).rejects.toThrow('PutWorkflow error: workflow version is required, or use autoVersion');
|
|
53
|
+
}));
|
|
54
|
+
it('should attempt to put the workflow', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
const workflow = {
|
|
56
|
+
name: 'workflow1',
|
|
57
|
+
version: 'v0.0.1',
|
|
58
|
+
description: 'description1',
|
|
59
|
+
eventTriggers: [],
|
|
60
|
+
cronTriggers: [],
|
|
61
|
+
scheduledTriggers: [],
|
|
62
|
+
jobs: [],
|
|
63
|
+
};
|
|
64
|
+
const putSpy = jest.spyOn(client.client, 'putWorkflow').mockResolvedValue({
|
|
65
|
+
id: 'workflow1',
|
|
66
|
+
version: 'v0.1.0',
|
|
67
|
+
order: 1,
|
|
68
|
+
workflowId: 'workflow1',
|
|
69
|
+
jobs: [],
|
|
70
|
+
createdAt: undefined,
|
|
71
|
+
updatedAt: undefined,
|
|
72
|
+
triggers: undefined,
|
|
73
|
+
});
|
|
74
|
+
yield client.put_workflow(workflow);
|
|
75
|
+
expect(putSpy).toHaveBeenCalled();
|
|
76
|
+
}));
|
|
77
|
+
});
|
|
78
|
+
describe('schedule_workflow', () => {
|
|
79
|
+
it('should schedule a workflow', () => {
|
|
80
|
+
const res = {
|
|
81
|
+
id: 'string',
|
|
82
|
+
version: 'v0.0.1',
|
|
83
|
+
order: 1,
|
|
84
|
+
workflowId: 'string',
|
|
85
|
+
jobs: [],
|
|
86
|
+
createdAt: undefined,
|
|
87
|
+
updatedAt: undefined,
|
|
88
|
+
triggers: undefined,
|
|
89
|
+
};
|
|
90
|
+
const spy = jest.spyOn(client.client, 'scheduleWorkflow').mockResolvedValue(res);
|
|
91
|
+
const now = new Date();
|
|
92
|
+
client.schedule_workflow('workflowId', {
|
|
93
|
+
schedules: [now],
|
|
94
|
+
});
|
|
95
|
+
expect(spy).toHaveBeenCalledWith({
|
|
96
|
+
workflowId: 'workflowId',
|
|
97
|
+
schedules: [now],
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DispatcherClient as PbDispatcherClient, AssignedAction } from '@protoc/dispatcher';
|
|
2
|
+
import { ClientConfig } from '@clients/hatchet-client/client-config';
|
|
3
|
+
import { DispatcherClient } from './dispatcher-client';
|
|
4
|
+
export interface Action {
|
|
5
|
+
tenantId: string;
|
|
6
|
+
jobId: string;
|
|
7
|
+
jobName: string;
|
|
8
|
+
jobRunId: string;
|
|
9
|
+
stepId: string;
|
|
10
|
+
stepRunId: string;
|
|
11
|
+
actionId: string;
|
|
12
|
+
actionType: number;
|
|
13
|
+
actionPayload: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class ActionListener {
|
|
16
|
+
config: ClientConfig;
|
|
17
|
+
client: PbDispatcherClient;
|
|
18
|
+
listener: AsyncIterable<AssignedAction>;
|
|
19
|
+
workerId: string;
|
|
20
|
+
constructor(client: DispatcherClient, listener: AsyncIterable<AssignedAction>, workerId: string);
|
|
21
|
+
actions: () => AsyncGenerator<Action, void, unknown>;
|
|
22
|
+
retrySubscribe(): Promise<void>;
|
|
23
|
+
unregister(): Promise<import("@protoc/dispatcher").WorkerUnsubscribeResponse>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
12
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
13
|
+
var m = o[Symbol.asyncIterator], i;
|
|
14
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
15
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
16
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
17
|
+
};
|
|
18
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
19
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
20
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
21
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
22
|
+
return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
23
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
24
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
25
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
26
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
27
|
+
function fulfill(value) { resume("next", value); }
|
|
28
|
+
function reject(value) { resume("throw", value); }
|
|
29
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
30
|
+
};
|
|
31
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
32
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.ActionListener = void 0;
|
|
36
|
+
const nice_grpc_1 = require("nice-grpc");
|
|
37
|
+
const sleep_1 = __importDefault(require("@util/sleep"));
|
|
38
|
+
const hatchet_error_1 = __importDefault(require("@util/errors/hatchet-error"));
|
|
39
|
+
const DEFAULT_ACTION_LISTENER_RETRY_INTERVAL = 5; // seconds
|
|
40
|
+
const DEFAULT_ACTION_LISTENER_RETRY_COUNT = 5;
|
|
41
|
+
class ActionListener {
|
|
42
|
+
constructor(client, listener, workerId) {
|
|
43
|
+
this.actions = () => (function gen(client) {
|
|
44
|
+
return __asyncGenerator(this, arguments, function* gen_1() {
|
|
45
|
+
var _a, e_1, _b, _c;
|
|
46
|
+
while (true) {
|
|
47
|
+
try {
|
|
48
|
+
try {
|
|
49
|
+
for (var _d = true, _e = (e_1 = void 0, __asyncValues(client.listener)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
|
|
50
|
+
_c = _f.value;
|
|
51
|
+
_d = false;
|
|
52
|
+
const assignedAction = _c;
|
|
53
|
+
const action = Object.assign({}, assignedAction);
|
|
54
|
+
yield yield __await(action);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
58
|
+
finally {
|
|
59
|
+
try {
|
|
60
|
+
if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
|
|
61
|
+
}
|
|
62
|
+
finally { if (e_1) throw e_1.error; }
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
if (e.code === nice_grpc_1.Status.CANCELLED) {
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
if (e.code === nice_grpc_1.Status.UNAVAILABLE) {
|
|
70
|
+
client.retrySubscribe();
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
})(this);
|
|
77
|
+
this.config = client.config;
|
|
78
|
+
this.client = client.client;
|
|
79
|
+
this.listener = listener;
|
|
80
|
+
this.workerId = workerId;
|
|
81
|
+
}
|
|
82
|
+
retrySubscribe() {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
let retries = 0;
|
|
85
|
+
while (retries < DEFAULT_ACTION_LISTENER_RETRY_COUNT) {
|
|
86
|
+
try {
|
|
87
|
+
yield (0, sleep_1.default)(DEFAULT_ACTION_LISTENER_RETRY_INTERVAL);
|
|
88
|
+
this.listener = this.client.listen({
|
|
89
|
+
workerId: this.workerId,
|
|
90
|
+
});
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
retries += 1;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
throw new hatchet_error_1.default(`Could not subscribe to the worker after ${DEFAULT_ACTION_LISTENER_RETRY_COUNT} retries`);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
unregister() {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
try {
|
|
103
|
+
return this.client.unsubscribe({
|
|
104
|
+
workerId: this.workerId,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
throw new hatchet_error_1.default(`Failed to unsubscribe: ${e.message}`);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.ActionListener = ActionListener;
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
12
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
13
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
14
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
15
|
+
return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
16
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
17
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
18
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
19
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
20
|
+
function fulfill(value) { resume("next", value); }
|
|
21
|
+
function reject(value) { resume("throw", value); }
|
|
22
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
23
|
+
};
|
|
24
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
25
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
26
|
+
var m = o[Symbol.asyncIterator], i;
|
|
27
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
28
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
29
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
30
|
+
};
|
|
31
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
32
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.mockListener = void 0;
|
|
36
|
+
const dispatcher_1 = require("@protoc/dispatcher");
|
|
37
|
+
const sleep_1 = __importDefault(require("@util/sleep"));
|
|
38
|
+
const nice_grpc_common_1 = require("nice-grpc-common");
|
|
39
|
+
const dispatcher_client_1 = require("./dispatcher-client");
|
|
40
|
+
const action_listener_1 = require("./action-listener");
|
|
41
|
+
const hatchet_client_test_1 = require("../hatchet-client/hatchet-client.test");
|
|
42
|
+
let dispatcher;
|
|
43
|
+
// Mock data for AssignedAction
|
|
44
|
+
const mockAssignedActions = [
|
|
45
|
+
{
|
|
46
|
+
tenantId: 'tenant1',
|
|
47
|
+
jobId: 'job1',
|
|
48
|
+
jobName: 'Job One',
|
|
49
|
+
jobRunId: 'run1',
|
|
50
|
+
stepId: 'step1',
|
|
51
|
+
stepRunId: 'runStep1',
|
|
52
|
+
actionId: 'action1',
|
|
53
|
+
actionType: dispatcher_1.ActionType.START_STEP_RUN,
|
|
54
|
+
actionPayload: 'payload1',
|
|
55
|
+
},
|
|
56
|
+
// ... Add more mock AssignedAction objects as needed
|
|
57
|
+
];
|
|
58
|
+
// Mock implementation of the listener
|
|
59
|
+
const mockListener = (fixture) => (function gen() {
|
|
60
|
+
return __asyncGenerator(this, arguments, function* gen_1() {
|
|
61
|
+
for (const action of fixture) {
|
|
62
|
+
// Simulate asynchronous behavior
|
|
63
|
+
yield __await((0, sleep_1.default)(100));
|
|
64
|
+
if (action instanceof Error) {
|
|
65
|
+
throw action;
|
|
66
|
+
}
|
|
67
|
+
yield yield __await(action);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
})();
|
|
71
|
+
exports.mockListener = mockListener;
|
|
72
|
+
describe('ActionListener', () => {
|
|
73
|
+
beforeEach(() => {
|
|
74
|
+
dispatcher = new dispatcher_client_1.DispatcherClient({
|
|
75
|
+
token: 'TOKEN',
|
|
76
|
+
host_port: 'HOST_PORT',
|
|
77
|
+
log_level: 'OFF',
|
|
78
|
+
tls_config: {
|
|
79
|
+
cert_file: 'TLS_CERT_FILE',
|
|
80
|
+
key_file: 'TLS_KEY_FILE',
|
|
81
|
+
ca_file: 'TLS_ROOT_CA_FILE',
|
|
82
|
+
server_name: 'TLS_SERVER_NAME',
|
|
83
|
+
},
|
|
84
|
+
}, hatchet_client_test_1.mockChannel, hatchet_client_test_1.mockFactory);
|
|
85
|
+
});
|
|
86
|
+
it('should create a client', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
|
+
const listener = new action_listener_1.ActionListener(dispatcher, (0, exports.mockListener)(mockAssignedActions), 'WORKER_ID');
|
|
88
|
+
expect(listener).toBeDefined();
|
|
89
|
+
expect(listener.workerId).toEqual('WORKER_ID');
|
|
90
|
+
}));
|
|
91
|
+
describe('actions', () => {
|
|
92
|
+
it('it should "yield" actions', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
93
|
+
var _a, e_1, _b, _c;
|
|
94
|
+
const listener = new action_listener_1.ActionListener(dispatcher, (0, exports.mockListener)([...mockAssignedActions, new nice_grpc_common_1.ServerError(nice_grpc_common_1.Status.CANCELLED, 'CANCELLED')]), 'WORKER_ID');
|
|
95
|
+
const actions = listener.actions();
|
|
96
|
+
const res = [];
|
|
97
|
+
try {
|
|
98
|
+
for (var _d = true, actions_1 = __asyncValues(actions), actions_1_1; actions_1_1 = yield actions_1.next(), _a = actions_1_1.done, !_a; _d = true) {
|
|
99
|
+
_c = actions_1_1.value;
|
|
100
|
+
_d = false;
|
|
101
|
+
const action = _c;
|
|
102
|
+
res.push(action);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
106
|
+
finally {
|
|
107
|
+
try {
|
|
108
|
+
if (!_d && !_a && (_b = actions_1.return)) yield _b.call(actions_1);
|
|
109
|
+
}
|
|
110
|
+
finally { if (e_1) throw e_1.error; }
|
|
111
|
+
}
|
|
112
|
+
expect(res[0]).toEqual({
|
|
113
|
+
tenantId: 'tenant1',
|
|
114
|
+
jobId: 'job1',
|
|
115
|
+
jobName: 'Job One',
|
|
116
|
+
jobRunId: 'run1',
|
|
117
|
+
stepId: 'step1',
|
|
118
|
+
stepRunId: 'runStep1',
|
|
119
|
+
actionId: 'action1',
|
|
120
|
+
actionType: dispatcher_1.ActionType.START_STEP_RUN,
|
|
121
|
+
actionPayload: 'payload1',
|
|
122
|
+
});
|
|
123
|
+
}));
|
|
124
|
+
it('it should break on grpc CANCELLED', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
|
+
var _e, e_2, _f, _g;
|
|
126
|
+
const listener = new action_listener_1.ActionListener(dispatcher, (0, exports.mockListener)([...mockAssignedActions, new nice_grpc_common_1.ServerError(nice_grpc_common_1.Status.CANCELLED, 'CANCELLED')]), 'WORKER_ID');
|
|
127
|
+
const actions = listener.actions();
|
|
128
|
+
const retrySpy = jest.spyOn(listener, 'retrySubscribe').mockResolvedValue(undefined);
|
|
129
|
+
const res = [];
|
|
130
|
+
try {
|
|
131
|
+
for (var _h = true, actions_2 = __asyncValues(actions), actions_2_1; actions_2_1 = yield actions_2.next(), _e = actions_2_1.done, !_e; _h = true) {
|
|
132
|
+
_g = actions_2_1.value;
|
|
133
|
+
_h = false;
|
|
134
|
+
const action = _g;
|
|
135
|
+
res.push(action);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
139
|
+
finally {
|
|
140
|
+
try {
|
|
141
|
+
if (!_h && !_e && (_f = actions_2.return)) yield _f.call(actions_2);
|
|
142
|
+
}
|
|
143
|
+
finally { if (e_2) throw e_2.error; }
|
|
144
|
+
}
|
|
145
|
+
expect(res.length).toEqual(1);
|
|
146
|
+
expect(retrySpy).not.toHaveBeenCalled();
|
|
147
|
+
}));
|
|
148
|
+
it('it should break on unknown error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
149
|
+
var _j, e_3, _k, _l;
|
|
150
|
+
const listener = new action_listener_1.ActionListener(dispatcher, (0, exports.mockListener)([...mockAssignedActions, new Error('Simulated error')]), 'WORKER_ID');
|
|
151
|
+
const actions = listener.actions();
|
|
152
|
+
const retrySpy = jest.spyOn(listener, 'retrySubscribe').mockResolvedValue(undefined);
|
|
153
|
+
const res = [];
|
|
154
|
+
try {
|
|
155
|
+
for (var _m = true, actions_3 = __asyncValues(actions), actions_3_1; actions_3_1 = yield actions_3.next(), _j = actions_3_1.done, !_j; _m = true) {
|
|
156
|
+
_l = actions_3_1.value;
|
|
157
|
+
_m = false;
|
|
158
|
+
const action = _l;
|
|
159
|
+
res.push(action);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
163
|
+
finally {
|
|
164
|
+
try {
|
|
165
|
+
if (!_m && !_j && (_k = actions_3.return)) yield _k.call(actions_3);
|
|
166
|
+
}
|
|
167
|
+
finally { if (e_3) throw e_3.error; }
|
|
168
|
+
}
|
|
169
|
+
expect(res.length).toEqual(1);
|
|
170
|
+
expect(retrySpy).not.toHaveBeenCalled();
|
|
171
|
+
}));
|
|
172
|
+
it('it should attempt to re-establish connection on grpc UNAVAILABLE', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
173
|
+
var _o, e_4, _p, _q;
|
|
174
|
+
const listener = new action_listener_1.ActionListener(dispatcher, (0, exports.mockListener)([...mockAssignedActions, new nice_grpc_common_1.ServerError(nice_grpc_common_1.Status.UNAVAILABLE, 'UNAVAILABLE')]), 'WORKER_ID');
|
|
175
|
+
const retrySpy = jest.spyOn(listener, 'retrySubscribe').mockResolvedValue(undefined);
|
|
176
|
+
const actions = listener.actions();
|
|
177
|
+
const res = [];
|
|
178
|
+
try {
|
|
179
|
+
for (var _r = true, actions_4 = __asyncValues(actions), actions_4_1; actions_4_1 = yield actions_4.next(), _o = actions_4_1.done, !_o; _r = true) {
|
|
180
|
+
_q = actions_4_1.value;
|
|
181
|
+
_r = false;
|
|
182
|
+
const action = _q;
|
|
183
|
+
res.push(action);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
187
|
+
finally {
|
|
188
|
+
try {
|
|
189
|
+
if (!_r && !_o && (_p = actions_4.return)) yield _p.call(actions_4);
|
|
190
|
+
}
|
|
191
|
+
finally { if (e_4) throw e_4.error; }
|
|
192
|
+
}
|
|
193
|
+
expect(res.length).toEqual(1);
|
|
194
|
+
expect(retrySpy).toHaveBeenCalled();
|
|
195
|
+
}));
|
|
196
|
+
});
|
|
197
|
+
describe('retry_subscribe', () => {
|
|
198
|
+
it('should exit after successful connection', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
199
|
+
const listener = new action_listener_1.ActionListener(dispatcher, (0, exports.mockListener)(mockAssignedActions), 'WORKER_ID');
|
|
200
|
+
// Mock the listener to throw an error on the first call
|
|
201
|
+
const listenSpy = jest
|
|
202
|
+
.spyOn(listener.client, 'listen')
|
|
203
|
+
.mockReturnValue((0, exports.mockListener)(mockAssignedActions));
|
|
204
|
+
yield listener.retrySubscribe();
|
|
205
|
+
expect(listenSpy).toHaveBeenCalledTimes(1);
|
|
206
|
+
}));
|
|
207
|
+
it('should retry until success', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
208
|
+
const listener = new action_listener_1.ActionListener(dispatcher, (0, exports.mockListener)(mockAssignedActions), 'WORKER_ID');
|
|
209
|
+
// Mock the listener to throw an error on the first call
|
|
210
|
+
const listenSpy = jest
|
|
211
|
+
.spyOn(listener.client, 'listen')
|
|
212
|
+
.mockImplementationOnce(() => {
|
|
213
|
+
throw new Error('Simulated error');
|
|
214
|
+
})
|
|
215
|
+
.mockImplementationOnce(() => (0, exports.mockListener)(mockAssignedActions));
|
|
216
|
+
yield expect(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
217
|
+
yield listener.retrySubscribe();
|
|
218
|
+
})).not.toThrow();
|
|
219
|
+
}));
|
|
220
|
+
it('should not throw an error if successful', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
221
|
+
const listener = new action_listener_1.ActionListener(dispatcher, (0, exports.mockListener)(mockAssignedActions), 'WORKER_ID');
|
|
222
|
+
// Mock the listener to throw an error on the first call
|
|
223
|
+
const listenSpy = jest
|
|
224
|
+
.spyOn(listener.client, 'listen')
|
|
225
|
+
.mockImplementationOnce(() => {
|
|
226
|
+
throw new Error('Simulated error');
|
|
227
|
+
})
|
|
228
|
+
.mockImplementationOnce(() => (0, exports.mockListener)(mockAssignedActions));
|
|
229
|
+
yield listener.retrySubscribe();
|
|
230
|
+
expect(listenSpy).toHaveBeenCalledTimes(2);
|
|
231
|
+
}));
|
|
232
|
+
it('should retry at most COUNT times and throw an error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
233
|
+
const listener = new action_listener_1.ActionListener(dispatcher, (0, exports.mockListener)(mockAssignedActions), 'WORKER_ID');
|
|
234
|
+
// Mock the listener to throw an error on the first call
|
|
235
|
+
const listenSpy = jest
|
|
236
|
+
.spyOn(listener.client, 'listen')
|
|
237
|
+
.mockImplementationOnce(() => {
|
|
238
|
+
throw new Error('Simulated error');
|
|
239
|
+
})
|
|
240
|
+
.mockImplementationOnce(() => {
|
|
241
|
+
throw new Error('Simulated error');
|
|
242
|
+
})
|
|
243
|
+
.mockImplementationOnce(() => {
|
|
244
|
+
throw new Error('Simulated error');
|
|
245
|
+
})
|
|
246
|
+
.mockImplementationOnce(() => {
|
|
247
|
+
throw new Error('Simulated error');
|
|
248
|
+
})
|
|
249
|
+
.mockImplementationOnce(() => {
|
|
250
|
+
throw new Error('Simulated error');
|
|
251
|
+
})
|
|
252
|
+
.mockImplementationOnce(() => {
|
|
253
|
+
throw new Error('Simulated error');
|
|
254
|
+
})
|
|
255
|
+
.mockImplementationOnce(() => (0, exports.mockListener)(mockAssignedActions));
|
|
256
|
+
try {
|
|
257
|
+
yield listener.retrySubscribe();
|
|
258
|
+
expect(listenSpy).toHaveBeenCalledTimes(5);
|
|
259
|
+
}
|
|
260
|
+
catch (e) {
|
|
261
|
+
expect(e.message).toEqual(`Could not subscribe to the worker after 5 retries`);
|
|
262
|
+
}
|
|
263
|
+
}));
|
|
264
|
+
});
|
|
265
|
+
describe('unregister', () => {
|
|
266
|
+
it('should unsubscribe itself', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
267
|
+
const listener = new action_listener_1.ActionListener(dispatcher, (0, exports.mockListener)(mockAssignedActions), 'WORKER_ID');
|
|
268
|
+
const unsubscribeSpy = jest.spyOn(listener.client, 'unsubscribe').mockResolvedValue({
|
|
269
|
+
tenantId: 'TENANT_ID',
|
|
270
|
+
workerId: 'WORKER_ID',
|
|
271
|
+
});
|
|
272
|
+
const res = yield listener.unregister();
|
|
273
|
+
expect(unsubscribeSpy).toHaveBeenCalled();
|
|
274
|
+
expect(res.workerId).toEqual('WORKER_ID');
|
|
275
|
+
}));
|
|
276
|
+
});
|
|
277
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Channel, ClientFactory } from 'nice-grpc';
|
|
2
|
+
import { DispatcherClient as PbDispatcherClient, ActionEvent } from '@protoc/dispatcher';
|
|
3
|
+
import { ClientConfig } from '@clients/hatchet-client/client-config';
|
|
4
|
+
import { ActionListener } from './action-listener';
|
|
5
|
+
interface GetActionListenerOptions {
|
|
6
|
+
workerName: string;
|
|
7
|
+
services: string[];
|
|
8
|
+
actions: string[];
|
|
9
|
+
}
|
|
10
|
+
export declare class DispatcherClient {
|
|
11
|
+
config: ClientConfig;
|
|
12
|
+
client: PbDispatcherClient;
|
|
13
|
+
constructor(config: ClientConfig, channel: Channel, factory: ClientFactory);
|
|
14
|
+
get_action_listener(options: GetActionListenerOptions): Promise<ActionListener>;
|
|
15
|
+
send_action_event(in_: ActionEvent): Promise<import("@protoc/dispatcher").ActionEventResponse>;
|
|
16
|
+
}
|
|
17
|
+
export {};
|