@hatchet-dev/typescript-sdk 0.13.1 → 0.15.0

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.
@@ -12,6 +12,17 @@ type WorkflowMetricsQuery = {
12
12
  status?: WorkflowRunStatus;
13
13
  groupKey?: string;
14
14
  };
15
+ export type WorkflowRun<T = object> = {
16
+ workflowName: string;
17
+ input: T;
18
+ options?: {
19
+ parentId?: string | undefined;
20
+ parentStepRunId?: string | undefined;
21
+ childIndex?: number | undefined;
22
+ childKey?: string | undefined;
23
+ additionalMetadata?: Record<string, string> | undefined;
24
+ };
25
+ };
15
26
  /**
16
27
  * AdminClient is a client for interacting with the Hatchet Admin API. This allows you to configure, trigger,
17
28
  * and monitor workflows.
@@ -78,6 +89,24 @@ export declare class AdminClient {
78
89
  additionalMetadata?: Record<string, string> | undefined;
79
90
  desiredWorkerId?: string | undefined;
80
91
  }): WorkflowRunRef<P>;
92
+ /**
93
+ * Run multiple workflows runs with the given input and options. This will create new workflow runs and return their IDs.
94
+ * Order is preserved in the response.
95
+ * @param workflowRuns an array of objects containing the workflow name, input, and options for each workflow run
96
+ * @returns an array of workflow run references
97
+ */
98
+ runWorkflows<Q = object, P = object>(workflowRuns: Array<{
99
+ workflowName: string;
100
+ input: Q;
101
+ options?: {
102
+ parentId?: string | undefined;
103
+ parentStepRunId?: string | undefined;
104
+ childIndex?: number | undefined;
105
+ childKey?: string | undefined;
106
+ additionalMetadata?: Record<string, string> | undefined;
107
+ desiredWorkerId?: string | undefined;
108
+ };
109
+ }>): Promise<WorkflowRunRef<P>[]>;
81
110
  /**
82
111
  * @deprecated use listWorkflows instead
83
112
  */
@@ -127,6 +127,40 @@ class AdminClient {
127
127
  throw new hatchet_error_1.default(e.message);
128
128
  }
129
129
  }
130
+ /**
131
+ * Run multiple workflows runs with the given input and options. This will create new workflow runs and return their IDs.
132
+ * Order is preserved in the response.
133
+ * @param workflowRuns an array of objects containing the workflow name, input, and options for each workflow run
134
+ * @returns an array of workflow run references
135
+ */
136
+ runWorkflows(workflowRuns) {
137
+ // Prepare workflows to be triggered in bulk
138
+ const workflowRequests = workflowRuns.map(({ workflowName, input, options }) => {
139
+ let computedName = workflowName;
140
+ if (this.config.namespace && !workflowName.startsWith(this.config.namespace)) {
141
+ computedName = this.config.namespace + workflowName;
142
+ }
143
+ const inputStr = JSON.stringify(input);
144
+ return Object.assign(Object.assign({ name: computedName, input: inputStr }, options), { additionalMetadata: (options === null || options === void 0 ? void 0 : options.additionalMetadata)
145
+ ? JSON.stringify(options.additionalMetadata)
146
+ : undefined });
147
+ });
148
+ try {
149
+ // Call the bulk trigger workflow method
150
+ const bulkTriggerWorkflowResponse = this.client.bulkTriggerWorkflow(workflows_1.BulkTriggerWorkflowRequest.create({
151
+ workflows: workflowRequests,
152
+ }));
153
+ return bulkTriggerWorkflowResponse.then((res) => {
154
+ return res.workflowRunIds.map((resp, index) => {
155
+ const { options } = workflowRuns[index];
156
+ return new workflow_run_ref_1.default(resp, this.listenerClient, options === null || options === void 0 ? void 0 : options.parentId);
157
+ });
158
+ });
159
+ }
160
+ catch (e) {
161
+ throw new hatchet_error_1.default(e.message);
162
+ }
163
+ }
130
164
  /**
131
165
  * @deprecated use listWorkflows instead
132
166
  */
