@hatchet-dev/typescript-sdk 0.5.5 → 0.5.7

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.
@@ -17,6 +17,6 @@ export declare class DispatcherClient {
17
17
  getActionListener(options: GetActionListenerOptions): Promise<ActionListener>;
18
18
  sendStepActionEvent(in_: StepActionEvent): Promise<import("../../protoc/dispatcher").ActionEventResponse>;
19
19
  sendGroupKeyActionEvent(in_: GroupKeyActionEvent): Promise<import("../../protoc/dispatcher").ActionEventResponse>;
20
- putOverridesData(in_: DeepPartial<OverridesData>): Promise<import("../../protoc/dispatcher").OverridesDataResponse>;
20
+ putOverridesData(in_: DeepPartial<OverridesData>): Promise<void | import("../../protoc/dispatcher").OverridesDataResponse>;
21
21
  }
22
22
  export {};
@@ -34,7 +34,7 @@ class DispatcherClient {
34
34
  sendStepActionEvent(in_) {
35
35
  return __awaiter(this, void 0, void 0, function* () {
36
36
  try {
37
- return (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.client.sendStepActionEvent(in_); }), this.logger);
37
+ return yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.client.sendStepActionEvent(in_); }), this.logger);
38
38
  }
39
39
  catch (e) {
40
40
  throw new hatchet_error_1.default(e.message);
@@ -44,7 +44,7 @@ class DispatcherClient {
44
44
  sendGroupKeyActionEvent(in_) {
45
45
  return __awaiter(this, void 0, void 0, function* () {
46
46
  try {
47
- return (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.client.sendGroupKeyActionEvent(in_); }), this.logger);
47
+ return yield (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.client.sendGroupKeyActionEvent(in_); }), this.logger);
48
48
  }
49
49
  catch (e) {
50
50
  throw new hatchet_error_1.default(e.message);
@@ -53,12 +53,9 @@ class DispatcherClient {
53
53
  }
54
54
  putOverridesData(in_) {
55
55
  return __awaiter(this, void 0, void 0, function* () {
56
- try {
57
- return (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.client.putOverridesData(in_); }), this.logger);
58
- }
59
- catch (e) {
60
- throw new hatchet_error_1.default(e.message);
61
- }
56
+ return (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.client.putOverridesData(in_); }), this.logger).catch((e) => {
57
+ this.logger.warn(`Could not put overrides data: ${e.message}`);
58
+ });
62
59
  });
63
60
  }
64
61
  }
@@ -50,20 +50,17 @@ class EventClient {
50
50
  }
51
51
  putLog(stepRunId, log, level) {
52
52
  const createdAt = new Date();
53
- try {
54
- (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () {
55
- return this.client.putLog({
56
- stepRunId,
57
- createdAt,
58
- message: log,
59
- level: level || LogLevel.INFO,
60
- });
61
- }), this.logger);
62
- }
63
- catch (e) {
53
+ (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () {
54
+ return this.client.putLog({
55
+ stepRunId,
56
+ createdAt,
57
+ message: log,
58
+ level: level || LogLevel.INFO,
59
+ });
60
+ }), this.logger).catch((e) => {
64
61
  // log a warning, but this is not a fatal error
65
62
  this.logger.warn(`Could not put log: ${e.message}`);
66
- }
63
+ });
67
64
  }
68
65
  putStream(stepRunId, data) {
69
66
  const createdAt = new Date();
@@ -77,19 +74,16 @@ class EventClient {
77
74
  else {
78
75
  throw new Error('Invalid data type. Expected string or Uint8Array.');
79
76
  }
80
- try {
81
- (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () {
82
- return this.client.putStreamEvent({
83
- stepRunId,
84
- createdAt,
85
- message: dataBytes,
86
- });
87
- }), this.logger);
88
- }
89
- catch (e) {
77
+ (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () {
78
+ return this.client.putStreamEvent({
79
+ stepRunId,
80
+ createdAt,
81
+ message: dataBytes,
82
+ });
83
+ }), this.logger).catch((e) => {
90
84
  // log a warning, but this is not a fatal error
91
85
  this.logger.warn(`Could not put log: ${e.message}`);
92
- }
86
+ });
93
87
  }
94
88
  }
95
89
  exports.EventClient = EventClient;
@@ -125,7 +125,9 @@ class Worker {
125
125
  try {
126
126
  // Send the action event to the dispatcher
127
127
  const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_COMPLETED, result);
128
- this.client.dispatcher.sendStepActionEvent(event);
128
+ this.client.dispatcher.sendStepActionEvent(event).catch((e) => {
129
+ this.logger.error(`Could not send action event: ${e.message}`);
130
+ });
129
131
  // delete the run from the futures
130
132
  delete this.futures[action.stepRunId];
131
133
  }
@@ -144,7 +146,9 @@ class Worker {
144
146
  message: error === null || error === void 0 ? void 0 : error.message,
145
147
  stack: error === null || error === void 0 ? void 0 : error.stack,
146
148
  });
