@hatchet-dev/typescript-sdk 1.0.0-alpha0 → 1.0.0-alpha1

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.
@@ -6,7 +6,7 @@ import { Workflow as V0Workflow } from '../../workflow';
6
6
  import { V0Worker, WorkerOpts } from '../worker';
7
7
  import { AxiosRequestConfig } from 'axios';
8
8
  import { Logger } from '../../util/logger';
9
- import { Workflow as V1Workflow } from '../../v1/workflow';
9
+ import { WorkflowDeclaration as V1Workflow } from '../../v1/workflow';
10
10
  import { ClientConfig } from './client-config';
11
11
  import { ListenerClient } from '../listener/listener-client';
12
12
  import { Api } from '../rest/generated/Api';
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HatchetLogger = exports.DEFAULT_LOGGER = void 0;
4
+ /* eslint-disable no-console */
4
5
  const logger_1 = require("../../util/logger");
5
6
  const DEFAULT_LOGGER = (context, logLevel) => new HatchetLogger(context, logLevel);
6
7
  exports.DEFAULT_LOGGER = DEFAULT_LOGGER;
@@ -19,8 +20,22 @@ class HatchetLogger {
19
20
  minute: '2-digit',
20
21
  second: '2-digit',
21
22
  });
23
+ // eslint-disable-next-line prefer-destructuring
24
+ let print = console.log;
25
+ if (level === 'ERROR') {
26
+ print = console.error;
27
+ }
28
+ if (level === 'WARN') {
29
+ print = console.warn;
30
+ }
31
+ if (level === 'INFO') {
32
+ print = console.info;
33
+ }
34
+ if (level === 'DEBUG') {
35
+ print = console.debug;
36
+ }
22
37
  // eslint-disable-next-line no-console
23
- console.log(`🪓 ${process.pid} | ${time} ${color && `\x1b[${color || ''}m`} [${level}/${this.context}] ${message}\x1b[0m`);
38
+ print(`🪓 ${process.pid} | ${time} ${color && `\x1b[${color || ''}m`} [${level}/${this.context}] ${message}\x1b[0m`);
24
39
  }
25
40
  }
26
41
  debug(message) {
@@ -187,8 +187,6 @@ class V0Worker {
187
187
  // Send the action event to the dispatcher
188
188
  const event = this.getStepActionEvent(action, dispatcher_1.StepActionEventType.STEP_EVENT_TYPE_COMPLETED, result || null);
189
189
  yield this.client.dispatcher.sendStepActionEvent(event);
190
- // delete the run from the futures
191
- delete this.futures[action.stepRunId];
192
190
  }
193
191
  catch (actionEventError) {
194
192
  this.logger.error(`Could not send completed action event: ${actionEventError.message || actionEventError}`);
@@ -202,6 +200,11 @@ class V0Worker {
202
200
  }
203
201
  this.logger.error(`Could not send action event: ${actionEventError.message || actionEventError}`);
204
202
  }
203
+ finally {
204
+ // delete the run from the futures
205
+ delete this.futures[action.stepRunId];
206
+ delete this.contexts[action.stepRunId];
207
+ }
205
208
  });
206
209
  const failure = (error) => __awaiter(this, void 0, void 0, function* () {
207
210
  this.logger.error(`Step run ${action.stepRunId} failed: ${error.message}`);
@@ -215,12 +218,15 @@ class V0Worker {
215
218
  stack: error === null || error === void 0 ? void 0 : error.stack,
216
219
  });
217
220
  yield this.client.dispatcher.sendStepActionEvent(event);
218
- // delete the run from the futures
219
- delete this.futures[action.stepRunId];
220
221
  }
221
222
  catch (e) {
222
223
  this.logger.error(`Could not send action event: ${e.message}`);
223
224
  }
225
+ finally {
226
+ // delete the run from the futures
227
+ delete this.futures[action.stepRunId];
228
+ delete this.contexts[action.stepRunId];
229
+ }
224
230
  });
