@hatchet-dev/typescript-sdk 0.0.1 → 0.0.3
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 +2 -3
- package/dist/{hatchet/clients → clients}/admin/admin-client.d.ts +2 -2
- package/dist/{hatchet/clients → clients}/admin/admin-client.js +2 -2
- package/dist/{hatchet/clients → clients}/dispatcher/action-listener.d.ts +3 -3
- package/dist/{hatchet/clients → clients}/dispatcher/action-listener.js +2 -2
- package/dist/{hatchet/clients → clients}/dispatcher/dispatcher-client.d.ts +3 -3
- package/dist/{hatchet/clients → clients}/dispatcher/dispatcher-client.js +2 -2
- package/dist/{hatchet/clients → clients}/event/event-client.d.ts +3 -3
- package/dist/{hatchet/clients → clients}/event/event-client.js +2 -2
- package/dist/{hatchet/clients → clients}/hatchet-client/hatchet-client.d.ts +6 -6
- package/dist/{hatchet/clients → clients}/hatchet-client/hatchet-client.js +6 -6
- package/dist/{hatchet/clients → clients}/worker/worker.d.ts +6 -6
- package/dist/{hatchet/clients → clients}/worker/worker.js +5 -5
- package/dist/index.d.ts +2 -0
- package/dist/{hatchet/index.js → index.js} +1 -1
- package/dist/protoc/events/index.js +17 -0
- package/dist/sdk.d.ts +2 -0
- package/dist/{hatchet/sdk.js → sdk.js} +1 -1
- package/dist/{hatchet/step.js → step.js} +1 -1
- package/dist/{hatchet/util → util}/config-loader/config-loader.d.ts +1 -1
- package/dist/{hatchet/util → util}/config-loader/config-loader.js +1 -1
- package/package.json +8 -5
- package/.eslintrc.json +0 -36
- package/.prettierrc.json +0 -6
- package/dist/hatchet/clients/admin/admin-client.test.d.ts +0 -1
- package/dist/hatchet/clients/admin/admin-client.test.js +0 -101
- package/dist/hatchet/clients/dispatcher/action-listener.test.d.ts +0 -4
- package/dist/hatchet/clients/dispatcher/action-listener.test.js +0 -277
- package/dist/hatchet/clients/dispatcher/dispatcher-client.test.d.ts +0 -1
- package/dist/hatchet/clients/dispatcher/dispatcher-client.test.js +0 -99
- package/dist/hatchet/clients/event/event-client.test.d.ts +0 -1
- package/dist/hatchet/clients/event/event-client.test.js +0 -60
- package/dist/hatchet/clients/hatchet-client/hatchet-client.test.d.ts +0 -2
- package/dist/hatchet/clients/hatchet-client/hatchet-client.test.js +0 -135
- package/dist/hatchet/clients/worker/worker.test.d.ts +0 -1
- package/dist/hatchet/clients/worker/worker.test.js +0 -256
- package/dist/hatchet/index.d.ts +0 -2
- package/dist/hatchet/sdk.d.ts +0 -2
- package/dist/hatchet/util/config-loader/config-loader.test.d.ts +0 -1
- package/dist/hatchet/util/config-loader/config-loader.test.js +0 -72
- package/dist/hatchet/util/hatchet-promise/hatchet-promise.test.d.ts +0 -1
- package/dist/hatchet/util/hatchet-promise/hatchet-promise.test.js +0 -40
- package/examples/dag-worker.ts +0 -55
- package/examples/example-event.ts +0 -7
- package/examples/simple-worker.ts +0 -39
- package/generate-protoc.sh +0 -10
- package/hatchet/clients/admin/admin-client.test.ts +0 -116
- package/hatchet/clients/admin/admin-client.ts +0 -43
- package/hatchet/clients/dispatcher/action-listener.test.ts +0 -270
- package/hatchet/clients/dispatcher/action-listener.ts +0 -91
- package/hatchet/clients/dispatcher/dispatcher-client.test.ts +0 -111
- package/hatchet/clients/dispatcher/dispatcher-client.ts +0 -47
- package/hatchet/clients/event/event-client.test.ts +0 -72
- package/hatchet/clients/event/event-client.ts +0 -32
- package/hatchet/clients/hatchet-client/client-config.ts +0 -22
- package/hatchet/clients/hatchet-client/fixtures/.hatchet-invalid.yaml +0 -6
- package/hatchet/clients/hatchet-client/fixtures/.hatchet.yaml +0 -8
- package/hatchet/clients/hatchet-client/hatchet-client.test.ts +0 -162
- package/hatchet/clients/hatchet-client/hatchet-client.ts +0 -136
- package/hatchet/clients/hatchet-client/index.ts +0 -2
- package/hatchet/clients/worker/index.ts +0 -1
- package/hatchet/clients/worker/worker.test.ts +0 -347
- package/hatchet/clients/worker/worker.ts +0 -229
- package/hatchet/index.ts +0 -3
- package/hatchet/sdk.ts +0 -3
- package/hatchet/step.ts +0 -48
- package/hatchet/util/config-loader/config-loader.test.ts +0 -79
- package/hatchet/util/config-loader/config-loader.ts +0 -91
- package/hatchet/util/config-loader/fixtures/.hatchet-invalid.yaml +0 -6
- package/hatchet/util/config-loader/fixtures/.hatchet.yaml +0 -8
- package/hatchet/util/config-loader/index.ts +0 -1
- package/hatchet/util/errors/hatchet-error.ts +0 -8
- package/hatchet/util/hatchet-promise/hatchet-promise.test.ts +0 -32
- package/hatchet/util/hatchet-promise/hatchet-promise.ts +0 -13
- package/hatchet/util/logger/index.ts +0 -1
- package/hatchet/util/logger/logger.ts +0 -44
- package/hatchet/util/sleep.ts +0 -6
- package/hatchet/workflow.ts +0 -30
- package/jest.config.ts +0 -205
- package/protoc/dispatcher/dispatcher.ts +0 -1101
- package/protoc/dispatcher/index.ts +0 -1
- package/protoc/events/events.ts +0 -519
- package/protoc/google/protobuf/timestamp.ts +0 -210
- package/protoc/google/protobuf/wrappers.ts +0 -657
- package/protoc/workflows/index.ts +0 -1
- package/protoc/workflows/workflows.ts +0 -2158
- package/tsconfig.json +0 -120
- /package/dist/{hatchet/clients → clients}/hatchet-client/client-config.d.ts +0 -0
- /package/dist/{hatchet/clients → clients}/hatchet-client/client-config.js +0 -0
- /package/dist/{hatchet/clients → clients}/hatchet-client/index.d.ts +0 -0
- /package/dist/{hatchet/clients → clients}/hatchet-client/index.js +0 -0
- /package/dist/{hatchet/clients → clients}/worker/index.d.ts +0 -0
- /package/dist/{hatchet/clients → clients}/worker/index.js +0 -0
- /package/{protoc/events/index.ts → dist/protoc/events/index.d.ts} +0 -0
- /package/dist/{hatchet/step.d.ts → step.d.ts} +0 -0
- /package/dist/{hatchet/util → util}/config-loader/index.d.ts +0 -0
- /package/dist/{hatchet/util → util}/config-loader/index.js +0 -0
- /package/dist/{hatchet/util → util}/errors/hatchet-error.d.ts +0 -0
- /package/dist/{hatchet/util → util}/errors/hatchet-error.js +0 -0
- /package/dist/{hatchet/util → util}/hatchet-promise/hatchet-promise.d.ts +0 -0
- /package/dist/{hatchet/util → util}/hatchet-promise/hatchet-promise.js +0 -0
- /package/dist/{hatchet/util → util}/logger/index.d.ts +0 -0
- /package/dist/{hatchet/util → util}/logger/index.js +0 -0
- /package/dist/{hatchet/util → util}/logger/logger.d.ts +0 -0
- /package/dist/{hatchet/util → util}/logger/logger.js +0 -0
- /package/dist/{hatchet/util → util}/sleep.d.ts +0 -0
- /package/dist/{hatchet/util → util}/sleep.js +0 -0
- /package/dist/{hatchet/workflow.d.ts → workflow.d.ts} +0 -0
- /package/dist/{hatchet/workflow.js → workflow.js} +0 -0
|
@@ -1,277 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,99 +0,0 @@
|
|
|
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 dispatcher_1 = require("@protoc/dispatcher");
|
|
13
|
-
const dispatcher_client_1 = require("./dispatcher-client");
|
|
14
|
-
const hatchet_client_test_1 = require("../hatchet-client/hatchet-client.test");
|
|
15
|
-
let client;
|
|
16
|
-
describe('DispatcherClient', () => {
|
|
17
|
-
it('should create a client', () => {
|
|
18
|
-
const x = new dispatcher_client_1.DispatcherClient({
|
|
19
|
-
token: 'TOKEN',
|
|
20
|
-
host_port: 'HOST_PORT',
|
|
21
|
-
log_level: 'OFF',
|
|
22
|
-
tls_config: {
|
|
23
|
-
cert_file: 'TLS_CERT_FILE',
|
|
24
|
-
key_file: 'TLS_KEY_FILE',
|
|
25
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
26
|
-
server_name: 'TLS_SERVER_NAME',
|
|
27
|
-
},
|
|
28
|
-
}, hatchet_client_test_1.mockChannel, hatchet_client_test_1.mockFactory);
|
|
29
|
-
expect(x).toBeDefined();
|
|
30
|
-
});
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
client = new dispatcher_client_1.DispatcherClient({
|
|
33
|
-
token: 'TOKEN',
|
|
34
|
-
host_port: 'HOST_PORT',
|
|
35
|
-
log_level: 'OFF',
|
|
36
|
-
tls_config: {
|
|
37
|
-
cert_file: 'TLS_CERT_FILE',
|
|
38
|
-
key_file: 'TLS_KEY_FILE',
|
|
39
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
40
|
-
server_name: 'TLS_SERVER_NAME',
|
|
41
|
-
},
|
|
42
|
-
}, hatchet_client_test_1.mockChannel, hatchet_client_test_1.mockFactory);
|
|
43
|
-
});
|
|
44
|
-
describe('get_action_listener', () => {
|
|
45
|
-
it('should register the worker', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
-
const clientSpy = jest.spyOn(client.client, 'register').mockResolvedValue({
|
|
47
|
-
workerId: 'WORKER_ID',
|
|
48
|
-
tenantId: 'TENANT_ID',
|
|
49
|
-
workerName: 'WORKER_NAME',
|
|
50
|
-
});
|
|
51
|
-
const listenerSpy = jest.spyOn(client.client, 'listen');
|
|
52
|
-
const listener = yield client.get_action_listener({
|
|
53
|
-
workerName: 'WORKER_NAME',
|
|
54
|
-
services: ['SERVICE'],
|
|
55
|
-
actions: ['ACTION'],
|
|
56
|
-
});
|
|
57
|
-
expect(clientSpy).toHaveBeenCalledWith({
|
|
58
|
-
workerName: 'WORKER_NAME',
|
|
59
|
-
services: ['SERVICE'],
|
|
60
|
-
actions: ['ACTION'],
|
|
61
|
-
});
|
|
62
|
-
expect(listenerSpy).toHaveBeenCalledWith({
|
|
63
|
-
workerId: 'WORKER_ID',
|
|
64
|
-
});
|
|
65
|
-
expect(listener).toBeDefined();
|
|
66
|
-
expect(listener.workerId).toEqual('WORKER_ID');
|
|
67
|
-
}));
|
|
68
|
-
});
|
|
69
|
-
describe('send_action_event', () => {
|
|
70
|
-
it('should send action events', () => {
|
|
71
|
-
const clientSpy = jest.spyOn(client.client, 'sendActionEvent').mockResolvedValue({
|
|
72
|
-
tenantId: 'TENANT_ID',
|
|
73
|
-
workerId: 'WORKER_ID',
|
|
74
|
-
});
|
|
75
|
-
client.send_action_event({
|
|
76
|
-
workerId: 'WORKER_ID',
|
|
77
|
-
actionId: 'ACTION_ID',
|
|
78
|
-
eventType: dispatcher_1.ActionEventType.STEP_EVENT_TYPE_COMPLETED,
|
|
79
|
-
eventPayload: '{"foo":"bar"}',
|
|
80
|
-
eventTimestamp: new Date(),
|
|
81
|
-
jobId: 'a',
|
|
82
|
-
jobRunId: 'b',
|
|
83
|
-
stepId: 'c',
|
|
84
|
-
stepRunId: 'd',
|
|
85
|
-
});
|
|
86
|
-
expect(clientSpy).toHaveBeenCalledWith({
|
|
87
|
-
workerId: 'WORKER_ID',
|
|
88
|
-
actionId: 'ACTION_ID',
|
|
89
|
-
eventType: dispatcher_1.ActionEventType.STEP_EVENT_TYPE_COMPLETED,
|
|
90
|
-
eventPayload: '{"foo":"bar"}',
|
|
91
|
-
jobId: 'a',
|
|
92
|
-
jobRunId: 'b',
|
|
93
|
-
stepId: 'c',
|
|
94
|
-
stepRunId: 'd',
|
|
95
|
-
eventTimestamp: expect.any(Object),
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const hatchet_error_1 = __importDefault(require("@util/errors/hatchet-error"));
|
|
7
|
-
const event_client_1 = require("./event-client");
|
|
8
|
-
const hatchet_client_test_1 = require("../hatchet-client/hatchet-client.test");
|
|
9
|
-
let client;
|
|
10
|
-
describe('EventClient', () => {
|
|
11
|
-
it('should create a client', () => {
|
|
12
|
-
const x = new event_client_1.EventClient({
|
|
13
|
-
token: 'TOKEN',
|
|
14
|
-
host_port: 'HOST_PORT',
|
|
15
|
-
tls_config: {
|
|
16
|
-
cert_file: 'TLS_CERT_FILE',
|
|
17
|
-
key_file: 'TLS_KEY_FILE',
|
|
18
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
19
|
-
server_name: 'TLS_SERVER_NAME',
|
|
20
|
-
},
|
|
21
|
-
}, hatchet_client_test_1.mockChannel, hatchet_client_test_1.mockFactory);
|
|
22
|
-
expect(x).toBeDefined();
|
|
23
|
-
});
|
|
24
|
-
beforeEach(() => {
|
|
25
|
-
client = new event_client_1.EventClient({
|
|
26
|
-
token: 'TOKEN',
|
|
27
|
-
host_port: 'HOST_PORT',
|
|
28
|
-
tls_config: {
|
|
29
|
-
cert_file: 'TLS_CERT_FILE',
|
|
30
|
-
key_file: 'TLS_KEY_FILE',
|
|
31
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
32
|
-
server_name: 'TLS_SERVER_NAME',
|
|
33
|
-
},
|
|
34
|
-
}, hatchet_client_test_1.mockChannel, hatchet_client_test_1.mockFactory);
|
|
35
|
-
});
|
|
36
|
-
it('should push events', () => {
|
|
37
|
-
const clientSpy = jest.spyOn(client.client, 'push').mockResolvedValue({
|
|
38
|
-
tenantId: 'x',
|
|
39
|
-
eventId: 'y',
|
|
40
|
-
key: 'z',
|
|
41
|
-
eventTimestamp: new Date(),
|
|
42
|
-
payload: 'string',
|
|
43
|
-
});
|
|
44
|
-
client.push('type', { foo: 'bar' });
|
|
45
|
-
expect(clientSpy).toHaveBeenCalledWith({
|
|
46
|
-
key: 'type',
|
|
47
|
-
payload: '{"foo":"bar"}',
|
|
48
|
-
eventTimestamp: expect.any(Date),
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
it('should throw an error when push fails', () => {
|
|
52
|
-
const clientSpy = jest.spyOn(client.client, 'push');
|
|
53
|
-
clientSpy.mockImplementation(() => {
|
|
54
|
-
throw new Error('foo');
|
|
55
|
-
});
|
|
56
|
-
expect(() => {
|
|
57
|
-
client.push('type', { foo: 'bar' });
|
|
58
|
-
}).toThrow(new hatchet_error_1.default('foo'));
|
|
59
|
-
});
|
|
60
|
-
});
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mockFactory = exports.mockChannel = void 0;
|
|
4
|
-
const nice_grpc_1 = require("nice-grpc");
|
|
5
|
-
const hatchet_client_1 = require("./hatchet-client");
|
|
6
|
-
exports.mockChannel = (0, nice_grpc_1.createChannel)('localhost:50051');
|
|
7
|
-
exports.mockFactory = (0, nice_grpc_1.createClientFactory)();
|
|
8
|
-
describe('Client', () => {
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
process.env.HATCHET_CLIENT_TOKEN = 'TOKEN_ENV';
|
|
11
|
-
});
|
|
12
|
-
it('should load from environment variables', () => {
|
|
13
|
-
const hatchet = new hatchet_client_1.HatchetClient({
|
|
14
|
-
token: 'TOKEN_ENV',
|
|
15
|
-
host_port: 'HOST_PORT',
|
|
16
|
-
log_level: 'OFF',
|
|
17
|
-
tls_config: {
|
|
18
|
-
cert_file: 'TLS_CERT_FILE',
|
|
19
|
-
key_file: 'TLS_KEY_FILE',
|
|
20
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
21
|
-
server_name: 'TLS_SERVER_NAME',
|
|
22
|
-
},
|
|
23
|
-
}, {
|
|
24
|
-
credentials: nice_grpc_1.ChannelCredentials.createInsecure(),
|
|
25
|
-
});
|
|
26
|
-
expect(hatchet.config).toEqual({
|
|
27
|
-
token: 'TOKEN_ENV',
|
|
28
|
-
host_port: 'HOST_PORT',
|
|
29
|
-
log_level: 'OFF',
|
|
30
|
-
tls_config: {
|
|
31
|
-
tls_strategy: 'tls',
|
|
32
|
-
cert_file: 'TLS_CERT_FILE',
|
|
33
|
-
key_file: 'TLS_KEY_FILE',
|
|
34
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
35
|
-
server_name: 'TLS_SERVER_NAME',
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
it('should throw an error if the config param is invalid', () => {
|
|
40
|
-
expect(() => new hatchet_client_1.HatchetClient({
|
|
41
|
-
host_port: 'HOST_PORT',
|
|
42
|
-
tls_config: {
|
|
43
|
-
tls_strategy: 'tls',
|
|
44
|
-
cert_file: 'TLS_CERT_FILE',
|
|
45
|
-
key_file: 'TLS_KEY_FILE',
|
|
46
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
47
|
-
// @ts-ignore
|
|
48
|
-
server_name: undefined,
|
|
49
|
-
},
|
|
50
|
-
})).toThrow();
|
|
51
|
-
});
|
|
52
|
-
it('should favor config param over yaml over env vars ', () => {
|
|
53
|
-
const hatchet = new hatchet_client_1.HatchetClient({
|
|
54
|
-
tls_config: {
|
|
55
|
-
cert_file: 'TLS_CERT_FILE',
|
|
56
|
-
key_file: 'TLS_KEY_FILE',
|
|
57
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
58
|
-
server_name: 'TLS_SERVER_NAME',
|
|
59
|
-
},
|
|
60
|
-
}, {
|
|
61
|
-
config_path: './fixtures/.hatchet.yaml',
|
|
62
|
-
credentials: nice_grpc_1.ChannelCredentials.createInsecure(),
|
|
63
|
-
});
|
|
64
|
-
expect(hatchet.config).toEqual({
|
|
65
|
-
token: 'TOKEN_YAML',
|
|
66
|
-
host_port: 'HOST_PORT_YAML',
|
|
67
|
-
log_level: 'INFO',
|
|
68
|
-
tls_config: {
|
|
69
|
-
tls_strategy: 'tls',
|
|
70
|
-
cert_file: 'TLS_CERT_FILE',
|
|
71
|
-
key_file: 'TLS_KEY_FILE',
|
|
72
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
73
|
-
server_name: 'TLS_SERVER_NAME',
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
describe('with_host_port', () => {
|
|
78
|
-
it('should set the host_port', () => {
|
|
79
|
-
const hatchet = hatchet_client_1.HatchetClient.with_host_port('HOST', 1234, {
|
|
80
|
-
token: 'TOKEN',
|
|
81
|
-
tls_config: {
|
|
82
|
-
tls_strategy: 'tls',
|
|
83
|
-
cert_file: 'TLS_CERT_FILE',
|
|
84
|
-
key_file: 'TLS_KEY_FILE',
|
|
85
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
86
|
-
server_name: 'TLS_SERVER_NAME',
|
|
87
|
-
},
|
|
88
|
-
}, {
|
|
89
|
-
credentials: nice_grpc_1.ChannelCredentials.createInsecure(),
|
|
90
|
-
});
|
|
91
|
-
expect(hatchet.config).toEqual({
|
|
92
|
-
token: 'TOKEN',
|
|
93
|
-
host_port: 'HOST:1234',
|
|
94
|
-
log_level: 'INFO',
|
|
95
|
-
tls_config: {
|
|
96
|
-
tls_strategy: 'tls',
|
|
97
|
-
cert_file: 'TLS_CERT_FILE',
|
|
98
|
-
key_file: 'TLS_KEY_FILE',
|
|
99
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
100
|
-
server_name: 'TLS_SERVER_NAME',
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
describe('Worker', () => {
|
|
106
|
-
let hatchet;
|
|
107
|
-
beforeEach(() => {
|
|
108
|
-
hatchet = new hatchet_client_1.HatchetClient({
|
|
109
|
-
token: 'TOKEN',
|
|
110
|
-
host_port: 'HOST_PORT',
|
|
111
|
-
log_level: 'OFF',
|
|
112
|
-
tls_config: {
|
|
113
|
-
cert_file: 'TLS_CERT_FILE',
|
|
114
|
-
key_file: 'TLS_KEY_FILE',
|
|
115
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
116
|
-
server_name: 'TLS_SERVER_NAME',
|
|
117
|
-
},
|
|
118
|
-
}, {
|
|
119
|
-
credentials: nice_grpc_1.ChannelCredentials.createInsecure(),
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
describe('run', () => {
|
|
123
|
-
xit('should start a worker', () => {
|
|
124
|
-
const worker = hatchet.run('workflow1');
|
|
125
|
-
expect(worker).toBeDefined();
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
describe('worker', () => {
|
|
129
|
-
it('should start a worker', () => {
|
|
130
|
-
const worker = hatchet.worker('workflow1');
|
|
131
|
-
expect(worker).toBeDefined();
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|