@hatchet-dev/typescript-sdk 1.1.1 → 1.1.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.
@@ -51,7 +51,7 @@ export declare class V0Worker {
51
51
  registerAction<T, K>(actionId: string, action: StepRunFunction<T, K>): void;
52
52
  handleStartStepRun(action: Action): Promise<void>;
53
53
  handleStartGroupKeyRun(action: Action): Promise<void>;
54
- getStepActionEvent(action: Action, eventType: StepActionEventType, shouldNotRetry: boolean, payload?: any): StepActionEvent;
54
+ getStepActionEvent(action: Action, eventType: StepActionEventType, shouldNotRetry: boolean, payload?: any, retryCount?: number): StepActionEvent;
55
55
  getGroupKeyActionEvent(action: Action, eventType: GroupKeyActionEventType, payload?: any): GroupKeyActionEvent;
56
56
  handleCancelStepRun(action: Action): Promise<void>;
57
57
  stop(): Promise<void>;
@@ -346,13 +346,13 @@ class V0Worker {
346
346
  this.logger.info(`Step run ${action.stepRunId} succeeded`);
347
347
  try {
348
348
  // Send the action event to the dispatcher
349
- const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_COMPLETED, false, result || null);
349
+ const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_COMPLETED, false, result || null, action.retryCount);
350
350
  yield this.client.dispatcher.sendStepActionEvent(event);
351
351
  }
352
352
  catch (actionEventError) {
353
353
  this.logger.error(`Could not send completed action event: ${actionEventError.message || actionEventError}`);
354
354
  // send a failure event
355
- const failureEvent = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_FAILED, false, actionEventError.message);
355
+ const failureEvent = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_FAILED, false, actionEventError.message, action.retryCount);
356
356
  try {
357
357
  yield this.client.dispatcher.sendStepActionEvent(failureEvent);
358
358
  }
@@ -378,7 +378,7 @@ class V0Worker {
378
378
  const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_FAILED, shouldNotRetry, {
379
379
  message: error === null || error === void 0 ? void 0 : error.message,
380
380
  stack: error === null || error === void 0 ? void 0 : error.stack,
381
- });
381
+ }, action.retryCount);
382
382
  yield this.client.dispatcher.sendStepActionEvent(event);
383
383
  }
384
384
  catch (e) {
@@ -403,7 +403,7 @@ class V0Worker {
403
403
  }))());
404
404
  this.futures[action.stepRunId] = future;
405
405
  // Send the action event to the dispatcher
406
- const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_STARTED, false);
406
+ const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_STARTED, false, undefined, action.retryCount);
407
407
  this.client.dispatcher.sendStepActionEvent(event).catch((e) => {
408
408
  this.logger.error(`Could not send action event: ${e.message}`);
409
409
  });
@@ -489,7 +489,7 @@ class V0Worker {
489
489
  }
490
490
  });
491
491
  }