225
231
  const future = new hatchet_promise_1.default((() => __awaiter(this, void 0, void 0, function* () {
226
232
  let result;
@@ -279,12 +285,15 @@ class V0Worker {
279
285
  this.client.dispatcher.sendGroupKeyActionEvent(event).catch((e) => {
280
286
  this.logger.error(`Could not send action event: ${e.message}`);
281
287
  });
282
- // delete the run from the futures
283
- delete this.futures[key];
284
288
  }
285
289
  catch (e) {
286
290
  this.logger.error(`Could not send action event: ${e.message}`);
287
291
  }
292
+ finally {
293
+ // delete the run from the futures
294
+ delete this.futures[key];
295
+ delete this.contexts[key];
296
+ }
288
297
  };
289
298
  const failure = (error) => {
290
299
  this.logger.error(`Step run ${key} failed: ${error.message}`);
@@ -294,12 +303,15 @@ class V0Worker {
294
303
  this.client.dispatcher.sendGroupKeyActionEvent(event).catch((e) => {
295
304
  this.logger.error(`Could not send action event: ${e.message}`);
296
305
  });
297
- // delete the run from the futures
298
- delete this.futures[key];
299
306
  }
300
307
  catch (e) {
301
308
  this.logger.error(`Could not send action event: ${e.message}`);
302
309
  }
310
+ finally {
311
+ // delete the run from the futures
312
+ delete this.futures[key];
313
+ delete this.contexts[key];
314
+ }
303
315
  };
304
316
  const future = new hatchet_promise_1.default(run().then(success).catch(failure));
305
317
  this.futures[key] = future;
@@ -344,14 +356,13 @@ class V0Worker {
344
356
  }
345
357
  handleCancelStepRun(action) {
346
358
  return __awaiter(this, void 0, void 0, function* () {
359
+ const { stepRunId } = action;
347
360
  try {
348
361
  this.logger.info(`Cancelling step run ${action.stepRunId}`);
349
- const { stepRunId } = action;
350
362
  const future = this.futures[stepRunId];
351
363
  const context = this.contexts[stepRunId];
352
364
  if (context && context.controller) {
353
365
  context.controller.abort('Cancelled by worker');
354
- delete this.contexts[stepRunId];
355
366
  }
356
367
  if (future) {
357
368
  future.promise.catch(() => {
@@ -359,12 +370,15 @@ class V0Worker {
359
370
  });
360
371
  future.cancel('Cancelled by worker');
361
372
  yield future.promise;
362
- delete this.futures[stepRunId];
363
373
  }
364
374
  }
365
375
  catch (e) {
366
376
  this.logger.error('Could not cancel step run: ', e);
367
377
  }
378
+ finally {
379
+ delete this.futures[stepRunId];
380
+ delete this.contexts[stepRunId];
381
+ }
368
382
  });
369
383
  }
370
384
  stop() {
package/index.d.ts CHANGED
@@ -7,5 +7,6 @@ export * from './clients/admin';
7
7
  export * from './util/workflow-run-ref';
8
8
  export * from './v1/client/client';
9
9
  export * from './v1/client/worker';
10
+ export * from './v1/workflow';
10
11
  export default Hatchet;
11
12
  export { Hatchet };
package/index.js CHANGED
@@ -25,4 +25,5 @@ __exportStar(require("./clients/admin"), exports);
25
25
  __exportStar(require("./util/workflow-run-ref"), exports);
26
26
  __exportStar(require("./v1/client/client"), exports);
27
27
  __exportStar(require("./v1/client/worker"), exports);
28
+ __exportStar(require("./v1/workflow"), exports);
28
29
  exports.default = client_1.HatchetClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "1.0.0-alpha0",
3
+ "version": "1.0.0-alpha1",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
package/step.d.ts CHANGED
@@ -9,7 +9,7 @@ import { V0Worker } from './clients/worker';
9
9
  import { WorkerLabels } from './clients/dispatcher/dispatcher-client';
10
10
  import { CreateStepRateLimit, RateLimitDuration, WorkerLabelComparator } from './protoc/workflows';
11
11
  import { CreateTaskOpts } from './v1/task';
12
- import { Workflow as WorkflowV1 } from './v1/workflow';
12
+ import { WorkflowDeclaration as WorkflowV1 } from './v1/workflow';
13
13
  export declare const CreateRateLimitSchema: z.ZodObject<{
14
14
  key: z.ZodOptional<z.ZodString>;
15
15
  staticKey: z.ZodOptional<z.ZodString>;
@@ -211,7 +211,7 @@ export declare class Context<T, K = {}> {
211
211
  * @param children an array of objects containing the workflow name, input data, and options for each workflow
212
212
  * @returns a list of workflow run references to the enqueued runs
213
213
  */
214
- bulkEnqueueChildren<Q extends Record<string, any> = any, P extends Record<string, any> = any>(children: Array<{
214
+ bulkEnqueueChildren<Q extends JsonObject = any, P extends JsonObject = any>(children: Array<{
215
215
  workflow: string | Workflow | WorkflowV1<Q, P>;
216
216
  input: Q;
217
217
  options?: {
@@ -225,7 +225,7 @@ export declare class Context<T, K = {}> {
225
225
  * @param children an array of objects containing the workflow name, input data, and options for each workflow
226
226
  * @returns a list of results from the children workflows
227
227
  */
228
- bulkRunChildren<Q extends Record<string, any> = any, P extends Record<string, any> = any>(children: Array<{
228
+ bulkRunChildren<Q extends JsonObject = any, P extends JsonObject = any>(children: Array<{
229
229
  workflow: string | Workflow | WorkflowV1<Q, P>;
230
230
  input: Q;
231
231
  options?: {
@@ -241,7 +241,7 @@ export declare class Context<T, K = {}> {
241
241
  * @returns a list of references to the spawned workflow runs
242
242
  * @deprecated use bulkEnqueueChildren or bulkRunChildren instead
243
243
  */
244
- spawnWorkflows<Q extends Record<string, any> = any, P extends Record<string, any> = any>(workflows: Array<{
244
+ spawnWorkflows<Q extends JsonObject = any, P extends JsonObject = any>(workflows: Array<{
245
245
  workflow: string | Workflow | WorkflowV1<Q, P>;
246
246
  input: Q;
247
247
  options?: {
@@ -260,7 +260,7 @@ export declare class Context<T, K = {}> {
260
260
  * @param <P> the type of the output data
261
261
  * @return the result of the workflow
262
262
  */
263
- runChild<Q extends Record<string, any>, P extends Record<string, any>>(workflow: string | Workflow | WorkflowV1<Q, P>, input: Q, options?: string | {
263
+ runChild<Q extends JsonObject, P extends JsonObject>(workflow: string | Workflow | WorkflowV1<Q, P>, input: Q, options?: string | {
264
264
  key?: string;
265
265
  sticky?: boolean;
266
266
  additionalMetadata?: Record<string, string>;
@@ -278,7 +278,7 @@ export declare class Context<T, K = {}> {
278
278
  * @param <P> the type of the output data
279
279
  * @return a reference to the spawned workflow run
280
280
  */
281
- enqueueChild<Q extends Record<string, any>, P extends Record<string, any>>(workflow: string | Workflow | WorkflowV1<Q, P>, input: Q, options?: string | {
281
+ enqueueChild<Q extends JsonObject, P extends JsonObject>(workflow: string | Workflow | WorkflowV1<Q, P>, input: Q, options?: string | {
282
282
  key?: string;
283
283
  sticky?: boolean;
284
284
  additionalMetadata?: Record<string, string>;
@@ -297,7 +297,7 @@ export declare class Context<T, K = {}> {
297
297
  * @return a reference to the spawned workflow run
298
298
  * @deprecated use runChild or enqueueChild instead
299
299
  */
300
- spawnWorkflow<Q extends Record<string, any>, P extends Record<string, any>>(workflow: string | Workflow | WorkflowV1<Q, P>, input: Q, options?: string | {
300
+ spawnWorkflow<Q extends JsonObject, P extends JsonObject>(workflow: string | Workflow | WorkflowV1<Q, P>, input: Q, options?: string | {
301
301
  key?: string;
302
302
  sticky?: boolean;
303
303
  additionalMetadata?: Record<string, string>;
@@ -2,7 +2,8 @@ import { ClientConfig, InternalHatchetClient, HatchetClientOptions } from '../..
2
2
  import { AxiosRequestConfig } from 'axios';
3
3
  import WorkflowRunRef from '../../util/workflow-run-ref';
4
4
  import { Workflow as V0Workflow } from '../../workflow';
5
- import { CreateWorkflowOpts, RunOpts, Workflow } from '../workflow';
5
+ import { JsonObject } from '../../step';
6
+ import { CreateWorkflowOpts, RunOpts, WorkflowDeclaration } from '../workflow';
6
7
  import { IHatchetClient } from './client.interface';
7
8
  import { CreateWorkerOpts, Worker } from './worker';
8
9
  /**
@@ -37,7 +38,7 @@ export declare class HatchetClient implements IHatchetClient {
37
38
  * @returns A new Workflow instance
38
39
  * @note It is possible to create an orphaned workflow if no client is available using @hatchet/client CreateWorkflow
39
40
  */
40
- workflow<T extends Record<string, any> = any, K = any>(options: CreateWorkflowOpts): Workflow<T, K>;
41
+ workflow<T extends JsonObject = any, K extends JsonObject = any>(options: CreateWorkflowOpts): WorkflowDeclaration<T, K>;
41
42
  /**
42
43
  * Triggers a workflow run without waiting for completion.
43
44
  * @template T - The input type for the workflow
@@ -47,7 +48,7 @@ export declare class HatchetClient implements IHatchetClient {
47
48
  * @param options - Configuration options for the workflow run
48
49
  * @returns A WorkflowRunRef containing the run ID and methods to interact with the run
49
50
  */
50
- enqueue<T extends Record<string, any> = any, K = any>(workflow: Workflow<T, K> | string | V0Workflow, input: T, options: RunOpts): WorkflowRunRef<K>;
51
+ enqueue<T extends JsonObject = any, K extends JsonObject = any>(workflow: WorkflowDeclaration<T, K> | string | V0Workflow, input: T, options: RunOpts): WorkflowRunRef<K>;
51
52
  /**
52
53
  * Triggers a workflow run and waits for the result.
53
54
  * @template T - The input type for the workflow
@@ -57,7 +58,7 @@ export declare class HatchetClient implements IHatchetClient {
57
58
  * @param options - Configuration options for the workflow run
58
59
  * @returns A promise that resolves with the workflow result
59
60
  */
60
- run<T extends Record<string, any> = any, K = any>(workflow: Workflow<T, K> | string | V0Workflow, input: T, options?: RunOpts): Promise<K>;
61
+ run<T extends JsonObject = any, K extends JsonObject = any>(workflow: WorkflowDeclaration<T, K> | string | V0Workflow, input: T, options?: RunOpts): Promise<K>;
61
62
  get cron(): import("../../clients/hatchet-client/features/cron-client").CronClient;
62
63
  get schedule(): import("../../clients/hatchet-client/features/schedule-client").ScheduleClient;
63
64
  get event(): import("../../clients/event/event-client").EventClient;
@@ -77,5 +78,5 @@ export declare class HatchetClient implements IHatchetClient {
77
78
  * @param workflows - The workflows to register on the webhooks
78
79
  * @returns A promise that resolves when the webhook is registered
79
80
  */
80
- webhooks(workflows: Workflow<any, any>[] | V0Workflow[]): import("../../clients/worker/handler").WebhookHandler;
81
+ webhooks(workflows: WorkflowDeclaration<any, any>[] | V0Workflow[]): import("../../clients/worker/handler").WebhookHandler;
81
82
  }
@@ -3,7 +3,7 @@ import { InternalHatchetClient } from '../../clients/hatchet-client';
3
3
  import { V0Worker } from '../../clients/worker';
4
4
  import { Workflow as V0Workflow } from '../../workflow';
5
5
  import { WebhookWorkerCreateRequest } from '../../clients/rest/generated/data-contracts';
6
- import { Workflow } from '../workflow';
6
+ import { WorkflowDeclaration } from '../workflow';
7
7
  /**
8
8
  * Options for creating a new hatchet worker
9
9
  * @interface CreateWorkerOpts
@@ -12,7 +12,7 @@ export interface CreateWorkerOpts {
12
12
  /** Maximum number of concurrent runs on this worker */
13
13
  slots?: number;
14
14
  /** Array of workflows to register */
15
- workflows?: Workflow<any, any>[] | V0Workflow[];
15
+ workflows?: WorkflowDeclaration<any, any>[] | V0Workflow[];
16
16
  /** Worker labels for affinity-based assignment */
17
17
  labels?: WorkerLabels;
18
18
  /** Whether to handle kill signals */
@@ -43,14 +43,14 @@ export declare class Worker {
43
43
  * @param workflows - Array of workflows to register
44
44
  * @returns Array of registered workflow promises
45
45
  */
46
- registerWorkflows(workflows?: Array<Workflow<any, any> | V0Workflow>): Promise<void>[] | undefined;
46
+ registerWorkflows(workflows?: Array<WorkflowDeclaration<any, any> | V0Workflow>): Promise<void[]>;
47
47
  /**
48
48
  * Registers a single workflow with the worker
49
49
  * @param workflow - The workflow to register
50
50
  * @returns A promise that resolves when the workflow is registered
51
51
  * @deprecated use registerWorkflows instead
52
52
  */
53
- registerWorkflow(workflow: Workflow<any, any> | V0Workflow): Promise<void>[] | undefined;
53
+ registerWorkflow(workflow: WorkflowDeclaration<any, any> | V0Workflow): Promise<void[]>;
54
54
  /**
55
55
  * Starts the worker
56
56
  * @returns Promise that resolves when the worker is stopped or killed
@@ -79,4 +79,4 @@ export declare class Worker {
79
79
  */
80
80
  registerWebhook(webhook: WebhookWorkerCreateRequest): Promise<import("axios").AxiosResponse<import("../../clients/rest/generated/data-contracts").WebhookWorkerCreated, any>>;
81
81
  }
82
- export declare function toV0Workflow(wf: Workflow<any, any> | V0Workflow): V0Workflow;
82
+ export declare function toV0Workflow(wf: WorkflowDeclaration<any, any> | V0Workflow): V0Workflow;
@@ -43,8 +43,10 @@ class Worker {
43
43
  * @returns Array of registered workflow promises
44
44
  */
45
45
  registerWorkflows(workflows) {
46
- return workflows === null || workflows === void 0 ? void 0 : workflows.map((wf) => {
47
- return this.v0.registerWorkflow(toV0Workflow(wf));
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ return Promise.all((workflows === null || workflows === void 0 ? void 0 : workflows.map((wf) => {
48
+ return this.v0.registerWorkflow(toV0Workflow(wf));
49
+ })) || []);
48
50
  });
49
51
  }
50
52
  /**
@@ -96,7 +98,7 @@ class Worker {
96
98
  }
97
99
  exports.Worker = Worker;
98
100
  function toV0Workflow(wf) {
99
- if (wf instanceof workflow_1.Workflow) {
101
+ if (wf instanceof workflow_1.WorkflowDeclaration) {
100
102
  const { definition } = wf;
101
103
  return {
102
104
  id: definition.name,
@@ -106,6 +108,10 @@ function toV0Workflow(wf) {
106
108
  scheduleTimeout: definition.scheduleTimeout,
107
109
  on: definition.on,
108
110
  concurrency: definition.concurrency,
111
+ onFailure: definition.onFailure && {
112
+ name: 'on-failure',
113
+ run: (ctx) => definition.onFailure(ctx),
114
+ },
109
115
  steps: definition.tasks.map((task) => {
110
116
  var _a;
111
117
  return ({
@@ -6,7 +6,7 @@ type ChildOutput = {
6
6
  Value: number;
7
7
  };
8
8
  };
9
- export declare const child: import("../../workflow").Workflow<ChildInput, ChildOutput>;
9
+ export declare const child: import("../../workflow").WorkflowDeclaration<ChildInput, ChildOutput>;
10
10
  type ParentInput = {
11
11
  N: number;
12
12
  };
@@ -15,5 +15,5 @@ type ParentOutput = {
15
15
  Result: number;
16
16
  };
17
17
  };
18
- export declare const parent: import("../../workflow").Workflow<ParentInput, ParentOutput>;
18
+ export declare const parent: import("../../workflow").WorkflowDeclaration<ParentInput, ParentOutput>;
19
19
  export {};
@@ -7,5 +7,5 @@ type SimpleOutput = {
7
7
  TransformedMessage: string;
8
8
  };
9
9
  };
10
- export declare const simpleConcurrency: import("../../workflow").Workflow<SimpleInput, SimpleOutput>;
10
+ export declare const simpleConcurrency: import("../../workflow").WorkflowDeclaration<SimpleInput, SimpleOutput>;
11
11
  export {};
@@ -7,5 +7,5 @@ type DagOutput = {
7
7
  Transformed: string;
8
8
  };
9
9
  };
10
- export declare const dag: import("../../workflow").Workflow<DagInput, DagOutput>;
10
+ export declare const dag: import("../../workflow").WorkflowDeclaration<DagInput, DagOutput>;
11
11
  export {};
@@ -7,12 +7,12 @@ type Output = {
7
7
  Sum: number;
8
8
  };
9
9
  };
10
- export declare const child1: import("../../workflow").Workflow<SimpleInput, Output>;
11
- export declare const child2: import("../../workflow").Workflow<SimpleInput, Output>;
12
- export declare const child3: import("../../workflow").Workflow<SimpleInput, Output>;
13
- export declare const child4: import("../../workflow").Workflow<SimpleInput, Output>;
14
- export declare const child5: import("../../workflow").Workflow<SimpleInput, Output>;
15
- export declare const parent: import("../../workflow").Workflow<SimpleInput, {
10
+ export declare const child1: import("../../workflow").WorkflowDeclaration<SimpleInput, Output>;
11
+ export declare const child2: import("../../workflow").WorkflowDeclaration<SimpleInput, Output>;
12
+ export declare const child3: import("../../workflow").WorkflowDeclaration<SimpleInput, Output>;
13
+ export declare const child4: import("../../workflow").WorkflowDeclaration<SimpleInput, Output>;
14
+ export declare const child5: import("../../workflow").WorkflowDeclaration<SimpleInput, Output>;
15
+ export declare const parent: import("../../workflow").WorkflowDeclaration<SimpleInput, {
16
16
  parent: Output["transformer"];
17
17
  }>;
18
18
  export {};
@@ -7,11 +7,11 @@ type LowerOutput = {
7
7
  TransformedMessage: string;
8
8
  };
9
9
  };
10
- export declare const lower: import("../../workflow").Workflow<Input, LowerOutput>;
10
+ export declare const lower: import("../../workflow").WorkflowDeclaration<Input, LowerOutput>;
11
11
  type UpperOutput = {
12
12
  upper: {
13
13
  TransformedMessage: string;
14
14
  };
15
15
  };
16
- export declare const upper: import("../../workflow").Workflow<Input, UpperOutput>;
16
+ export declare const upper: import("../../workflow").WorkflowDeclaration<Input, UpperOutput>;
17
17
  export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
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.alwaysFail.run({});
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
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
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 client_1 = require("../client");
13
+ const workflow_1 = require("./workflow");
14
+ function main() {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const worker = yield client_1.hatchet.worker('always-fail-worker', {
17
+ workflows: [workflow_1.alwaysFail],
18
+ });
19
+ yield worker.start();
20
+ });
21
+ }
22
+ if (require.main === module) {
23
+ main();
24
+ }
@@ -0,0 +1 @@
1
+ export declare const alwaysFail: import("../../workflow").WorkflowDeclaration<any, any>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.alwaysFail = void 0;
4
+ /* eslint-disable no-console */
5
+ const client_1 = require("../client");
6
+ exports.alwaysFail = client_1.hatchet.workflow({
7
+ name: 'always-fail',
8
+ onFailure: (ctx) => {
9
+ console.log('onFailure for run:', ctx.workflowRunId());
10
+ return {
11
+ 'on-failure': 'success',
12
+ };
13
+ },
14
+ });
15
+ exports.alwaysFail.task({
16
+ name: 'always-fail',
17
+ fn: () => {
18
+ throw new Error('intentional failure');
19
+ },
20
+ });
@@ -1,5 +1,5 @@
1
1
  type SimpleInput = {
2
2
  Message: string;
3
3
  };
4
- export declare const simple: import("../../workflow").Workflow<SimpleInput, any>;
4
+ export declare const simple: import("../../workflow").WorkflowDeclaration<SimpleInput, any>;
5
5
  export {};
package/v1/workflow.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import WorkflowRunRef from '../util/workflow-run-ref';
2
- import { Context } from '../step';
2
+ import { Context, JsonObject } from '../step';
3
3
  import { CronWorkflows, ScheduledWorkflows } from '../clients/rest/generated/data-contracts';
4
4
  import { Workflow as WorkflowV0 } from '../workflow';
5
5
  import { IHatchetClient } from './client/client.interface';
@@ -30,26 +30,32 @@ export type CreateWorkflowOpts = {
30
30
  */
31
31
  name: WorkflowV0['id'];
32
32
  /**
33
- * Optional description of the workflow.
33
+ * (optional) description of the workflow.
34
34
  */
35
35
  description?: WorkflowV0['description'];
36
36
  /**
37
- * Optional version of the workflow.
37
+ * (optional) version of the workflow.
38
38
  */
39
39
  version?: WorkflowV0['version'];
40
40
  /**
41
- * Optional sticky strategy for the workflow.
41
+ * (optional) sticky strategy for the workflow.
42
42
  */
43
43
  sticky?: WorkflowV0['sticky'];
44
44
  /**
45
- * Optional schedule timeout for the workflow.
45
+ * (optional) schedule timeout for the workflow.
46
46
  */
47
47
  scheduleTimeout?: WorkflowV0['scheduleTimeout'];
48
48
  /**
49
- * Optional on config for the workflow.
49
+ * (optional) on config for the workflow.
50
50
  */
51
51
  on?: WorkflowV0['on'];
52
52
  concurrency?: WorkflowV0['concurrency'];
53
+ /**
54
+ * (optional) onFailure handler for the workflow.
55
+ * Invoked when any task in the workflow fails.
56
+ * @param ctx The context of the workflow.
57
+ */
58
+ onFailure?: (ctx: Context<any>) => void;
53
59
  };
54
60
  /**
55
61
  * Internal definition of a workflow and its tasks.
@@ -65,7 +71,7 @@ type WorkflowDefinition = CreateWorkflowOpts & {
65
71
  * @template T The input type for the workflow.
66
72
  * @template K The return type of the workflow.
67
73
  */
68
- export declare class Workflow<T extends Record<string, any>, K> {
74
+ export declare class WorkflowDeclaration<T extends JsonObject, K extends JsonObject> {
69
75
  /**
70
76
  * The Hatchet client instance used to execute the workflow.
71
77
  */
@@ -148,5 +154,5 @@ export declare class Workflow<T extends Record<string, any>, K> {
148
154
  * @param client Optional Hatchet client instance.
149
155
  * @returns A new Workflow instance.
150
156
  */
151
- export declare function CreateWorkflow<T extends Record<string, any> = any, K = any>(options: CreateWorkflowOpts, client?: IHatchetClient): Workflow<T, K>;
157
+ export declare function CreateWorkflow<T extends JsonObject = any, K extends JsonObject = any>(options: CreateWorkflowOpts, client?: IHatchetClient): WorkflowDeclaration<T, K>;
152
158
  export {};
package/v1/workflow.js CHANGED
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Workflow = void 0;
12
+ exports.WorkflowDeclaration = void 0;
13
13
  exports.CreateWorkflow = CreateWorkflow;
14
14
  const UNBOUND_ERR = new Error('workflow unbound to hatchet client, hint: use client.run instead');
15
15
  /**
@@ -17,7 +17,7 @@ const UNBOUND_ERR = new Error('workflow unbound to hatchet client, hint: use cli
17
17
  * @template T The input type for the workflow.
18
18
  * @template K The return type of the workflow.
19
19
  */
20
- class Workflow {
20
+ class WorkflowDeclaration {
21
21
  /**
22
22
  * Creates a new workflow instance.
23
23
  * @param options The options for creating the workflow.
@@ -131,7 +131,7 @@ class Workflow {
131
131
  return this.definition.name;
132
132
  }
133
133
  }
134
- exports.Workflow = Workflow;
134
+ exports.WorkflowDeclaration = WorkflowDeclaration;
135
135
  /**
136
136
  * Creates a new workflow instance.
137
137
  * @template T The input type for the workflow.
@@ -141,5 +141,5 @@ exports.Workflow = Workflow;
141
141
  * @returns A new Workflow instance.
142
142
  */
143
143
  function CreateWorkflow(options, client) {
144
- return new Workflow(options, client);
144
+ return new WorkflowDeclaration(options, client);
145
145
  }
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const HATCHET_VERSION = "1.0.0-alpha0";
1
+ export declare const HATCHET_VERSION = "1.0.0-alpha1";
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.0.0-alpha0';
4
+ exports.HATCHET_VERSION = '1.0.0-alpha1';