@@ -1,4 +1,4 @@
1
- import { AcceptInviteRequest, APIErrors, APIMeta, BulkCreateEventRequest, BulkCreateEventResponse, CancelEventRequest, CreateAPITokenRequest, CreateAPITokenResponse, CreateEventRequest, CreateSNSIntegrationRequest, CreateTenantAlertEmailGroupRequest, CreateTenantInviteRequest, CreateTenantRequest, Event, EventData, EventKey, EventKeyList, EventList, EventOrderByDirection, EventOrderByField, EventSearch, ListAPIMetaIntegration, ListAPITokensResponse, ListSlackWebhooks, ListSNSIntegrations, LogLineLevelField, LogLineList, LogLineOrderByDirection, LogLineOrderByField, LogLineSearch, RejectInviteRequest, ReplayEventRequest, ReplayWorkflowRunsRequest, ReplayWorkflowRunsResponse, RerunStepRunRequest, SNSIntegration, StepRun, StepRunArchiveList, StepRunEventList, Tenant, TenantAlertEmailGroup, TenantAlertEmailGroupList, TenantAlertingSettings, TenantInvite, TenantInviteList, TenantMember, TenantMemberList, TenantQueueMetrics, TenantResourcePolicy, TriggerWorkflowRunRequest, UpdateTenantAlertEmailGroupRequest, UpdateTenantInviteRequest, UpdateTenantRequest, UpdateWorkerRequest, User, UserChangePasswordRequest, UserLoginRequest, UserRegisterRequest, UserTenantMembershipsList, WebhookWorkerCreated, WebhookWorkerCreateRequest, WebhookWorkerListResponse, WebhookWorkerRequestListResponse, Worker, WorkerList, Workflow, WorkflowID, WorkflowKindList, WorkflowList, WorkflowMetrics, WorkflowRun, WorkflowRunList, WorkflowRunOrderByDirection, WorkflowRunOrderByField, WorkflowRunsCancelRequest, WorkflowRunShape, WorkflowRunsMetrics, WorkflowRunStatus, WorkflowRunStatusList, WorkflowVersion, WorkflowWorkersCount } from './data-contracts';
1
+ import { AcceptInviteRequest, APIErrors, APIMeta, BulkCreateEventRequest, BulkCreateEventResponse, CancelEventRequest, CreateAPITokenRequest, CreateAPITokenResponse, CreateEventRequest, CreateSNSIntegrationRequest, CreateTenantAlertEmailGroupRequest, CreateTenantInviteRequest, CreateTenantRequest, Event, EventData, EventKey, EventKeyList, EventList, EventOrderByDirection, EventOrderByField, EventSearch, ListAPIMetaIntegration, ListAPITokensResponse, ListSlackWebhooks, ListSNSIntegrations, LogLineLevelField, LogLineList, LogLineOrderByDirection, LogLineOrderByField, LogLineSearch, RateLimitList, RateLimitOrderByDirection, RateLimitOrderByField, RejectInviteRequest, ReplayEventRequest, ReplayWorkflowRunsRequest, ReplayWorkflowRunsResponse, RerunStepRunRequest, SNSIntegration, StepRun, StepRunArchiveList, StepRunEventList, Tenant, TenantAlertEmailGroup, TenantAlertEmailGroupList, TenantAlertingSettings, TenantInvite, TenantInviteList, TenantMember, TenantMemberList, TenantQueueMetrics, TenantResourcePolicy, TenantStepRunQueueMetrics, TriggerWorkflowRunRequest, UpdateTenantAlertEmailGroupRequest, UpdateTenantInviteRequest, UpdateTenantRequest, UpdateWorkerRequest, User, UserChangePasswordRequest, UserLoginRequest, UserRegisterRequest, UserTenantMembershipsList, WebhookWorkerCreated, WebhookWorkerCreateRequest, WebhookWorkerListResponse, WebhookWorkerRequestListResponse, Worker, WorkerList, Workflow, WorkflowID, WorkflowKindList, WorkflowList, WorkflowMetrics, WorkflowRun, WorkflowRunList, WorkflowRunOrderByDirection, WorkflowRunOrderByField, WorkflowRunsCancelRequest, WorkflowRunShape, WorkflowRunsMetrics, WorkflowRunStatus, WorkflowRunStatusList, WorkflowUpdateRequest, WorkflowVersion, WorkflowWorkersCount } from './data-contracts';
2
2
  import { HttpClient, RequestParams } from './http-client';
3
3
  export declare class Api<SecurityDataType = unknown> extends HttpClient<SecurityDataType> {
4
4
  /**
@@ -416,6 +416,16 @@ export declare class Api<SecurityDataType = unknown> extends HttpClient<Security
416
416
  */
417
417
  additionalMetadata?: string[];
418
418
  }, params?: RequestParams) => Promise<import("axios").AxiosResponse<TenantQueueMetrics, any>>;
