@hatchet-dev/typescript-sdk 0.12.5 → 0.13.1

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.
@@ -106,8 +106,7 @@ export interface PaginationResponse {
106
106
  export interface APIResourceMeta {
107
107
  /**
108
108
  * the id of this resource, in UUID format
109
- * @format uuid
110
- * @minLength 36
109
+ * @minLength 0
111
110
  * @maxLength 36
112
111
  * @example "bb214807-246e-43a5-a25d-41761d1cff9e"
113
112
  */
@@ -383,6 +382,14 @@ export interface CreateEventRequest {
383
382
  /** Additional metadata for the event. */
384
383
  additionalMetadata?: object;
385
384
  }
385
+ export interface BulkCreateEventRequest {
386
+ events: CreateEventRequest[];
387
+ }
388
+ export interface BulkCreateEventResponse {
389
+ metadata: APIResourceMeta;
390
+ /** The events. */
391
+ events: Event[];
392
+ }
386
393
  export interface EventWorkflowRunSummary {
387
394
  /**
388
395
  * The number of pending runs.
@@ -433,6 +440,9 @@ export interface EventList {
433
440
  export interface ReplayEventRequest {
434
441
  eventIds: string[];
435
442
  }
443
+ export interface CancelEventRequest {
444
+ eventIds: string[];
445
+ }
436
446
  export interface Workflow {
437
447
  metadata: APIResourceMeta;
438
448
  /** The name of the workflow. */
@@ -442,7 +452,6 @@ export interface Workflow {
442
452
  versions?: WorkflowVersionMeta[];
443
453
  /** The tags of the workflow. */
444
454
  tags?: WorkflowTag[];
445
- lastRun?: WorkflowRun;
446
455
  /** The jobs of the workflow. */
447
456
  jobs?: Job[];
448
457
  }
@@ -473,6 +482,13 @@ export interface WorkflowVersion {
473
482
  /** @format int32 */
474
483
  order: number;
475
484
  workflowId: string;
485
+ /** The sticky strategy of the workflow. */
486
+ sticky?: string;
487
+ /**
488
+ * The default priority of the workflow.
489
+ * @format int32
490
+ */
491
+ defaultPriority?: number;
476
492
  workflow?: Workflow;
477
493
  concurrency?: WorkflowConcurrency;
478
494
  triggers?: WorkflowTriggers;
@@ -532,6 +548,11 @@ export interface Step {
532
548
  children?: string[];
533
549
  parents?: string[];
534
550
  }
551
+ export interface WorkflowWorkersCount {
552
+ freeSlotCount?: number;
553
+ maxSlotCount?: number;
554
+ workflowRunId?: string;
555
+ }
535
556
  export interface WorkflowRun {
536
557
  metadata: APIResourceMeta;
537
558
  tenantId: string;
@@ -547,6 +568,42 @@ export interface WorkflowRun {
547
568
  startedAt?: string;
548
569
  /** @format date-time */
549
570
  finishedAt?: string;
571
+ /** @example 1000 */
572
+ duration?: number;
573
+ /**
574
+ * @format uuid
575
+ * @minLength 36
576
+ * @maxLength 36
577
+ * @example "bb214807-246e-43a5-a25d-41761d1cff9e"
578
+ */
579
+ parentId?: string;
580
+ /**
581
+ * @format uuid
582
+ * @minLength 36
583
+ * @maxLength 36
584
+ * @example "bb214807-246e-43a5-a25d-41761d1cff9e"
585
+ */
586
+ parentStepRunId?: string;
587
+ additionalMetadata?: Record<string, any>;
588
+ }
589
+ export interface WorkflowRunShape {
590
+ metadata: APIResourceMeta;
591
+ tenantId: string;
592
+ workflowId?: string;
593
+ workflowVersionId: string;
594
+ workflowVersion?: WorkflowVersion;
595
+ status: WorkflowRunStatus;
596
+ displayName?: string;
597
+ jobRuns?: JobRun[];
598
+ triggeredBy: WorkflowRunTriggeredBy;
599
+ input?: Record<string, any>;
600
+ error?: string;
601
+ /** @format date-time */
602
+ startedAt?: string;
603
+ /** @format date-time */
604
+ finishedAt?: string;
605
+ /** @example 1000 */
606
+ duration?: number;
550
607
  /**
551
608
  * @format uuid
552
609
  * @minLength 36
@@ -563,10 +620,27 @@ export interface WorkflowRun {
563
620
  parentStepRunId?: string;
564
621
  additionalMetadata?: Record<string, any>;
565
622
  }
623
+ export interface ReplayWorkflowRunsRequest {
624
+ /** @maxLength 500 */
625
+ workflowRunIds: string[];
626
+ }
627
+ export interface ReplayWorkflowRunsResponse {
628
+ workflowRuns: WorkflowRun[];
629
+ }
566
630
  export interface WorkflowRunList {
567
631
  rows?: WorkflowRun[];
568
632
  pagination?: PaginationResponse;
569
633
  }
634
+ export declare enum WorkflowRunOrderByField {
635
+ CreatedAt = "createdAt",
636
+ StartedAt = "startedAt",
637
+ FinishedAt = "finishedAt",
638
+ Duration = "duration"
639
+ }
640
+ export declare enum WorkflowRunOrderByDirection {
641
+ ASC = "ASC",
642
+ DESC = "DESC"
643
+ }
570
644
  export interface WorkflowRunsMetrics {
571
645
  counts?: WorkflowRunsMetricsCounts;
572
646
  }
@@ -586,6 +660,12 @@ export declare enum WorkflowRunStatus {
586
660
  QUEUED = "QUEUED"
587
661
  }
588
662
  export type WorkflowRunStatusList = WorkflowRunStatus[];
663
+ export declare enum WorkflowKind {
664
+ FUNCTION = "FUNCTION",
665
+ DURABLE = "DURABLE",
666
+ DAG = "DAG"
667
+ }
668
+ export type WorkflowKindList = WorkflowKind[];
589
669
  export interface WorkflowRunsCancelRequest {
590
670
  workflowRunIds: string[];
591
671
  }
@@ -603,7 +683,8 @@ export declare enum StepRunStatus {
603
683
  RUNNING = "RUNNING",
604
684
  SUCCEEDED = "SUCCEEDED",
605
685
  FAILED = "FAILED",
606
- CANCELLED = "CANCELLED"
686
+ CANCELLED = "CANCELLED",
687
+ CANCELLING = "CANCELLING"
607
688
  }
608
689
  export interface JobRun {
609
690
  metadata: APIResourceMeta;
@@ -629,9 +710,8 @@ export interface JobRun {
629
710
  }
630
711
  export interface WorkflowRunTriggeredBy {
631
712
  metadata: APIResourceMeta;
632
- parentId: string;
713
+ parentWorkflowRunId?: string;
633
714
  eventId?: string;
634
- event?: Event;
635
715
  cronParentId?: string;
636
716
  cronSchedule?: string;
637
717
  }
@@ -642,7 +722,7 @@ export interface StepRun {
642
722
  jobRun?: JobRun;
643
723
  stepId: string;
644
724
  step?: Step;
645
- children?: string[];
725
+ childWorkflowsCount?: number;
646
726
  parents?: string[];
647
727
  childWorkflowRuns?: string[];
648
728
  workerId?: string;
@@ -682,7 +762,9 @@ export declare enum StepRunEventReason {
682
762
  REASSIGNED = "REASSIGNED",
683
763
  TIMED_OUT = "TIMED_OUT",
684
764
  SLOT_RELEASED = "SLOT_RELEASED",
685
- RETRIED_BY_USER = "RETRIED_BY_USER"
765
+ RETRIED_BY_USER = "RETRIED_BY_USER",
766
+ WORKFLOW_RUN_GROUP_KEY_SUCCEEDED = "WORKFLOW_RUN_GROUP_KEY_SUCCEEDED",
767
+ WORKFLOW_RUN_GROUP_KEY_FAILED = "WORKFLOW_RUN_GROUP_KEY_FAILED"
686
768
  }
687
769
  export declare enum StepRunEventSeverity {
688
770
  INFO = "INFO",
@@ -695,7 +777,8 @@ export interface StepRunEvent {
695
777
  timeFirstSeen: string;
696
778
  /** @format date-time */
697
779
  timeLastSeen: string;
698
- stepRunId: string;
780
+ stepRunId?: string;
781
+ workflowRunId?: string;
699
782
  reason: StepRunEventReason;
700
783
  severity: StepRunEventSeverity;
701
784
  message: string;
@@ -714,6 +797,7 @@ export interface StepRunArchive {
714
797
  /** @format date-time */
715
798
  startedAt?: string;
716
799
  error?: string;
800
+ retryCount: number;
717
801
  /** @format date-time */
718
802
  createdAt: string;
719
803
  startedAtEpoch?: number;
@@ -737,10 +821,50 @@ export interface WorkerList {
737
821
  pagination?: PaginationResponse;
738
822
  rows?: Worker[];
739
823
  }
824
+ export interface SemaphoreSlots {
825
+ /**
826
+ * The step run id.
827
+ * @format uuid
828
+ */
829
+ stepRunId: string;
830
+ /** The action id. */
831
+ actionId: string;
832
+ /**
833
+ * The time this slot was started.
834
+ * @format date-time
835
+ */
836
+ startedAt?: string;
837
+ /**
838
+ * The time this slot will timeout.
839
+ * @format date-time
840
+ */
841
+ timeoutAt?: string;
842
+ /**
843
+ * The workflow run id.
844
+ * @format uuid
845
+ */
846
+ workflowRunId: string;
847
+ status: StepRunStatus;
848
+ }
849
+ export interface RecentStepRuns {
850
+ metadata: APIResourceMeta;
851
+ /** The action id. */
852
+ actionId: string;
853
+ status: StepRunStatus;
854
+ /** @format date-time */
855
+ startedAt?: string;
856
+ /** @format date-time */
857
+ finishedAt?: string;
858
+ /** @format date-time */
859
+ cancelledAt?: string;
860
+ /** @format uuid */
861
+ workflowRunId: string;
862
+ }
740
863
  export interface Worker {
741
864
  metadata: APIResourceMeta;
742
865
  /** The name of the worker. */
743
866
  name: string;
867
+ type: 'SELFHOSTED' | 'MANAGED' | 'WEBHOOK';
744
868
  /**
745
869
  * The time this worker last sent a heartbeat.
746
870
  * @format date-time
@@ -755,10 +879,12 @@ export interface Worker {
755
879
  lastListenerEstablished?: string;
756
880
  /** The actions this worker can perform. */
757
881
  actions?: string[];
758
- /** The recent step runs for this worker. */
759
- recentStepRuns?: StepRun[];
882
+ /** The semaphore slot state for the worker. */
883
+ slots?: SemaphoreSlots[];
884
+ /** The recent step runs for the worker. */
885
+ recentStepRuns?: RecentStepRuns[];
760
886
  /** The status of the worker. */
761
- status?: 'ACTIVE' | 'INACTIVE';
887
+ status?: 'ACTIVE' | 'INACTIVE' | 'PAUSED';
762
888
  /** The maximum number of runs this worker can execute concurrently. */
763
889
  maxRuns?: number;
764
890
  /** The number of runs this worker can execute concurrently. */
@@ -771,6 +897,26 @@ export interface Worker {
771
897
  * @example "bb214807-246e-43a5-a25d-41761d1cff9e"
772
898
  */
773
899
  dispatcherId?: string;
900
+ /** The current label state of the worker. */
901
+ labels?: WorkerLabel[];
902
+ /** The webhook URL for the worker. */
903
+ webhookUrl?: string;
904
+ /**
905
+ * The webhook ID for the worker.
906
+ * @format uuid
907
+ */
908
+ webhookId?: string;
909
+ }
910
+ export interface WorkerLabel {
911
+ metadata: APIResourceMeta;
912
+ /** The key of the label. */
913
+ key: string;
914
+ /** The value of the label. */
915
+ value?: string;
916
+ }
917
+ export interface UpdateWorkerRequest {
918
+ /** Whether the worker is paused and cannot accept new runs. */
919
+ isPaused?: boolean;
774
920
  }
775
921
  export interface APIToken {
776
922
  metadata: APIResourceMeta;
@@ -791,6 +937,8 @@ export interface CreateAPITokenRequest {
791
937
  * @maxLength 255
792
938
  */
793
939
  name: string;
940
+ /** The duration for which the token is valid. */
941
+ expiresIn?: string;
794
942
  }
795
943
  export interface CreateAPITokenResponse {
796
944
  /** The API token. */
@@ -918,6 +1066,26 @@ export interface WebhookWorker {
918
1066
  /** The webhook url. */
919
1067
  url: string;
920
1068
  }
1069
+ export declare enum WebhookWorkerRequestMethod {
1070
+ GET = "GET",
1071
+ POST = "POST",
1072
+ PUT = "PUT"
1073
+ }
1074
+ export interface WebhookWorkerRequest {
1075
+ /**
1076
+ * The date and time the request was created.
1077
+ * @format date-time
1078
+ */
1079
+ created_at: string;
1080
+ /** The HTTP method used for the request. */
1081
+ method: WebhookWorkerRequestMethod;
1082
+ /** The HTTP status code of the response. */
1083
+ statusCode: number;
1084
+ }
1085
+ export interface WebhookWorkerRequestListResponse {
1086
+ /** The list of webhook requests. */
1087
+ requests?: WebhookWorkerRequest[];
1088
+ }
921
1089
  export interface WebhookWorkerCreated {
922
1090
  metadata: APIResourceMeta;
923
1091
  /** The name of the webhook worker. */
@@ -10,7 +10,7 @@
10
10
  * ---------------------------------------------------------------
11
11
  */
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.LogLineOrderByDirection = exports.LogLineOrderByField = exports.LogLineLevel = exports.PullRequestState = exports.StepRunEventSeverity = exports.StepRunEventReason = exports.StepRunStatus = exports.JobRunStatus = exports.WorkflowRunStatus = exports.EventOrderByDirection = exports.EventOrderByField = exports.TenantResource = exports.TenantMemberRole = void 0;
13
+ exports.WebhookWorkerRequestMethod = exports.LogLineOrderByDirection = exports.LogLineOrderByField = exports.LogLineLevel = exports.PullRequestState = exports.StepRunEventSeverity = exports.StepRunEventReason = exports.StepRunStatus = exports.JobRunStatus = exports.WorkflowKind = exports.WorkflowRunStatus = exports.WorkflowRunOrderByDirection = exports.WorkflowRunOrderByField = exports.EventOrderByDirection = exports.EventOrderByField = exports.TenantResource = exports.TenantMemberRole = void 0;
14
14
  var TenantMemberRole;
15
15
  (function (TenantMemberRole) {
16
16
  TenantMemberRole["OWNER"] = "OWNER";
@@ -34,6 +34,18 @@ var EventOrderByDirection;
34
34
  EventOrderByDirection["Asc"] = "asc";
35
35
  EventOrderByDirection["Desc"] = "desc";
36
36
  })(EventOrderByDirection || (exports.EventOrderByDirection = EventOrderByDirection = {}));
37
+ var WorkflowRunOrderByField;
38
+ (function (WorkflowRunOrderByField) {
39
+ WorkflowRunOrderByField["CreatedAt"] = "createdAt";
40
+ WorkflowRunOrderByField["StartedAt"] = "startedAt";
41
+ WorkflowRunOrderByField["FinishedAt"] = "finishedAt";
42
+ WorkflowRunOrderByField["Duration"] = "duration";
43
+ })(WorkflowRunOrderByField || (exports.WorkflowRunOrderByField = WorkflowRunOrderByField = {}));
44
+ var WorkflowRunOrderByDirection;
45
+ (function (WorkflowRunOrderByDirection) {
46
+ WorkflowRunOrderByDirection["ASC"] = "ASC";
47
+ WorkflowRunOrderByDirection["DESC"] = "DESC";
48
+ })(WorkflowRunOrderByDirection || (exports.WorkflowRunOrderByDirection = WorkflowRunOrderByDirection = {}));
37
49
  var WorkflowRunStatus;
38
50
  (function (WorkflowRunStatus) {
39
51
  WorkflowRunStatus["PENDING"] = "PENDING";
@@ -43,6 +55,12 @@ var WorkflowRunStatus;
43
55
  WorkflowRunStatus["CANCELLED"] = "CANCELLED";
44
56
  WorkflowRunStatus["QUEUED"] = "QUEUED";
45
57
  })(WorkflowRunStatus || (exports.WorkflowRunStatus = WorkflowRunStatus = {}));
58
+ var WorkflowKind;
59
+ (function (WorkflowKind) {
60
+ WorkflowKind["FUNCTION"] = "FUNCTION";
61
+ WorkflowKind["DURABLE"] = "DURABLE";
62
+ WorkflowKind["DAG"] = "DAG";
63
+ })(WorkflowKind || (exports.WorkflowKind = WorkflowKind = {}));
46
64
  var JobRunStatus;
47
65
  (function (JobRunStatus) {
48
66
  JobRunStatus["PENDING"] = "PENDING";
@@ -60,6 +78,7 @@ var StepRunStatus;
60
78
  StepRunStatus["SUCCEEDED"] = "SUCCEEDED";
61
79
  StepRunStatus["FAILED"] = "FAILED";
62
80
  StepRunStatus["CANCELLED"] = "CANCELLED";
81
+ StepRunStatus["CANCELLING"] = "CANCELLING";
63
82
  })(StepRunStatus || (exports.StepRunStatus = StepRunStatus = {}));
64
83
  var StepRunEventReason;
65
84
  (function (StepRunEventReason) {
@@ -77,6 +96,8 @@ var StepRunEventReason;
77
96
  StepRunEventReason["TIMED_OUT"] = "TIMED_OUT";
78
97
  StepRunEventReason["SLOT_RELEASED"] = "SLOT_RELEASED";
79
98
  StepRunEventReason["RETRIED_BY_USER"] = "RETRIED_BY_USER";
99
+ StepRunEventReason["WORKFLOW_RUN_GROUP_KEY_SUCCEEDED"] = "WORKFLOW_RUN_GROUP_KEY_SUCCEEDED";
100
+ StepRunEventReason["WORKFLOW_RUN_GROUP_KEY_FAILED"] = "WORKFLOW_RUN_GROUP_KEY_FAILED";
80
101
  })(StepRunEventReason || (exports.StepRunEventReason = StepRunEventReason = {}));
81
102
  var StepRunEventSeverity;
82
103
  (function (StepRunEventSeverity) {
@@ -105,3 +126,9 @@ var LogLineOrderByDirection;
105
126
  LogLineOrderByDirection["Asc"] = "asc";
106
127
  LogLineOrderByDirection["Desc"] = "desc";
107
128
  })(LogLineOrderByDirection || (exports.LogLineOrderByDirection = LogLineOrderByDirection = {}));
129
+ var WebhookWorkerRequestMethod;
130
+ (function (WebhookWorkerRequestMethod) {
131
+ WebhookWorkerRequestMethod["GET"] = "GET";
132
+ WebhookWorkerRequestMethod["POST"] = "POST";
133
+ WebhookWorkerRequestMethod["PUT"] = "PUT";
134
+ })(WebhookWorkerRequestMethod || (exports.WebhookWorkerRequestMethod = WebhookWorkerRequestMethod = {}));
@@ -63,7 +63,7 @@ class HttpClient {
63
63
  if (type === ContentType.Text && body && body !== null && typeof body !== 'string') {
64
64
  body = JSON.stringify(body);
65
65
  }
66
- return this.instance.request(Object.assign(Object.assign({}, requestParams), { headers: Object.assign(Object.assign({}, (requestParams.headers || {})), (type && type !== ContentType.FormData ? { 'Content-Type': type } : {})), params: query, responseType: responseFormat, data: body, url: path }));
66
+ return this.instance.request(Object.assign(Object.assign({}, requestParams), { headers: Object.assign(Object.assign({}, (requestParams.headers || {})), (type ? { 'Content-Type': type } : {})), params: query, responseType: responseFormat, data: body, url: path }));
67
67
  });
68
68
  this.instance = axios_1.default.create(Object.assign(Object.assign({}, axiosConfig), { baseURL: axiosConfig.baseURL || '' }));
69
69
  this.secure = secure;
@@ -85,6 +85,9 @@ class HttpClient {
85
85
  }
86
86
  }
87
87
  createFormData(input) {
88
+ if (input instanceof FormData) {
89
+ return input;
90
+ }
88
91
  return Object.keys(input || {}).reduce((formData, key) => {
89
92
  const property = input[key];
90
93
  const propertyContent = property instanceof Array ? property : [property];
@@ -57,8 +57,9 @@ class Worker {
57
57
  }
58
58
  : {};
59
59
  this.action_registry = Object.assign(Object.assign(Object.assign({}, this.action_registry), newActions), onFailureAction);
60
- this.action_registry = ((_a = workflow.concurrency) === null || _a === void 0 ? void 0 : _a.name)
61
- ? Object.assign(Object.assign({}, this.action_registry), { [`${workflow.id}:${workflow.concurrency.name}`]: workflow.concurrency.key }) : Object.assign({}, this.action_registry);
60
+ this.action_registry =
61
+ ((_a = workflow.concurrency) === null || _a === void 0 ? void 0 : _a.name) && workflow.concurrency.key
62
+ ? Object.assign(Object.assign({}, this.action_registry), { [`${workflow.id}:${workflow.concurrency.name}`]: workflow.concurrency.key }) : Object.assign({}, this.action_registry);
62
63
  }
63
64
  getHandler(workflows) {
64
65
  for (const workflow of workflows) {
@@ -82,13 +83,19 @@ class Worker {
82
83
  }
83
84
  registerWorkflow(initWorkflow) {
84
85
  return __awaiter(this, void 0, void 0, function* () {
85
- var _a, _b;
86
+ var _a, _b, _c, _d;
86
87
  const workflow = Object.assign(Object.assign({}, initWorkflow), { id: this.client.config.namespace + initWorkflow.id });
87
88
  try {
88
- const concurrency = ((_a = workflow.concurrency) === null || _a === void 0 ? void 0 : _a.name)
89
+ if (((_a = workflow.concurrency) === null || _a === void 0 ? void 0 : _a.key) && workflow.concurrency.expression) {
90
+ throw new hatchet_error_1.default('Cannot have both key function and expression in workflow concurrency configuration');
91
+ }
92
+ const concurrency = ((_b = workflow.concurrency) === null || _b === void 0 ? void 0 : _b.name) || ((_c = workflow.concurrency) === null || _c === void 0 ? void 0 : _c.expression)
89
93
  ? {
90
- action: `${workflow.id}:${workflow.concurrency.name}`,
94
+ action: !workflow.concurrency.expression
95
+ ? `${workflow.id}:${workflow.concurrency.name}`
96
+ : undefined,
91
97
  maxRuns: workflow.concurrency.maxRuns || 1,
98
+ expression: workflow.concurrency.expression,
92
99
  limitStrategy: workflow.concurrency.limitStrategy || workflows_1.ConcurrencyLimitStrategy.CANCEL_IN_PROGRESS,
93
100
  }
94
101
  : undefined;
@@ -105,7 +112,7 @@ class Worker {
105
112
  parents: [],
106
113
  userData: '{}',
107
114
  retries: workflow.onFailure.retries || 0,
108
- rateLimits: (_b = workflow.onFailure.rate_limits) !== null && _b !== void 0 ? _b : [],
115
+ rateLimits: (_d = workflow.onFailure.rate_limits) !== null && _d !== void 0 ? _d : [],
109
116
  workerLabels: {}, // no worker labels for on failure steps
110
117
  },
111
118
  ],
@@ -26,7 +26,7 @@ const workflow = {
26
26
  },
27
27
  concurrency: {
28
28
  name: 'user-concurrency',
29
- key: (ctx) => ctx.workflowInput().group,
29
+ expression: 'input.group',
30
30
  maxRuns: 2,
31
31
  limitStrategy: workflow_1.ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
32
32
  },
@@ -0,0 +1,62 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const sdk_1 = __importDefault(require("../../../sdk"));
16
+ const workflow_1 = require("../../../workflow");
17
+ const hatchet = sdk_1.default.init();
18
+ const sleep = (ms) => new Promise((resolve) => {
19
+ setTimeout(resolve, ms);
20
+ });
21
+ const workflow = {
22
+ id: 'concurrency-example-rr',
23
+ description: 'test',
24
+ on: {
25
+ event: 'concurrency:create',
26
+ },
27
+ concurrency: {
28
+ name: 'user-concurrency',
29
+ // NOTE: it is recommended to use expression unless you specifically need to use a custom key function
30
+ key: (ctx) => ctx.workflowInput().group,
31
+ maxRuns: 2,
32
+ limitStrategy: workflow_1.ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
33
+ },
34
+ steps: [
35
+ {
36
+ name: 'step1',
37
+ run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
38
+ const { data } = ctx.workflowInput();
39
+ const { signal } = ctx.controller;
40
+ if (signal.aborted)
41
+ throw new Error('step1 was aborted');
42
+ console.log('starting step1 and waiting 5 seconds...', data);
43
+ yield sleep(2000);
44
+ if (signal.aborted)
45
+ throw new Error('step1 was aborted');
46
+ // NOTE: the AbortController signal can be passed to many http libraries to cancel active requests
47
+ // fetch(url, { signal })
48
+ // axios.get(url, { signal })
49
+ console.log('executed step1!');
50
+ return { step1: `step1 results for ${data}!` };
51
+ }),
52
+ },
53
+ ],
54
+ };
55
+ function main() {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ const worker = yield hatchet.worker('example-worker');
58
+ yield worker.registerWorkflow(workflow);
59
+ worker.start();
60
+ });
61
+ }
62
+ main();
@@ -5,6 +5,44 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const sdk_1 = __importDefault(require("../sdk"));
7
7
  const hatchet = sdk_1.default.init();
8
+ // Push a single event (example)
8
9
  hatchet.event.push('user:create', {
9
10
  test: 'test',
10
11
  });
12
+ // Example events to be pushed in bulk
13
+ const events = [
14
+ {
15
+ payload: { test: 'test1' },
16
+ additionalMetadata: { user_id: 'user1', source: 'test' },
17
+ },
18
+ {
19
+ payload: { test: 'test2' },
20
+ additionalMetadata: { user_id: 'user2', source: 'test' },
21
+ },
22
+ {
23
+ payload: { test: 'test3' },
24
+ additionalMetadata: { user_id: 'user3', source: 'test' },
25
+ },
26
+ ];
27
+ // Bulk push the events and compare the keys
28
+ hatchet.event
29
+ .bulkPush('user:create:bulk', events)
30
+ .then((result) => {
31
+ const returnedEvents = result.events;
32
+ const keysMatch = returnedEvents.every((returnedEvent) => {
33
+ const expectedKey = `user:create:bulk`;
34
+ return returnedEvent.key === expectedKey;
35
+ });
36
+ if (keysMatch) {
37
+ // eslint-disable-next-line no-console
38
+ console.log('All keys match the original events.');
39
+ }
40
+ else {
41
+ // eslint-disable-next-line no-console
42
+ console.log('Mismatch found between original events and returned events.');
43
+ }
44
+ })
45
+ .catch((error) => {
46
+ // eslint-disable-next-line no-console
47
+ console.error('Error during bulk push:', error);
48
+ });
@@ -14,9 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const sdk_1 = __importDefault(require("../sdk"));
16
16
  const hatchet = sdk_1.default.init();
17
- const sleep = (ms) => new Promise((resolve) => {
18
- setTimeout(resolve, ms);
19
- });
20
17
  const parentWorkflow = {
21
18
  id: 'parent-workflow',
22
19
  description: 'simple example for spawning child workflows',
@@ -26,14 +23,19 @@ const parentWorkflow = {
26
23
  steps: [
27
24
  {
28
25
  name: 'parent-spawn',
29
- timeout: '10s',
26
+ timeout: '70s',
30
27
  run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
31
- ctx.putStream('spawning children');
32
- const promises = Array.from({ length: 7 }, (_, i) => ctx.spawnWorkflow('child-workflow', { input: `child-input-${i}` }, { additionalMetadata: { childKey: "childValue" } }).result());
28
+ const promises = Array.from({ length: 3 }, (_, i) => ctx
29
+ .spawnWorkflow('child-workflow', { input: `child-input-${i}` }, { additionalMetadata: { childKey: 'childValue' } })
30
+ .result()
31
+ .then((result) => {
32
+ ctx.log('spawned workflow result:');
33
+ return result;
34
+ }));
33
35
  const results = yield Promise.all(promises);
34
36
  console.log('spawned workflow results:', results);
35
37
  console.log('number of spawned workflows:', results.length);
36
- return { spawned: results };
38
+ return { spawned: 'x' };
37
39
  }),
38
40
  },
39
41
  ],
@@ -42,25 +44,46 @@ const childWorkflow = {
42
44
  id: 'child-workflow',
43
45
  description: 'simple example for spawning child workflows',
44
46
  on: {
45
- event: 'fanout:create',
47
+ event: 'child:create',
46
48
  },
47
49
  steps: [
48
50
  {
49
51
  name: 'child-work',
50
52
  run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
51
53
  const { input } = ctx.workflowInput();
52
- ctx.putStream('child running...');
53
- yield sleep(10);
54
+ // throw new Error('child error');
55
+ return { 'child-output': 'sm' };
56
+ }),
57
+ },
58
+ {
59
+ name: 'child-work2',
60
+ run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
61
+ const { input } = ctx.workflowInput();
62
+ // Perform CPU-bound work
54
63
  // throw new Error('child error');
55
64
  console.log('child workflow input:', input);
56
- return { 'child-output': 'results' };
65
+ // Generate a large amount of garbage data
66
+ const garbageData = Array.from({ length: 1e6 / 3.5 }, (_, i) => `garbage-${i}`).join(',');
67
+ console.log('Generated garbage data:', `${garbageData.slice(0, 100)}...`); // Print a snippet of the garbage data
68
+ return { 'child-output': garbageData };
69
+ }),
70
+ },
71
+ {
72
+ name: 'child-work3',
73
+ parents: ['child-work'],
74
+ run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
75
+ const { input } = ctx.workflowInput();
76
+ // throw new Error('child error');
77
+ const garbageData = Array.from({ length: 1e6 / 3.5 }, (_, i) => `garbage-${i}`).join(',');
78
+ console.log('Generated garbage data:', `${garbageData.slice(0, 100)}...`); // Print a snippet of the garbage data
79
+ return { 'child-output': garbageData };
57
80
  }),
58
81
  },
59
82
  ],
60
83
  };
61
84
  function main() {
62
85
  return __awaiter(this, void 0, void 0, function* () {
63
- const worker = yield hatchet.worker('fanout-worker');
86
+ const worker = yield hatchet.worker('fanout-worker', { maxRuns: 1000 });
64
87
  yield worker.registerWorkflow(parentWorkflow);
65
88
  yield worker.registerWorkflow(childWorkflow);
66
89
  worker.start();