@hatchet-dev/typescript-sdk 0.15.1-alpha2 → 0.15.1-alpha4
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/worker/worker.js +11 -6
- package/package.json +1 -1
- package/util/retrier.js +8 -3
package/clients/worker/worker.js
CHANGED
|
@@ -189,16 +189,16 @@ class Worker {
|
|
|
189
189
|
delete this.futures[action.stepRunId];
|
|
190
190
|
}
|
|
191
191
|
catch (actionEventError) {
|
|
192
|
-
this.logger.error(`Could not send completed action event: ${actionEventError.message}`);
|
|
192
|
+
this.logger.error(`Could not send completed action event: ${actionEventError.message || actionEventError}`);
|
|
193
193
|
// send a failure event
|
|
194
194
|
const failureEvent = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_FAILED, actionEventError.message);
|
|
195
195
|
try {
|
|
196
196
|
yield this.client.dispatcher.sendStepActionEvent(failureEvent);
|
|
197
197
|
}
|
|
198
198
|
catch (failureEventError) {
|
|
199
|
-
this.logger.error(`Could not send failed action event: ${failureEventError.message}`);
|
|
199
|
+
this.logger.error(`Could not send failed action event: ${failureEventError.message || failureEventError}`);
|
|
200
200
|
}
|
|
201
|
-
this.logger.error(`Could not send action event: ${actionEventError.message}`);
|
|
201
|
+
this.logger.error(`Could not send action event: ${actionEventError.message || actionEventError}`);
|
|
202
202
|
}
|
|
203
203
|
});
|
|
204
204
|
const failure = (error) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -237,10 +237,15 @@ class Worker {
|
|
|
237
237
|
this.client.dispatcher.sendStepActionEvent(event).catch((e) => {
|
|
238
238
|
this.logger.error(`Could not send action event: ${e.message}`);
|
|
239
239
|
});
|
|
240
|
-
|
|
240
|
+
try {
|
|
241
|
+
yield future.promise;
|
|
242
|
+
}
|
|
243
|
+
catch (e) {
|
|
244
|
+
this.logger.error(`Could not wait for step run to finish: ${e}`);
|
|
245
|
+
}
|
|
241
246
|
}
|
|
242
247
|
catch (e) {
|
|
243
|
-
this.logger.error(`Could not send action event: ${e
|
|
248
|
+
this.logger.error(`Could not send action event (outer): ${e}`);
|
|
244
249
|
}
|
|
245
250
|
});
|
|
246
251
|
}
|
|
@@ -356,7 +361,7 @@ class Worker {
|
|
|
356
361
|
}
|
|
357
362
|
}
|
|
358
363
|
catch (e) {
|
|
359
|
-
this.logger.error(`Could not cancel step run: ${e
|
|
364
|
+
this.logger.error(`Could not cancel step run: ${e}`);
|
|
360
365
|
}
|
|
361
366
|
});
|
|
362
367
|
}
|
package/package.json
CHANGED
package/util/retrier.js
CHANGED
|
@@ -14,8 +14,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.retrier = retrier;
|
|
16
16
|
const sleep_1 = __importDefault(require("./sleep"));
|
|
17
|
-
const DEFAULT_RETRY_INTERVAL =
|
|
18
|
-
const DEFAULT_RETRY_COUNT =
|
|
17
|
+
const DEFAULT_RETRY_INTERVAL = 0.1; // seconds
|
|
18
|
+
const DEFAULT_RETRY_COUNT = 8;
|
|
19
|
+
const MAX_JITTER = 400; // milliseconds
|
|
19
20
|
function retrier(fn_1, logger_1) {
|
|
20
21
|
return __awaiter(this, arguments, void 0, function* (fn, logger, retries = DEFAULT_RETRY_COUNT, interval = DEFAULT_RETRY_INTERVAL) {
|
|
21
22
|
let lastError;
|
|
@@ -27,7 +28,11 @@ function retrier(fn_1, logger_1) {
|
|
|
27
28
|
catch (e) {
|
|
28
29
|
lastError = e;
|
|
29
30
|
logger.error(`Error: ${e.message}`);
|
|
30
|
-
|
|
31
|
+
// Calculate exponential backoff with random jitter
|
|
32
|
+
const exponentialDelay = interval * 2 ** i * 1000;
|
|
33
|
+
const jitter = Math.random() * MAX_JITTER;
|
|
34
|
+
const totalDelay = exponentialDelay + jitter;
|
|
35
|
+
yield (0, sleep_1.default)(totalDelay);
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
38
|
throw lastError;
|