419
+ /**
420
+ * @description Get the queue metrics for the tenant
421
+ *
422
+ * @tags Tenant
423
+ * @name TenantGetStepRunQueueMetrics
424
+ * @summary Get step run metrics
425
+ * @request GET:/api/v1/tenants/{tenant}/step-run-queue-metrics
426
+ * @secure
427
+ */
428
+ tenantGetStepRunQueueMetrics: (tenant: string, params?: RequestParams) => Promise<import("axios").AxiosResponse<TenantStepRunQueueMetrics, any>>;
419
429
  /**
420
430
  * @description Lists all events for a tenant.
421
431
  *
@@ -498,6 +508,33 @@ export declare class Api<SecurityDataType = unknown> extends HttpClient<Security
498
508
  eventUpdateCancel: (tenant: string, data: CancelEventRequest, params?: RequestParams) => Promise<import("axios").AxiosResponse<{
499
509
  workflowRunIds?: string[];
500
510
  }, any>>;
511
+ /**
512
+ * @description Lists all rate limits for a tenant.
513
+ *
514
+ * @tags Rate Limits
515
+ * @name RateLimitList
516
+ * @summary List rate limits
517
+ * @request GET:/api/v1/tenants/{tenant}/rate-limits
518
+ * @secure
519
+ */
520
+ rateLimitList: (tenant: string, query?: {
521
+ /**
522
+ * The number to skip
523
+ * @format int64
524
+ */
525
+ offset?: number;
526
+ /**
527
+ * The number to limit by
528
+ * @format int64
529
+ */
530
+ limit?: number;
531
+ /** The search query to filter for */
532
+ search?: string;
533
+ /** What to order by */
534
+ orderByField?: RateLimitOrderByField;
535
+ /** The order direction */
536
+ orderByDirection?: RateLimitOrderByDirection;
537
+ }, params?: RequestParams) => Promise<import("axios").AxiosResponse<RateLimitList, any>>;
501
538
  /**
502
539
  * @description Gets a list of tenant members
503
540
  *
@@ -590,6 +627,16 @@ export declare class Api<SecurityDataType = unknown> extends HttpClient<Security
590
627
  * @secure
591
628
  */
592
629
  workflowDelete: (workflow: string, params?: RequestParams) => Promise<import("axios").AxiosResponse<void, any>>;
630
+ /**
631
+ * @description Update a workflow for a tenant
632
+ *
633
+ * @tags Workflow
634
+ * @name WorkflowUpdate
635
+ * @summary Update workflow
636
+ * @request PATCH:/api/v1/workflows/{workflow}
637
+ * @secure
638
+ */
639
+ workflowUpdate: (workflow: string, data: WorkflowUpdateRequest, params?: RequestParams) => Promise<import("axios").AxiosResponse<Workflow, any>>;
593
640
  /**
594
641
  * @description Get a workflow version for a tenant
595
642
  *
@@ -807,6 +854,18 @@ export declare class Api<SecurityDataType = unknown> extends HttpClient<Security
807
854
  * @example "2021-01-01T00:00:00Z"
808
855
  */
809
856
  createdBefore?: string;
857
+ /**
858
+ * The time after the workflow run was finished
859
+ * @format date-time
860
+ * @example "2021-01-01T00:00:00Z"
861
+ */
862
+ finishedAfter?: string;
863
+ /**
864
+ * The time before the workflow run was finished
865
+ * @format date-time
866
+ * @example "2021-01-01T00:00:00Z"
867
+ */
868
+ finishedBefore?: string;
810
869
  /** The order by field */
811
870
  orderByField?: WorkflowRunOrderByField;
812
871
  /** The order by direction */
