@hatchet-dev/typescript-sdk 0.1.8 → 0.1.10

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.
@@ -13,7 +13,6 @@ export declare class Worker {
13
13
  killing: boolean;
14
14
  handle_kill: boolean;
15
15
  action_registry: ActionRegistry;
16
- concurrency_action_registry: ActionRegistry;
17
16
  listener: ActionListener | undefined;
18
17
  futures: Record<Action['stepRunId'], HatchetPromise<any>>;
19
18
  contexts: Record<Action['stepRunId'], Context<any>>;
@@ -35,7 +35,6 @@ class Worker {
35
35
  this.client = client;
36
36
  this.name = options.name;
37
37
  this.action_registry = {};
38
- this.concurrency_action_registry = {};
39
38
  process.on('SIGTERM', () => this.exitGracefully());
40
39
  process.on('SIGINT', () => this.exitGracefully());
41
40
  this.killing = false;
@@ -46,9 +45,9 @@ class Worker {
46
45
  var _a, _b;
47
46
  return __awaiter(this, void 0, void 0, function* () {
48
47
  try {
49
- const concurrency = ((_a = workflow.concurrency) === null || _a === void 0 ? void 0 : _a.action)
48
+ const concurrency = ((_a = workflow.concurrency) === null || _a === void 0 ? void 0 : _a.name)
50
49
  ? {
51
- action: `${this.serviceName}:${workflow.concurrency.action}`,
50
+ action: `${this.serviceName}:${workflow.concurrency.name}`,
52
51
  maxRuns: workflow.concurrency.maxRuns || 1,
53
52
  limitStrategy: workflow.concurrency.limitStrategy || workflows_1.ConcurrencyLimitStrategy.CANCEL_IN_PROGRESS,
54
53
  }
@@ -87,11 +86,8 @@ class Worker {
87
86
  acc[`${this.serviceName}:${step.name}`] = step.run;
88
87
  return acc;
89
88
  }, {});
90
- this.concurrency_action_registry = ((_b = workflow.concurrency) === null || _b === void 0 ? void 0 : _b.action)
91
- ? {
92
- [`${this.serviceName}:${workflow.concurrency.action}`]: workflow.concurrency.key,
93
- }
94
- : {};
89
+ this.action_registry = ((_b = workflow.concurrency) === null || _b === void 0 ? void 0 : _b.name)
90
+ ? Object.assign(Object.assign({}, this.action_registry), { [`${this.serviceName}:${workflow.concurrency.name}`]: workflow.concurrency.key }) : Object.assign({}, this.action_registry);
95
91
  });
96
92
  }
97
93
  handleStartStepRun(action) {
@@ -148,6 +144,7 @@ class Worker {
148
144
  const context = new step_1.Context(action.actionPayload);
149
145
  const key = action.getGroupKeyRunId;
150
146
  this.contexts[key] = context;
147
+ this.logger.debug(`Starting group key run ${key}`);
151
148
  const step = this.action_registry[actionId];
152
149
  if (!step) {
153
150
  this.logger.error(`Could not find step '${actionId}'`);
@@ -218,17 +215,26 @@ class Worker {
218
215
  };
219
216
  }
220
217
  handleCancelStepRun(action) {
221
- const { stepRunId } = action;
222
- const future = this.futures[stepRunId];
223
- const context = this.contexts[stepRunId];
224
- // TODO send cancel signal to context
225
- // if (context && context.cancel) {
226
- // context.cancel();
227
- // delete this.contexts[stepRunId];
228
- // }
229
- if (future) {
230
- future.cancel();
231
- delete this.futures[stepRunId];
218
+ try {
219
+ this.logger.info(`Cancelling step run ${action.stepRunId}`);
220
+ const { stepRunId } = action;
221
+ const future = this.futures[stepRunId];
222
+ const context = this.contexts[stepRunId];
223
+ // TODO send cancel signal to context
224
+ if (context && context.controller) {
225
+ context.controller.abort('Cancelled by worker');
226
+ delete this.contexts[stepRunId];
227
+ }
228
+ if (future) {
229
+ future.promise.catch(() => {
230
+ this.logger.info(`Cancelled step run ${action.stepRunId}`);
231
+ });
232
+ future.cancel('Cancelled by worker');
233
+ delete this.futures[stepRunId];
234
+ }
235
+ }
236
+ catch (e) {
237
+ this.logger.error(`Could not cancel step run: ${e.message}`);
232
238
  }
233
239
  }
234
240
  stop() {
package/index.d.ts CHANGED
@@ -1,2 +1,5 @@
1
1
  import { HatchetClient as Hatchet } from './clients/hatchet-client';
2
+ export * from './workflow';
3
+ export * from './step';
4
+ export * from './clients/worker';
2
5
  export default Hatchet;
package/index.js CHANGED
@@ -1,4 +1,21 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
17
  const hatchet_client_1 = require("./clients/hatchet-client");
18
+ __exportStar(require("./workflow"), exports);
19
+ __exportStar(require("./step"), exports);
20
+ __exportStar(require("./clients/worker"), exports);
4
21
  exports.default = hatchet_client_1.HatchetClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/step.d.ts CHANGED
@@ -22,6 +22,7 @@ interface ContextData<T = unknown> {
22
22
  }
23
23
  export declare class Context<T = unknown> {
24
24
  data: ContextData<T>;
25
+ controller: AbortController;
25
26
  constructor(payload: string);
26
27
  stepOutput(step: string): string;
27
28
  triggeredByEvent(): boolean;
package/step.js CHANGED
@@ -37,6 +37,7 @@ exports.CreateStepSchema = z.object({
37
37
  });
38
38
  class Context {
39
39
  constructor(payload) {
40
+ this.controller = new AbortController();
40
41
  try {
41
42
  this.data = JSON.parse(JSON.parse(payload));
42
43
  }
package/workflow.d.ts CHANGED
@@ -17,15 +17,15 @@ declare const StepsSchema: z.ZodArray<z.ZodObject<{
17
17
  export type Steps = z.infer<typeof StepsSchema>;
18
18
  export declare const ConcurrencyLimitStrategy: typeof PbConcurrencyLimitStrategy;
19
19
  export declare const WorkflowConcurrency: z.ZodObject<{
20
- action: z.ZodOptional<z.ZodString>;
20
+ name: z.ZodString;
21
21
  maxRuns: z.ZodOptional<z.ZodNumber>;
22
22
  limitStrategy: z.ZodOptional<z.ZodNativeEnum<typeof PbConcurrencyLimitStrategy>>;
23
23
  }, "strip", z.ZodTypeAny, {
24
- action?: string | undefined;
24
+ name: string;
25
25
  maxRuns?: number | undefined;
26
26
  limitStrategy?: PbConcurrencyLimitStrategy | undefined;
27
27
  }, {
28
- action?: string | undefined;
28
+ name: string;
29
29
  maxRuns?: number | undefined;
30
30
  limitStrategy?: PbConcurrencyLimitStrategy | undefined;
31
31
  }>;
package/workflow.js CHANGED
@@ -39,7 +39,7 @@ const OnConfigSchema = z.union([CronConfigSchema, EventConfigSchema]);
39
39
  const StepsSchema = z.array(step_1.CreateStepSchema);
40
40
  exports.ConcurrencyLimitStrategy = workflows_1.ConcurrencyLimitStrategy;
41
41
  exports.WorkflowConcurrency = z.object({
42
- action: z.string().optional(),
42
+ name: z.string(),
43
43
  maxRuns: z.number().optional(),
44
44
  limitStrategy: z.nativeEnum(exports.ConcurrencyLimitStrategy).optional(),
45
45
  });