147
- this.client.dispatcher.sendStepActionEvent(event);
149
+ this.client.dispatcher.sendStepActionEvent(event).catch((e) => {
150
+ this.logger.error(`Could not send action event: ${e.message}`);
151
+ });
148
152
  // delete the run from the futures
149
153
  delete this.futures[action.stepRunId];
150
154
  }
@@ -156,7 +160,9 @@ class Worker {
156
160
  this.futures[action.stepRunId] = future;
157
161
  // Send the action event to the dispatcher
158
162
  const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_STARTED);
159
- this.client.dispatcher.sendStepActionEvent(event);
163
+ this.client.dispatcher.sendStepActionEvent(event).catch((e) => {
164
+ this.logger.error(`Could not send action event: ${e.message}`);
165
+ });
160
166
  }
161
167
  catch (e) {
162
168
  this.logger.error(`Could not send action event: ${e.message}`);
@@ -182,7 +188,9 @@ class Worker {
182
188
  try {
183
189
  // Send the action event to the dispatcher
184
190
  const event = this.getGroupKeyActionEvent(action, dispatcher_1.GroupKeyActionEventType.GROUP_KEY_EVENT_TYPE_COMPLETED, result);
185
- this.client.dispatcher.sendGroupKeyActionEvent(event);
191
+ this.client.dispatcher.sendGroupKeyActionEvent(event).catch((e) => {
192
+ this.logger.error(`Could not send action event: ${e.message}`);
193
+ });
186
194
  // delete the run from the futures
187
195
  delete this.futures[key];
188
196
  }
@@ -195,7 +203,9 @@ class Worker {
195
203
  try {
196
204
  // Send the action event to the dispatcher
197
205
  const event = this.getGroupKeyActionEvent(action, dispatcher_1.GroupKeyActionEventType.GROUP_KEY_EVENT_TYPE_FAILED, error);
198
- this.client.dispatcher.sendGroupKeyActionEvent(event);
206
+ this.client.dispatcher.sendGroupKeyActionEvent(event).catch((e) => {
207
+ this.logger.error(`Could not send action event: ${e.message}`);
208
+ });
199
209
  // delete the run from the futures
200
210
  delete this.futures[key];
201
211
  }
@@ -207,7 +217,9 @@ class Worker {
207
217
  this.futures[action.getGroupKeyRunId] = future;
208
218
  // Send the action event to the dispatcher
209
219
  const event = this.getGroupKeyActionEvent(action, dispatcher_1.GroupKeyActionEventType.GROUP_KEY_EVENT_TYPE_STARTED);
210
- this.client.dispatcher.sendGroupKeyActionEvent(event);
220
+ this.client.dispatcher.sendGroupKeyActionEvent(event).catch((e) => {
221
+ this.logger.error(`Could not send action event: ${e.message}`);
222
+ });
211
223
  }
212
224
  catch (e) {
213
225
  this.logger.error(`Could not send action event: ${e.message}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "0.5.5",
3
+ "version": "0.5.7",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -15,7 +15,7 @@ class Logger {
15
15
  this.logLevel = logLevel;
16
16
  this.context = context;
17
17
  }
18
- log(level, message, color = '33') {
18
+ log(level, message, color) {
19
19
  if (LogLevelEnum[level] >= LogLevelEnum[this.logLevel]) {
20
20
  const time = new Date().toLocaleString('en-US', {
21
21
  month: '2-digit',
@@ -26,14 +26,14 @@ class Logger {
26
26
  second: '2-digit',
27
27
  });
28
28
  // eslint-disable-next-line no-console
29
- console.log(`🪓 ${process.pid} | ${time} \x1b[${color}m [${level}/${this.context}] ${message}\x1b[0m`);
29
+ console.log(`🪓 ${process.pid} | ${time} ${color && `\x1b[${color}m`} [${level}/${this.context}] ${message}\x1b[0m`);
30
30
  }
31
31
  }
32
32
  debug(message) {
33
33
  this.log('DEBUG', message, '35');
34
34
  }
35
35
  info(message) {
36
- this.log('INFO', message, '90');
36
+ this.log('INFO', message);
37
37
  }
38
38
  green(message) {
39
39
  this.log('INFO', message, '32');
package/util/retrier.js CHANGED
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.retrier = void 0;
16
16
  const sleep_1 = __importDefault(require("./sleep"));
17
- const DEFAULT_RETRY_INTERVAL = 5;
17
+ const DEFAULT_RETRY_INTERVAL = 5; // seconds
18
18
  const DEFAULT_RETRY_COUNT = 5;
19
19
  function retrier(fn, logger, retries = DEFAULT_RETRY_COUNT, interval = DEFAULT_RETRY_INTERVAL) {
20
20
  return __awaiter(this, void 0, void 0, function* () {