@@ -422,6 +422,16 @@ class Api extends http_client_1.HttpClient {
422
422
  * @secure
423
423
  */
424
424
  this.tenantGetQueueMetrics = (tenant, query, params = {}) => this.request(Object.assign({ path: `/api/v1/tenants/${tenant}/queue-metrics`, method: 'GET', query: query, secure: true, format: 'json' }, params));
425
+ /**
426
+ * @description Get the queue metrics for the tenant
427
+ *
428
+ * @tags Tenant
429
+ * @name TenantGetStepRunQueueMetrics
430
+ * @summary Get step run metrics
431
+ * @request GET:/api/v1/tenants/{tenant}/step-run-queue-metrics
432
+ * @secure
433
+ */
434
+ this.tenantGetStepRunQueueMetrics = (tenant, params = {}) => this.request(Object.assign({ path: `/api/v1/tenants/${tenant}/step-run-queue-metrics`, method: 'GET', secure: true, format: 'json' }, params));
425
435
  /**
426
436
  * @description Lists all events for a tenant.
427
437
  *
@@ -472,6 +482,16 @@ class Api extends http_client_1.HttpClient {
472
482
  * @secure
473
483
  */
474
484
  this.eventUpdateCancel = (tenant, data, params = {}) => this.request(Object.assign({ path: `/api/v1/tenants/${tenant}/events/cancel`, method: 'POST', body: data, secure: true, type: http_client_1.ContentType.Json, format: 'json' }, params));
485
+ /**
486
+ * @description Lists all rate limits for a tenant.
487
+ *
488
+ * @tags Rate Limits
489
+ * @name RateLimitList
490
+ * @summary List rate limits
491
+ * @request GET:/api/v1/tenants/{tenant}/rate-limits
492
+ * @secure
493
+ */
494
+ this.rateLimitList = (tenant, query, params = {}) => this.request(Object.assign({ path: `/api/v1/tenants/${tenant}/rate-limits`, method: 'GET', query: query, secure: true, format: 'json' }, params));
475
495
  /**
476
496
  * @description Gets a list of tenant members
477
497
  *
@@ -562,6 +582,16 @@ class Api extends http_client_1.HttpClient {
562
582
  * @secure
563
583
  */
564
584
  this.workflowDelete = (workflow, params = {}) => this.request(Object.assign({ path: `/api/v1/workflows/${workflow}`, method: 'DELETE', secure: true }, params));
585
+ /**
586
+ * @description Update a workflow for a tenant
587
+ *
588
+ * @tags Workflow
589
+ * @name WorkflowUpdate
590
+ * @summary Update workflow
591
+ * @request PATCH:/api/v1/workflows/{workflow}
592
+ * @secure
593
+ */
594
+ this.workflowUpdate = (workflow, data, params = {}) => this.request(Object.assign({ path: `/api/v1/workflows/${workflow}`, method: 'PATCH', body: data, secure: true, type: http_client_1.ContentType.Json, format: 'json' }, params));
565
595
  /**
566
596
  * @description Get a workflow version for a tenant
567
597
  *
@@ -314,6 +314,10 @@ export interface TenantQueueMetrics {
314
314
  /** The total queue metrics. */
315
315
  total?: QueueMetrics;
316
316
  workflow?: Record<string, QueueMetrics>;
317
+ queues?: Record<string, number>;
318
+ }
319
+ export interface TenantStepRunQueueMetrics {
320
+ queues?: Record<string, number>;
317
321
  }
318
322
  export interface AcceptInviteRequest {
319
323
  /**
@@ -437,6 +441,37 @@ export interface EventList {
437
441
  pagination?: PaginationResponse;
438
442
  rows?: Event[];
439
443
  }
444
+ export interface RateLimit {
445
+ /** The key for the rate limit. */
446
+ key: string;
447
+ /** The ID of the tenant associated with this rate limit. */
448
+ tenantId: string;
449
+ /** The maximum number of requests allowed within the window. */
450
+ limitValue: number;
451
+ /** The current number of requests made within the window. */
452
+ value: number;
453
+ /** The window of time in which the limitValue is enforced. */
454
+ window: string;
455
+ /**
456
+ * The last time the rate limit was refilled.
457
+ * @format date-time
458
+ * @example "2022-12-13T20:06:48.888Z"
459
+ */
460
+ lastRefill: string;
461
+ }
462
+ export interface RateLimitList {
463
+ pagination?: PaginationResponse;
464
+ rows?: RateLimit[];
465
+ }
466
+ export declare enum RateLimitOrderByField {
467
+ Key = "key",
468
+ Value = "value",
469
+ LimitValue = "limitValue"
470
+ }
471
+ export declare enum RateLimitOrderByDirection {
472
+ Asc = "asc",
473
+ Desc = "desc"
474
+ }
440
475
  export interface ReplayEventRequest {
441
476
  eventIds: string[];
442
477
  }