492
- getStepActionEvent(action, eventType, shouldNotRetry, payload = '') {
492
+ getStepActionEvent(action, eventType, shouldNotRetry, payload = '', retryCount = 0) {
493
493
  return {
494
494
  workerId: this.name,
495
495
  jobId: action.jobId,
@@ -501,6 +501,7 @@ class V0Worker {
501
501
  eventType,
502
502
  eventPayload: JSON.stringify(payload),
503
503
  shouldNotRetry,
504
+ retryCount,
504
505
  };
505
506
  }
506
507
  getGroupKeyActionEvent(action, eventType, payload = '') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -13,6 +13,7 @@ import { WorkflowsClient } from './features/workflows';
13
13
  import { RunsClient } from './features/runs';
14
14
  import { CreateStandaloneDurableTaskOpts } from '../task';
15
15
  import { InputType, OutputType, UnknownInputType, StrictWorkflowOutputType } from '../types';
16
+ import { RatelimitsClient } from './features';
16
17
  /**
17
18
  * HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
18
19
  * It provides methods for creating and executing workflows, as well as managing workers.
@@ -159,6 +160,12 @@ export declare class HatchetClient implements IHatchetClient {
159
160
  * @returns A metrics client instance
160
161
  */
161
162
  get metrics(): MetricsClient;
163
+ private _ratelimits;
164
+ /**
165
+ * Get the rate limits client for creating and managing rate limits
166
+ * @returns A rate limits client instance
167
+ */
168
+ get ratelimits(): RatelimitsClient;
162
169
  private _runs;
163
170
  /**
164
171
  * Get the runs client for creating and managing runs
@@ -27,6 +27,7 @@ const metrics_1 = require("./features/metrics");
27
27
  const workers_1 = require("./features/workers");
28
28
  const workflows_1 = require("./features/workflows");
29
29
  const runs_1 = require("./features/runs");
30
+ const features_1 = require("./features");
30
31
  /**
31
32
  * HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
32
33
  * It provides methods for creating and executing workflows, as well as managing workers.
@@ -210,6 +211,16 @@ class HatchetClient {
210
211
  }
211
212
  return this._metrics;
212
213
  }
214
+ /**
215
+ * Get the rate limits client for creating and managing rate limits
216
+ * @returns A rate limits client instance
217
+ */
218
+ get ratelimits() {
219
+ if (!this._ratelimits) {
220
+ this._ratelimits = new features_1.RatelimitsClient(this);
221
+ }
222
+ return this._ratelimits;
223
+ }
213
224
  /**
214
225
  * Get the runs client for creating and managing runs
215
226
  * @returns A runs client instance
@@ -10,10 +10,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const hatchet_client_1 = require("../hatchet-client");
13
- const workflow_1 = require("./workflow");
14
13
  function main() {
15
14
  return __awaiter(this, void 0, void 0, function* () {
16
- const res = yield hatchet_client_1.hatchet.events.push(workflow_1.SIMPLE_EVENT, {
15
+ // Pushing an Event
16
+ const res = yield hatchet_client_1.hatchet.events.push('simple-event:create', {
17
17
  Message: 'hello',
18
18
  });
19
19
  // !!
@@ -6,10 +6,8 @@ exports.SIMPLE_EVENT = 'simple-event:create';
6
6
  // ❓ Run workflow on event
7
7
  exports.lower = hatchet_client_1.hatchet.workflow({
8
8
  name: 'lower',
9
- on: {
10
- // 👀 Declare the event that will trigger the workflow
11
- event: exports.SIMPLE_EVENT,
12
- },
9
+ // 👀 Declare the event that will trigger the workflow
10
+ onEvents: ['simple-event:create'],
13
11
  });
14
12
  // !!
15
13
  exports.lower.task({
@@ -1,5 +1 @@
1
- type RateLimitInput = {
2
- userId: string;
3
- };
4
- export declare const rateLimitWorkflow: import("../..").WorkflowDeclaration<RateLimitInput, {}>;
5
1
  export {};
@@ -1,29 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rateLimitWorkflow = void 0;
4
3
  const workflows_1 = require("../../../protoc/v1/workflows");
5
4
  const hatchet_client_1 = require("../hatchet-client");
6
- exports.rateLimitWorkflow = hatchet_client_1.hatchet.workflow({
7
- name: 'RateLimitWorkflow',
5
+ // Upsert Rate Limit
6
+ hatchet_client_1.hatchet.ratelimits.upsert({
7
+ key: 'api-service-rate-limit',
8
+ limit: 10,
9
+ duration: workflows_1.RateLimitDuration.SECOND,
8
10
  });
9
11
  // !!
10
12
  // ❓ Static
11
- const RATE_LIMIT_KEY = 'test-limit';
12
- const task1 = exports.rateLimitWorkflow.task({
13
+ const RATE_LIMIT_KEY = 'api-service-rate-limit';
14
+ const task1 = hatchet_client_1.hatchet.task({
13
15
  name: 'task1',
14
- fn: (input) => {
15
- console.log('executed task1');
16
- },
17
16
  rateLimits: [
18
17
  {
19
18
  staticKey: RATE_LIMIT_KEY,
20
19
  units: 1,
21
20
  },
22
21
  ],
22
+ fn: (input) => {
23
+ console.log('executed task1');
24
+ },
23
25
  });
24
26
  // !!
25
27
  // ❓ Dynamic
26
- const task2 = exports.rateLimitWorkflow.task({
28
+ const task2 = hatchet_client_1.hatchet.task({
27
29
  name: 'task2',
28
30
  fn: (input) => {
29
31
  console.log('executed task2 for user: ', input.userId);
@@ -22,7 +22,16 @@ function main() {
22
22
  // !!
23
23
  // eslint-disable-next-line no-console
24
24
  console.log(cron.metadata.id);
25
- yield hatchet_client_1.hatchet.crons.delete(cron);
25
+ // ❓ Delete
26
+ yield hatchet_client_1.hatchet.crons.delete(cronId);
27
+ // !!
28
+ // ❓ List
29
+ const crons = yield hatchet_client_1.hatchet.crons.list({
30
+ workflowId: workflow_1.simple.id,
31
+ });
32
+ // !!
33
+ // eslint-disable-next-line no-console
34
+ console.log(crons);
26
35
  });
27
36
  }
28
37
  if (require.main === module) {
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const HATCHET_VERSION = "1.1.1";
1
+ export declare const HATCHET_VERSION = "1.1.2";
package/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HATCHET_VERSION = void 0;
4
- exports.HATCHET_VERSION = '1.1.1';
4
+ exports.HATCHET_VERSION = '1.1.2';
@@ -1 +0,0 @@
1
- export {};
@@ -1,29 +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
- /* eslint-disable no-console */
13
- const workflow_1 = require("./workflow");
14
- function main() {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- try {
17
- const res = yield workflow_1.rateLimitWorkflow.run({ userId: 'abc' });
18
- console.log(res);
19
- }
20
- catch (e) {
21
- console.log('error', e);
22
- }
23
- });
24
- }
25
- if (require.main === module) {
26
- main()
27
- .catch(console.error)
28
- .finally(() => process.exit(0));
29
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,24 +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 hatchet_client_1 = require("../hatchet-client");
13
- const workflow_1 = require("./workflow");
14
- function main() {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- const worker = yield hatchet_client_1.hatchet.worker('rate-limit-worker', {
17
- workflows: [workflow_1.rateLimitWorkflow],
18
- });
19
- yield worker.start();
20
- });
21
- }
22
- if (require.main === module) {
23
- main();
24
- }