@hatchet-dev/typescript-sdk 0.8.0-alpha.0 → 0.8.0-alpha.2

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.
@@ -86,13 +86,13 @@ class AdminClient {
86
86
  */
87
87
  run_workflow(workflowName, input, options) {
88
88
  return __awaiter(this, void 0, void 0, function* () {
89
+ let computedName = workflowName;
89
90
  try {
90
- let wfName = workflowName;
91
91
  if (this.config.namespace && !workflowName.startsWith(this.config.namespace)) {
92
- wfName = this.config.namespace + workflowName;
92
+ computedName = this.config.namespace + workflowName;
93
93
  }
94
94
  const inputStr = JSON.stringify(input);
95
- const resp = yield this.client.triggerWorkflow(Object.assign(Object.assign({ name: wfName, input: inputStr }, options), { additionalMetadata: (options === null || options === void 0 ? void 0 : options.additionalMetadata)
95
+ 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)
96
96
  ? JSON.stringify(options === null || options === void 0 ? void 0 : options.additionalMetadata)
97
97
  : undefined }));
98
98
  return resp.workflowRunId;
@@ -21,6 +21,7 @@ export declare const ActionObject: z.ZodObject<{
21
21
  workflowRunId: z.ZodString;
22
22
  getGroupKeyRunId: z.ZodOptional<z.ZodString>;
23
23
  stepName: z.ZodString;
24
+ retryCount: z.ZodNumber;
24
25
  }, "strip", z.ZodTypeAny, {
25
26
  tenantId: string;
26
27
  stepRunId: string;
@@ -32,6 +33,7 @@ export declare const ActionObject: z.ZodObject<{
32
33
  actionId: string;
33
34
  actionPayload: string;
34
35
  stepName: string;
36
+ retryCount: number;
35
37
  getGroupKeyRunId?: string | undefined;
36
38
  actionType?: number | undefined;
37
39
  }, {
@@ -45,6 +47,7 @@ export declare const ActionObject: z.ZodObject<{
45
47
  actionId: string;
46
48
  actionPayload: string;
47
49
  stepName: string;
50
+ retryCount: number;
48
51
  getGroupKeyRunId?: string | undefined;
49
52
  actionType?: unknown;
50
53
  }>;
@@ -73,6 +76,7 @@ export declare class ActionListener {
73
76
  actionId: string;
74
77
  actionPayload: string;
75
78
  stepName: string;
79
+ retryCount: number;
76
80
  getGroupKeyRunId?: string | undefined;
77
81
  actionType?: number | undefined;
78
82
  }, void, unknown>;
@@ -61,6 +61,7 @@ exports.ActionObject = zod_1.z.object({
61
61
  workflowRunId: zod_1.z.string(),
62
62
  getGroupKeyRunId: zod_1.z.string().optional(),
63
63
  stepName: zod_1.z.string(),
64
+ retryCount: zod_1.z.number(),
64
65
  });
65
66
  class ActionListener {
66
67
  constructor(client, workerId, retryInterval = DEFAULT_ACTION_LISTENER_RETRY_INTERVAL, retryCount = DEFAULT_ACTION_LISTENER_RETRY_COUNT) {
@@ -161,22 +161,29 @@ class Worker {
161
161
  const run = () => __awaiter(this, void 0, void 0, function* () {
162
162
  return step(context);
163
163
  });
164
- const success = (result) => {
164
+ const success = (result) => __awaiter(this, void 0, void 0, function* () {
165
165
  this.logger.info(`Step run ${action.stepRunId} succeeded`);
166
166
  try {
167
167
  // Send the action event to the dispatcher
168
- const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_COMPLETED, result);
169
- this.client.dispatcher.sendStepActionEvent(event).catch((e) => {
170
- this.logger.error(`Could not send action event: ${e.message}`);
171
- });
168
+ const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_COMPLETED, result || null);
169
+ yield this.client.dispatcher.sendStepActionEvent(event);
172
170
  // delete the run from the futures
173
171
  delete this.futures[action.stepRunId];
174
172
  }
175
- catch (e) {
176
- this.logger.error(`Could not send action event: ${e.message}`);
173
+ catch (actionEventError) {
174
+ this.logger.error(`Could not send completed action event: ${actionEventError.message}`);
175
+ // send a failure event
176
+ const failureEvent = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_FAILED, actionEventError.message);
177
+ try {
178
+ yield this.client.dispatcher.sendStepActionEvent(failureEvent);
179
+ }
180
+ catch (failureEventError) {
181
+ this.logger.error(`Could not send failed action event: ${failureEventError.message}`);
182
+ }
183
+ this.logger.error(`Could not send action event: ${actionEventError.message}`);
177
184
  }
178
- };
179
- const failure = (error) => {
185
+ });
186
+ const failure = (error) => __awaiter(this, void 0, void 0, function* () {
180
187
  this.logger.error(`Step run ${action.stepRunId} failed: ${error.message}`);
181
188
  if (error.stack) {
182
189
  this.logger.error(error.stack);
@@ -187,17 +194,25 @@ class Worker {
187
194
  message: error === null || error === void 0 ? void 0 : error.message,
188
195
  stack: error === null || error === void 0 ? void 0 : error.stack,
189
196
  });
190
- this.client.dispatcher.sendStepActionEvent(event).catch((e) => {
191
- this.logger.error(`Could not send action event: ${e.message}`);
192
- });
197
+ yield this.client.dispatcher.sendStepActionEvent(event);
193
198
  // delete the run from the futures
194
199
  delete this.futures[action.stepRunId];
195
200
  }
196
201
  catch (e) {
197
202
  this.logger.error(`Could not send action event: ${e.message}`);
198
203
  }
199
- };
200
- const future = new hatchet_promise_1.default(run().then(success).catch(failure));
204
+ });
205
+ const future = new hatchet_promise_1.default((() => __awaiter(this, void 0, void 0, function* () {
206
+ let result;
207
+ try {
208
+ result = yield run();
209
+ }
210
+ catch (e) {
211
+ yield failure(e);
212
+ return;
213
+ }
214
+ yield success(result);
215
+ }))());
201
216
  this.futures[action.stepRunId] = future;
202
217
  // Send the action event to the dispatcher
203
218
  const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_STARTED);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "0.8.0-alpha.0",
3
+ "version": "0.8.0-alpha.2",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -51,7 +51,7 @@
51
51
  "worker:logger": "npm run exec -- ./examples/logger.ts",
52
52
  "api": "npm run exec -- ./examples/api.ts",
53
53
  "prepublish": "cp package.json dist/package.json;",
54
- "publish:ci": "rm -rf ./dist && npm run tsc:build && npm run prepublish && cd dist && npm publish --access public --no-git-checks",
54
+ "publish:ci": "rm -rf ./dist && npm run tsc:build && npm run prepublish && cd dist && npm publish --access public --no-git-checks --tag=alpha",
55
55
  "generate-docs": "typedoc"
56
56
  },
57
57
  "keywords": [],
package/step.d.ts CHANGED
@@ -84,6 +84,7 @@ export declare class Context<T, K> {
84
84
  userData(): K;
85
85
  stepName(): string;
86
86
  workflowRunId(): string;
87
+ retryCount(): number;
87
88
  playground(name: string, defaultValue?: string): string;
88
89
  log(message: string, level?: LogLevel): void;
89
90
  /**
package/step.js CHANGED
@@ -168,6 +168,9 @@ class Context {
168
168
  workflowRunId() {
169
169
  return this.action.workflowRunId;
170
170
  }
171
+ retryCount() {
172
+ return this.action.retryCount;
173
+ }
171
174
  playground(name, defaultValue = '') {
172
175
  if (name in this.overridesData) {
173
176
  return this.overridesData[name];