@@ -449,12 +484,18 @@ export interface Workflow {
449
484
  name: string;
450
485
  /** The description of the workflow. */
451
486
  description?: string;
487
+ /** Whether the workflow is paused. */
488
+ isPaused?: boolean;
452
489
  versions?: WorkflowVersionMeta[];
453
490
  /** The tags of the workflow. */
454
491
  tags?: WorkflowTag[];
455
492
  /** The jobs of the workflow. */
456
493
  jobs?: Job[];
457
494
  }
495
+ export interface WorkflowUpdateRequest {
496
+ /** Whether the workflow is paused. */
497
+ isPaused?: boolean;
498
+ }
458
499
  export interface WorkflowConcurrency {
459
500
  /**
460
501
  * The maximum number of concurrent workflow runs.
@@ -754,6 +795,7 @@ export declare enum StepRunEventReason {
754
795
  SCHEDULING_TIMED_OUT = "SCHEDULING_TIMED_OUT",
755
796
  ASSIGNED = "ASSIGNED",
756
797
  STARTED = "STARTED",
798
+ ACKNOWLEDGED = "ACKNOWLEDGED",
757
799
  FINISHED = "FINISHED",
758
800
  FAILED = "FAILED",
759
801
  RETRYING = "RETRYING",
@@ -10,7 +10,7 @@
10
10
  * ---------------------------------------------------------------
11
11
  */
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
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;
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.RateLimitOrderByDirection = exports.RateLimitOrderByField = 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,17 @@ var EventOrderByDirection;
34
34
  EventOrderByDirection["Asc"] = "asc";
35
35
  EventOrderByDirection["Desc"] = "desc";
36
36
  })(EventOrderByDirection || (exports.EventOrderByDirection = EventOrderByDirection = {}));
37
+ var RateLimitOrderByField;
38
+ (function (RateLimitOrderByField) {
39
+ RateLimitOrderByField["Key"] = "key";
40
+ RateLimitOrderByField["Value"] = "value";
41
+ RateLimitOrderByField["LimitValue"] = "limitValue";
42
+ })(RateLimitOrderByField || (exports.RateLimitOrderByField = RateLimitOrderByField = {}));
43
+ var RateLimitOrderByDirection;
44
+ (function (RateLimitOrderByDirection) {
45
+ RateLimitOrderByDirection["Asc"] = "asc";
46
+ RateLimitOrderByDirection["Desc"] = "desc";
47
+ })(RateLimitOrderByDirection || (exports.RateLimitOrderByDirection = RateLimitOrderByDirection = {}));
37
48
  var WorkflowRunOrderByField;
38
49
  (function (WorkflowRunOrderByField) {
39
50
  WorkflowRunOrderByField["CreatedAt"] = "createdAt";
@@ -87,6 +98,7 @@ var StepRunEventReason;
87
98
  StepRunEventReason["SCHEDULING_TIMED_OUT"] = "SCHEDULING_TIMED_OUT";
88
99
  StepRunEventReason["ASSIGNED"] = "ASSIGNED";
89
100
  StepRunEventReason["STARTED"] = "STARTED";
101
+ StepRunEventReason["ACKNOWLEDGED"] = "ACKNOWLEDGED";
90
102
  StepRunEventReason["FINISHED"] = "FINISHED";
91
103
  StepRunEventReason["FAILED"] = "FAILED";
92
104
  StepRunEventReason["RETRYING"] = "RETRYING";
@@ -83,7 +83,7 @@ class Worker {
83
83
  }
84
84
  registerWorkflow(initWorkflow) {
85
85
  return __awaiter(this, void 0, void 0, function* () {
86
- var _a, _b, _c, _d;
86
+ var _a, _b, _c;
87
87
  const workflow = Object.assign(Object.assign({}, initWorkflow), { id: this.client.config.namespace + initWorkflow.id });
88
88
  try {
89
89
  if (((_a = workflow.concurrency) === null || _a === void 0 ? void 0 : _a.key) && workflow.concurrency.expression) {
@@ -112,7 +112,7 @@ class Worker {
112
112
  parents: [],
113
113
  userData: '{}',
114
114
  retries: workflow.onFailure.retries || 0,
115
- rateLimits: (_d = workflow.onFailure.rate_limits) !== null && _d !== void 0 ? _d : [],
115
+ rateLimits: (0, step_1.mapRateLimit)(workflow.onFailure.rate_limits),
116
116
  workerLabels: {}, // no worker labels for on failure steps
117
117
  },
118
118
  ],
@@ -136,7 +136,7 @@ class Worker {
136
136
  name: workflow.id,
137
137
  description: workflow.description,
138
138
  steps: workflow.steps.map((step) => {
139
- var _a, _b;
139
+ var _a;
140
140
  return ({
141
141
  readableId: step.name,
142
142
  action: `${workflow.id}:${step.name}`,
@@ -145,7 +145,7 @@ class Worker {
145
145
  parents: (_a = step.parents) !== null && _a !== void 0 ? _a : [],
146
146
  userData: '{}',
147
147
  retries: step.retries || 0,
148
- rateLimits: (_b = step.rate_limits) !== null && _b !== void 0 ? _b : [], // Add the missing rateLimits property
148
+ rateLimits: (0, step_1.mapRateLimit)(step.rate_limits),
149
149
  workerLabels: toPbWorkerLabel(step.worker_labels),
150
150
  });
151
151
  }),
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,74 @@
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 __asyncValues = (this && this.__asyncValues) || function (o) {
12
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
+ var m = o[Symbol.asyncIterator], i;
14
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
15
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
16
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
17
+ };
18
+ var __importDefault = (this && this.__importDefault) || function (mod) {
19
+ return (mod && mod.__esModule) ? mod : { "default": mod };
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ const sdk_1 = __importDefault(require("../sdk"));
23
+ const hatchet = sdk_1.default.init();
24
+ function main() {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const workflowRuns = [];
27
+ workflowRuns[0] = {
28
+ workflowName: 'bulk-parent-workflow',
29
+ input: {},
30
+ options: {
31
+ additionalMetadata: {
32
+ key: 'value',
33
+ },
34
+ },
35
+ };
36
+ workflowRuns[1] = {
37
+ workflowName: 'bulk-parent-workflow',
38
+ input: { second: 'second' },
39
+ options: {
40
+ additionalMetadata: {
41
+ key: 'value',
42
+ },
43
+ },
44
+ };
45
+ try {
46
+ const workflowRunResponse = hatchet.admin.runWorkflows(workflowRuns);
47
+ const result = yield workflowRunResponse;
48
+ console.log('result', result);
49
+ result.forEach((workflowRun) => __awaiter(this, void 0, void 0, function* () {
50
+ var _a, e_1, _b, _c;
51
+ const stream = yield workflowRun.stream();
52
+ try {
53
+ for (var _d = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield stream_1.next(), _a = stream_1_1.done, !_a; _d = true) {
54
+ _c = stream_1_1.value;
55
+ _d = false;
56
+ const event = _c;
57
+ console.log('event received', event);
58
+ }
59
+ }
60
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
61
+ finally {
62
+ try {
63
+ if (!_d && !_a && (_b = stream_1.return)) yield _b.call(stream_1);
64
+ }
65
+ finally { if (e_1) throw e_1.error; }
66
+ }
67
+ }));
68
+ }
69
+ catch (error) {
70
+ console.log('error', error);
71
+ }
72
+ });
73
+ }
74
+ main();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,93 @@
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 hatchet = sdk_1.default.init();
17
+ const parentWorkflow = {
18
+ id: 'bulk-parent-workflow',
19
+ description: 'simple example for spawning child workflows',
20
+ on: {
21
+ event: 'bulk:fanout:create',
22
+ },
23
+ steps: [
24
+ {
25
+ name: 'parent-spawn',
26
+ timeout: '70s',
27
+ run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
28
+ // Prepare the workflows to spawn
29
+ const workflowRequests = Array.from({ length: 300 }, (_, i) => ({
30
+ workflow: 'child-workflow',
31
+ input: { input: `child-input-${i}` },
32
+ options: { additionalMetadata: { childKey: 'childValue' } },
33
+ }));
34
+ const spawnedWorkflows = yield ctx.spawnWorkflows(workflowRequests);
35
+ const results = yield Promise.all(spawnedWorkflows.map((workflowRef) => workflowRef.result().then((result) => {
36
+ ctx.log('spawned workflow result:');
37
+ return result;
38
+ })));
39
+ console.log('spawned workflow results:', results);
40
+ console.log('number of spawned workflows:', results.length);
41
+ return { spawned: results.length };
42
+ }),
43
+ },
44
+ ],
45
+ };
46
+ const childWorkflow = {
47
+ id: 'child-workflow',
48
+ description: 'simple example for spawning child workflows',
49
+ on: {
50
+ event: 'child:create',
51
+ },
52
+ steps: [
53
+ {
54
+ name: 'child-work',
55
+ run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
56
+ const { input } = ctx.workflowInput();
57
+ // throw new Error('child error');
58
+ return { 'child-output': 'sm' };
59
+ }),
60
+ },
61
+ {
62
+ name: 'child-work2',
63
+ run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
64
+ const { input } = ctx.workflowInput();
65
+ // Perform CPU-bound work
66
+ // throw new Error('child error');
67
+ console.log('child workflow input:', input);
68
+ // Generate a large amount of garbage data
69
+ const garbageData = 'garbage'; // Print a snippet of the garbage data
70
+ return { 'child-output': garbageData };
71
+ }),
72
+ },
73
+ {
74
+ name: 'child-work3',
75
+ parents: ['child-work'],
76
+ run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
77
+ const { input } = ctx.workflowInput();
78
+ // throw new Error('child error');
79
+ const garbageData = 'child garbage';
80
+ return { 'child-output': garbageData };
81
+ }),
82
+ },
83
+ ],
84
+ };
85
+ function main() {
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ const worker = yield hatchet.worker('fanout-worker', { maxRuns: 1000 });
88
+ yield worker.registerWorkflow(parentWorkflow);
89
+ yield worker.registerWorkflow(childWorkflow);
90
+ worker.start();
91
+ });
92
+ }
93
+ main();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,63 @@
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 __asyncValues = (this && this.__asyncValues) || function (o) {
12
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
+ var m = o[Symbol.asyncIterator], i;
14
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
15
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
16
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
17
+ };
18
+ var __importDefault = (this && this.__importDefault) || function (mod) {
19
+ return (mod && mod.__esModule) ? mod : { "default": mod };
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ const sdk_1 = __importDefault(require("../sdk"));
23
+ const hatchet = sdk_1.default.init();
24
+ function main() {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const workflowRuns = [];
27
+ for (let i = 0; i < 100; i += 1) {
28
+ workflowRuns.push({
29
+ workflowName: 'simple-workflow',
30
+ input: {},
31
+ options: {
32
+ additionalMetadata: {
33
+ key: 'value',
34
+ dedupe: 'key',
35
+ },
36
+ },
37
+ });
38
+ }
39
+ const workflowRunResponse = hatchet.admin.runWorkflows(workflowRuns);
40
+ const result = yield workflowRunResponse;
41
+ console.log('result', result);
42
+ result.forEach((workflowRun) => __awaiter(this, void 0, void 0, function* () {
43
+ var _a, e_1, _b, _c;
44
+ const stream = yield workflowRun.stream();
45
+ try {
46
+ for (var _d = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield stream_1.next(), _a = stream_1_1.done, !_a; _d = true) {
47
+ _c = stream_1_1.value;
48
+ _d = false;
49
+ const event = _c;
50
+ console.log('event received', event);
51
+ }
52
+ }
53
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
54
+ finally {
55
+ try {
56
+ if (!_d && !_a && (_b = stream_1.return)) yield _b.call(stream_1);
57
+ }
58
+ finally { if (e_1) throw e_1.error; }
59
+ }
60
+ }));
61
+ });
62
+ }
63
+ main();
@@ -23,10 +23,25 @@ const workflow = {
23
23
  },
24
24
  steps: [
25
25
  {
26
- name: 'step1',
26
+ name: 'dynamic',
27
+ rate_limits: [
28
+ {
29
+ dynamicKey: 'input.group',
30
+ units: 1,
31
+ limit: 10,
32
+ duration: workflows_1.RateLimitDuration.DAY,
33
+ },
34
+ ],
35
+ run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
36
+ console.log('starting step1 with the following input and a dynamic rate limit', ctx.workflowInput());
37
+ return { step1: 'step1 results!' };
38
+ }),
39
+ },
40
+ {
41
+ name: 'static',
27
42
  rate_limits: [{ key: 'test-limit', units: 1 }],
28
43
  run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
29
- console.log('starting step1 with the following input', ctx.workflowInput());
44
+ console.log('starting step1 with the following input and a static rate limit', ctx.workflowInput());
30
45
  return { step1: 'step1 results!' };
31
46
  }),
32
47
  },