@hatchet-dev/typescript-sdk 0.16.0-alpha.4 → 0.17.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.
Files changed (59) hide show
  1. package/clients/dispatcher/dispatcher-client.d.ts +2 -1
  2. package/clients/dispatcher/dispatcher-client.js +10 -1
  3. package/clients/event/event-client.js +13 -8
  4. package/clients/hatchet-client/client-config.d.ts +0 -6
  5. package/clients/hatchet-client/client-config.js +0 -2
  6. package/clients/hatchet-client/features/cron-client.d.ts +79 -0
  7. package/clients/hatchet-client/features/cron-client.js +127 -0
  8. package/clients/hatchet-client/features/schedule-client.d.ts +76 -0
  9. package/clients/hatchet-client/features/schedule-client.js +120 -0
  10. package/clients/hatchet-client/hatchet-client.d.ts +4 -2
  11. package/clients/hatchet-client/hatchet-client.js +6 -25
  12. package/clients/listener/child-listener-client.js +16 -13
  13. package/clients/rest/api.d.ts +0 -3
  14. package/clients/rest/api.js +0 -10
  15. package/clients/rest/generated/Api.d.ts +152 -2
  16. package/clients/rest/generated/Api.js +81 -1
  17. package/clients/rest/generated/data-contracts.d.ts +86 -0
  18. package/clients/rest/generated/data-contracts.js +27 -1
  19. package/clients/rest/index.d.ts +2 -2
  20. package/clients/rest/index.js +21 -10
  21. package/clients/worker/handler.js +16 -11
  22. package/clients/worker/worker.d.ts +2 -10
  23. package/clients/worker/worker.js +24 -38
  24. package/examples/crons/cron-worker.d.ts +2 -0
  25. package/examples/crons/cron-worker.js +48 -0
  26. package/examples/crons/programatic-crons.js +55 -0
  27. package/examples/on-failure.js +15 -10
  28. package/examples/retries-with-backoff.d.ts +1 -0
  29. package/examples/{managed-worker.js → retries-with-backoff.js} +24 -33
  30. package/examples/scheduled-runs/programatic-schedules.d.ts +1 -0
  31. package/examples/scheduled-runs/programatic-schedules.js +54 -0
  32. package/examples/simple-worker.d.ts +2 -1
  33. package/examples/simple-worker.js +6 -3
  34. package/package.json +8 -8
  35. package/protoc/dispatcher/dispatcher.js +1 -1
  36. package/protoc/events/events.js +1 -1
  37. package/protoc/google/protobuf/timestamp.js +1 -1
  38. package/protoc/google/protobuf/wrappers.js +17 -7
  39. package/protoc/workflows/workflows.d.ts +13 -0
  40. package/protoc/workflows/workflows.js +160 -7
  41. package/step.d.ts +17 -121
  42. package/step.js +23 -9
  43. package/util/config-loader/config-loader.js +18 -26
  44. package/util/retrier.js +8 -3
  45. package/version.d.ts +1 -0
  46. package/version.js +4 -0
  47. package/workflow.d.ts +67 -459
  48. package/workflow.js +17 -7
  49. package/clients/rest/generated/cloud/Api.d.ts +0 -377
  50. package/clients/rest/generated/cloud/Api.js +0 -326
  51. package/clients/rest/generated/cloud/data-contracts.d.ts +0 -468
  52. package/clients/rest/generated/cloud/data-contracts.js +0 -68
  53. package/clients/rest/generated/cloud/http-client.d.ts +0 -41
  54. package/clients/rest/generated/cloud/http-client.js +0 -102
  55. package/clients/worker/compute/compute-config.d.ts +0 -156
  56. package/clients/worker/compute/compute-config.js +0 -82
  57. package/clients/worker/compute/managed-compute.d.ts +0 -15
  58. package/clients/worker/compute/managed-compute.js +0 -104
  59. /package/examples/{managed-worker.d.ts → crons/programatic-crons.d.ts} +0 -0
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
- // protoc-gen-ts_proto v2.2.4
4
+ // protoc-gen-ts_proto v2.5.0
5
5
  // protoc v3.19.1
6
6
  // source: workflows/workflows.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.WorkflowServiceDefinition = exports.PutRateLimitResponse = exports.PutRateLimitRequest = exports.TriggerWorkflowResponse = exports.TriggerWorkflowRequest = exports.BulkTriggerWorkflowResponse = exports.BulkTriggerWorkflowRequest = exports.WorkflowTriggerCronRef = exports.WorkflowTriggerEventRef = exports.WorkflowVersion = exports.ScheduleWorkflowRequest = exports.ListWorkflowsRequest = exports.CreateStepRateLimit = exports.CreateWorkflowStepOpts_WorkerLabelsEntry = exports.CreateWorkflowStepOpts = exports.DesiredWorkerLabels = exports.CreateWorkflowJobOpts = exports.WorkflowConcurrencyOpts = exports.CreateWorkflowVersionOpts = exports.PutWorkflowRequest = exports.RateLimitDuration = exports.WorkerLabelComparator = exports.ConcurrencyLimitStrategy = exports.WorkflowKind = exports.StickyStrategy = exports.protobufPackage = void 0;
8
+ exports.WorkflowServiceDefinition = exports.PutRateLimitResponse = exports.PutRateLimitRequest = exports.TriggerWorkflowResponse = exports.TriggerWorkflowRequest = exports.BulkTriggerWorkflowResponse = exports.BulkTriggerWorkflowRequest = exports.WorkflowTriggerCronRef = exports.WorkflowTriggerEventRef = exports.WorkflowVersion = exports.ScheduledWorkflow = exports.ScheduleWorkflowRequest = exports.ListWorkflowsRequest = exports.CreateStepRateLimit = exports.CreateWorkflowStepOpts_WorkerLabelsEntry = exports.CreateWorkflowStepOpts = exports.DesiredWorkerLabels = exports.CreateWorkflowJobOpts = exports.WorkflowConcurrencyOpts = exports.CreateWorkflowVersionOpts = exports.PutWorkflowRequest = exports.RateLimitDuration = exports.WorkerLabelComparator = exports.ConcurrencyLimitStrategy = exports.WorkflowKind = exports.StickyStrategy = exports.protobufPackage = void 0;
9
9
  exports.stickyStrategyFromJSON = stickyStrategyFromJSON;
10
10
  exports.stickyStrategyToJSON = stickyStrategyToJSON;
11
11
  exports.workflowKindFromJSON = workflowKindFromJSON;
@@ -911,6 +911,8 @@ function createBaseCreateWorkflowStepOpts() {
911
911
  retries: 0,
912
912
  rateLimits: [],
913
913
  workerLabels: {},
914
+ backoffFactor: undefined,
915
+ backoffMaxSeconds: undefined,
914
916
  };
915
917
  }
916
918
  exports.CreateWorkflowStepOpts = {
@@ -942,6 +944,12 @@ exports.CreateWorkflowStepOpts = {
942
944
  Object.entries(message.workerLabels).forEach(([key, value]) => {
943
945
  exports.CreateWorkflowStepOpts_WorkerLabelsEntry.encode({ key: key, value }, writer.uint32(74).fork()).join();
944
946
  });
947
+ if (message.backoffFactor !== undefined) {
948
+ writer.uint32(85).float(message.backoffFactor);
949
+ }
950
+ if (message.backoffMaxSeconds !== undefined) {
951
+ writer.uint32(88).int32(message.backoffMaxSeconds);
952
+ }
945
953
  return writer;
946
954
  },
947
955
  decode(input, length) {
@@ -1017,6 +1025,20 @@ exports.CreateWorkflowStepOpts = {
1017
1025
  }
1018
1026
  continue;
1019
1027
  }
1028
+ case 10: {
1029
+ if (tag !== 85) {
1030
+ break;
1031
+ }
1032
+ message.backoffFactor = reader.float();
1033
+ continue;
1034
+ }
1035
+ case 11: {
1036
+ if (tag !== 88) {
1037
+ break;
1038
+ }
1039
+ message.backoffMaxSeconds = reader.int32();
1040
+ continue;
1041
+ }
1020
1042
  }
1021
1043
  if ((tag & 7) === 4 || tag === 0) {
1022
1044
  break;
@@ -1045,6 +1067,12 @@ exports.CreateWorkflowStepOpts = {
1045
1067
  return acc;
1046
1068
  }, {})
1047
1069
  : {},
1070
+ backoffFactor: isSet(object.backoffFactor)
1071
+ ? globalThis.Number(object.backoffFactor)
1072
+ : undefined,
1073
+ backoffMaxSeconds: isSet(object.backoffMaxSeconds)
1074
+ ? globalThis.Number(object.backoffMaxSeconds)
1075
+ : undefined,
1048
1076
  };
1049
1077
  },
1050
1078
  toJSON(message) {
@@ -1083,13 +1111,19 @@ exports.CreateWorkflowStepOpts = {
1083
1111
  });
1084
1112
  }
1085
1113
  }
1114
+ if (message.backoffFactor !== undefined) {
1115
+ obj.backoffFactor = message.backoffFactor;
1116
+ }
1117
+ if (message.backoffMaxSeconds !== undefined) {
1118
+ obj.backoffMaxSeconds = Math.round(message.backoffMaxSeconds);
1119
+ }
1086
1120
  return obj;
1087
1121
  },
1088
1122
  create(base) {
1089
1123
  return exports.CreateWorkflowStepOpts.fromPartial(base !== null && base !== void 0 ? base : {});
1090
1124
  },
1091
1125
  fromPartial(object) {
1092
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1126
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
1093
1127
  const message = createBaseCreateWorkflowStepOpts();
1094
1128
  message.readableId = (_a = object.readableId) !== null && _a !== void 0 ? _a : '';
1095
1129
  message.action = (_b = object.action) !== null && _b !== void 0 ? _b : '';
@@ -1105,6 +1139,8 @@ exports.CreateWorkflowStepOpts = {
1105
1139
  }
1106
1140
  return acc;
1107
1141
  }, {});
1142
+ message.backoffFactor = (_k = object.backoffFactor) !== null && _k !== void 0 ? _k : undefined;
1143
+ message.backoffMaxSeconds = (_l = object.backoffMaxSeconds) !== null && _l !== void 0 ? _l : undefined;
1108
1144
  return message;
1109
1145
  },
1110
1146
  };
@@ -1364,6 +1400,7 @@ function createBaseScheduleWorkflowRequest() {
1364
1400
  parentStepRunId: undefined,
1365
1401
  childIndex: undefined,
1366
1402
  childKey: undefined,
1403
+ additionalMetadata: undefined,
1367
1404
  };
1368
1405
  }
1369
1406
  exports.ScheduleWorkflowRequest = {
@@ -1389,6 +1426,9 @@ exports.ScheduleWorkflowRequest = {
1389
1426
  if (message.childKey !== undefined) {
1390
1427
  writer.uint32(58).string(message.childKey);
1391
1428
  }
1429
+ if (message.additionalMetadata !== undefined) {
1430
+ writer.uint32(66).string(message.additionalMetadata);
1431
+ }
1392
1432
  return writer;
1393
1433
  },
1394
1434
  decode(input, length) {
@@ -1447,6 +1487,13 @@ exports.ScheduleWorkflowRequest = {
1447
1487
  message.childKey = reader.string();
1448
1488
  continue;
1449
1489
  }
1490
+ case 8: {
1491
+ if (tag !== 66) {
1492
+ break;
1493
+ }
1494
+ message.additionalMetadata = reader.string();
1495
+ continue;
1496
+ }
1450
1497
  }
1451
1498
  if ((tag & 7) === 4 || tag === 0) {
1452
1499
  break;
@@ -1468,6 +1515,9 @@ exports.ScheduleWorkflowRequest = {
1468
1515
  : undefined,
1469
1516
  childIndex: isSet(object.childIndex) ? globalThis.Number(object.childIndex) : undefined,
1470
1517
  childKey: isSet(object.childKey) ? globalThis.String(object.childKey) : undefined,
1518
+ additionalMetadata: isSet(object.additionalMetadata)
1519
+ ? globalThis.String(object.additionalMetadata)
1520
+ : undefined,
1471
1521
  };
1472
1522
  },
1473
1523
  toJSON(message) {
@@ -1494,13 +1544,16 @@ exports.ScheduleWorkflowRequest = {
1494
1544
  if (message.childKey !== undefined) {
1495
1545
  obj.childKey = message.childKey;
1496
1546
  }
1547
+ if (message.additionalMetadata !== undefined) {
1548
+ obj.additionalMetadata = message.additionalMetadata;
1549
+ }
1497
1550
  return obj;
1498
1551
  },
1499
1552
  create(base) {
1500
1553
  return exports.ScheduleWorkflowRequest.fromPartial(base !== null && base !== void 0 ? base : {});
1501
1554
  },
1502
1555
  fromPartial(object) {
1503
- var _a, _b, _c, _d, _e, _f, _g;
1556
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1504
1557
  const message = createBaseScheduleWorkflowRequest();
1505
1558
  message.name = (_a = object.name) !== null && _a !== void 0 ? _a : '';
1506
1559
  message.schedules = ((_b = object.schedules) === null || _b === void 0 ? void 0 : _b.map((e) => e)) || [];
@@ -1509,6 +1562,76 @@ exports.ScheduleWorkflowRequest = {
1509
1562
  message.parentStepRunId = (_e = object.parentStepRunId) !== null && _e !== void 0 ? _e : undefined;
1510
1563
  message.childIndex = (_f = object.childIndex) !== null && _f !== void 0 ? _f : undefined;
1511
1564
  message.childKey = (_g = object.childKey) !== null && _g !== void 0 ? _g : undefined;
1565
+ message.additionalMetadata = (_h = object.additionalMetadata) !== null && _h !== void 0 ? _h : undefined;
1566
+ return message;
1567
+ },
1568
+ };
1569
+ function createBaseScheduledWorkflow() {
1570
+ return { id: '', triggerAt: undefined };
1571
+ }
1572
+ exports.ScheduledWorkflow = {
1573
+ encode(message, writer = new wire_1.BinaryWriter()) {
1574
+ if (message.id !== '') {
1575
+ writer.uint32(10).string(message.id);
1576
+ }
1577
+ if (message.triggerAt !== undefined) {
1578
+ timestamp_1.Timestamp.encode(toTimestamp(message.triggerAt), writer.uint32(18).fork()).join();
1579
+ }
1580
+ return writer;
1581
+ },
1582
+ decode(input, length) {
1583
+ const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
1584
+ let end = length === undefined ? reader.len : reader.pos + length;
1585
+ const message = createBaseScheduledWorkflow();
1586
+ while (reader.pos < end) {
1587
+ const tag = reader.uint32();
1588
+ switch (tag >>> 3) {
1589
+ case 1: {
1590
+ if (tag !== 10) {
1591
+ break;
1592
+ }
1593
+ message.id = reader.string();
1594
+ continue;
1595
+ }
1596
+ case 2: {
1597
+ if (tag !== 18) {
1598
+ break;
1599
+ }
1600
+ message.triggerAt = fromTimestamp(timestamp_1.Timestamp.decode(reader, reader.uint32()));
1601
+ continue;
1602
+ }
1603
+ }
1604
+ if ((tag & 7) === 4 || tag === 0) {
1605
+ break;
1606
+ }
1607
+ reader.skip(tag & 7);
1608
+ }
1609
+ return message;
1610
+ },
1611
+ fromJSON(object) {
1612
+ return {
1613
+ id: isSet(object.id) ? globalThis.String(object.id) : '',
1614
+ triggerAt: isSet(object.triggerAt) ? fromJsonTimestamp(object.triggerAt) : undefined,
1615
+ };
1616
+ },
1617
+ toJSON(message) {
1618
+ const obj = {};
1619
+ if (message.id !== '') {
1620
+ obj.id = message.id;
1621
+ }
1622
+ if (message.triggerAt !== undefined) {
1623
+ obj.triggerAt = message.triggerAt.toISOString();
1624
+ }
1625
+ return obj;
1626
+ },
1627
+ create(base) {
1628
+ return exports.ScheduledWorkflow.fromPartial(base !== null && base !== void 0 ? base : {});
1629
+ },
1630
+ fromPartial(object) {
1631
+ var _a, _b;
1632
+ const message = createBaseScheduledWorkflow();
1633
+ message.id = (_a = object.id) !== null && _a !== void 0 ? _a : '';
1634
+ message.triggerAt = (_b = object.triggerAt) !== null && _b !== void 0 ? _b : undefined;
1512
1635
  return message;
1513
1636
  },
1514
1637
  };
@@ -1520,6 +1643,7 @@ function createBaseWorkflowVersion() {
1520
1643
  version: '',
1521
1644
  order: 0,
1522
1645
  workflowId: '',
1646
+ scheduledWorkflows: [],
1523
1647
  };
1524
1648
  }
1525
1649
  exports.WorkflowVersion = {
@@ -1537,11 +1661,14 @@ exports.WorkflowVersion = {
1537
1661
  writer.uint32(42).string(message.version);
1538
1662
  }
1539
1663
  if (message.order !== 0) {
1540
- writer.uint32(48).int32(message.order);
1664
+ writer.uint32(48).int64(message.order);
1541
1665
  }
1542
1666
  if (message.workflowId !== '') {
1543
1667
  writer.uint32(58).string(message.workflowId);
1544
1668
  }
1669
+ for (const v of message.scheduledWorkflows) {
1670
+ exports.ScheduledWorkflow.encode(v, writer.uint32(66).fork()).join();
1671
+ }
1545
1672
  return writer;
1546
1673
  },
1547
1674
  decode(input, length) {
@@ -1583,7 +1710,7 @@ exports.WorkflowVersion = {
1583
1710
  if (tag !== 48) {
1584
1711
  break;
1585
1712
  }
1586
- message.order = reader.int32();
1713
+ message.order = longToNumber(reader.int64());
1587
1714
  continue;
1588
1715
  }
1589
1716
  case 7: {
@@ -1593,6 +1720,13 @@ exports.WorkflowVersion = {
1593
1720
  message.workflowId = reader.string();
1594
1721
  continue;
1595
1722
  }
1723
+ case 8: {
1724
+ if (tag !== 66) {
1725
+ break;
1726
+ }
1727
+ message.scheduledWorkflows.push(exports.ScheduledWorkflow.decode(reader, reader.uint32()));
1728
+ continue;
1729
+ }
1596
1730
  }
1597
1731
  if ((tag & 7) === 4 || tag === 0) {
1598
1732
  break;
@@ -1609,9 +1743,13 @@ exports.WorkflowVersion = {
1609
1743
  version: isSet(object.version) ? globalThis.String(object.version) : '',
1610
1744
  order: isSet(object.order) ? globalThis.Number(object.order) : 0,
1611
1745
  workflowId: isSet(object.workflowId) ? globalThis.String(object.workflowId) : '',
1746
+ scheduledWorkflows: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.scheduledWorkflows)
1747
+ ? object.scheduledWorkflows.map((e) => exports.ScheduledWorkflow.fromJSON(e))
1748
+ : [],
1612
1749
  };
1613
1750
  },
1614
1751
  toJSON(message) {
1752
+ var _a;
1615
1753
  const obj = {};
1616
1754
  if (message.id !== '') {
1617
1755
  obj.id = message.id;
@@ -1631,13 +1769,16 @@ exports.WorkflowVersion = {
1631
1769
  if (message.workflowId !== '') {
1632
1770
  obj.workflowId = message.workflowId;
1633
1771
  }
1772
+ if ((_a = message.scheduledWorkflows) === null || _a === void 0 ? void 0 : _a.length) {
1773
+ obj.scheduledWorkflows = message.scheduledWorkflows.map((e) => exports.ScheduledWorkflow.toJSON(e));
1774
+ }
1634
1775
  return obj;
1635
1776
  },
1636
1777
  create(base) {
1637
1778
  return exports.WorkflowVersion.fromPartial(base !== null && base !== void 0 ? base : {});
1638
1779
  },
1639
1780
  fromPartial(object) {
1640
- var _a, _b, _c, _d, _e, _f;
1781
+ var _a, _b, _c, _d, _e, _f, _g;
1641
1782
  const message = createBaseWorkflowVersion();
1642
1783
  message.id = (_a = object.id) !== null && _a !== void 0 ? _a : '';
1643
1784
  message.createdAt = (_b = object.createdAt) !== null && _b !== void 0 ? _b : undefined;
@@ -1645,6 +1786,8 @@ exports.WorkflowVersion = {
1645
1786
  message.version = (_d = object.version) !== null && _d !== void 0 ? _d : '';
1646
1787
  message.order = (_e = object.order) !== null && _e !== void 0 ? _e : 0;
1647
1788
  message.workflowId = (_f = object.workflowId) !== null && _f !== void 0 ? _f : '';
1789
+ message.scheduledWorkflows =
1790
+ ((_g = object.scheduledWorkflows) === null || _g === void 0 ? void 0 : _g.map((e) => exports.ScheduledWorkflow.fromPartial(e))) || [];
1648
1791
  return message;
1649
1792
  },
1650
1793
  };
@@ -2332,6 +2475,16 @@ function fromJsonTimestamp(o) {
2332
2475
  return fromTimestamp(timestamp_1.Timestamp.fromJSON(o));
2333
2476
  }
2334
2477
  }
2478
+ function longToNumber(int64) {
2479
+ const num = globalThis.Number(int64.toString());
2480
+ if (num > globalThis.Number.MAX_SAFE_INTEGER) {
2481
+ throw new globalThis.Error('Value is larger than Number.MAX_SAFE_INTEGER');
2482
+ }
2483
+ if (num < globalThis.Number.MIN_SAFE_INTEGER) {
2484
+ throw new globalThis.Error('Value is smaller than Number.MIN_SAFE_INTEGER');
2485
+ }
2486
+ return num;
2487
+ }
2335
2488
  function isObject(value) {
2336
2489
  return typeof value === 'object' && value !== null;
2337
2490
  }
package/step.d.ts CHANGED
@@ -89,109 +89,21 @@ export declare const CreateStepSchema: z.ZodObject<{
89
89
  comparator?: WorkerLabelComparator | undefined;
90
90
  weight?: number | undefined;
91
91
  }>]>>>>>;
92
- compute: z.ZodOptional<z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
93
- pool: z.ZodOptional<z.ZodDefault<z.ZodString>>;
94
- numReplicas: z.ZodDefault<z.ZodNumber>;
95
- regions: z.ZodOptional<z.ZodArray<z.ZodNativeEnum<typeof import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion>, "many">>;
96
- cpus: z.ZodNumber;
97
- }, {
98
- cpuKind: z.ZodLiteral<"shared">;
99
- memoryMb: z.ZodEffects<z.ZodNumber, number, number>;
100
- }>, "strip", z.ZodTypeAny, {
101
- numReplicas: number;
102
- cpus: number;
103
- cpuKind: "shared";
104
- memoryMb: number;
105
- pool?: string | undefined;
106
- regions?: import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion[] | undefined;
107
- }, {
108
- cpus: number;
109
- cpuKind: "shared";
110
- memoryMb: number;
111
- pool?: string | undefined;
112
- numReplicas?: number | undefined;
113
- regions?: import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion[] | undefined;
114
- }>, z.ZodObject<z.objectUtil.extendShape<{
115
- pool: z.ZodOptional<z.ZodDefault<z.ZodString>>;
116
- numReplicas: z.ZodDefault<z.ZodNumber>;
117
- regions: z.ZodOptional<z.ZodArray<z.ZodNativeEnum<typeof import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion>, "many">>;
118
- cpus: z.ZodNumber;
119
- }, {
120
- cpuKind: z.ZodLiteral<"performance">;
121
- memoryMb: z.ZodEffects<z.ZodNumber, number, number>;
122
- }>, "strip", z.ZodTypeAny, {
123
- numReplicas: number;
124
- cpus: number;
125
- cpuKind: "performance";
126
- memoryMb: number;
127
- pool?: string | undefined;
128
- regions?: import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion[] | undefined;
129
- }, {
130
- cpus: number;
131
- cpuKind: "performance";
132
- memoryMb: number;
133
- pool?: string | undefined;
134
- numReplicas?: number | undefined;
135
- regions?: import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion[] | undefined;
136
- }>, z.ZodObject<z.objectUtil.extendShape<{
137
- pool: z.ZodOptional<z.ZodDefault<z.ZodString>>;
138
- numReplicas: z.ZodDefault<z.ZodNumber>;
139
- regions: z.ZodOptional<z.ZodArray<z.ZodNativeEnum<typeof import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion>, "many">>;
140
- cpus: z.ZodNumber;
141
- }, {
142
- cpuKind: z.ZodLiteral<"shared">;
143
- gpuKind: z.ZodEnum<["a10", "l40s", "a100-40gb", "a100-80gb"]>;
144
- gpus: z.ZodNumber;
145
- regions: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodNativeEnum<typeof import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion>, "many">, import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion[], import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion[]>>;
146
- memoryMb: z.ZodEffects<z.ZodNumber, number, number>;
147
- }>, "strip", z.ZodTypeAny, {
148
- numReplicas: number;
149
- cpus: number;
150
- cpuKind: "shared";
151
- memoryMb: number;
152
- gpuKind: "a10" | "l40s" | "a100-40gb" | "a100-80gb";
153
- gpus: number;
154
- pool?: string | undefined;
155
- regions?: import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion[] | undefined;
92
+ backoff: z.ZodOptional<z.ZodObject<{
93
+ factor: z.ZodOptional<z.ZodNumber>;
94
+ maxSeconds: z.ZodOptional<z.ZodNumber>;
95
+ }, "strip", z.ZodTypeAny, {
96
+ factor?: number | undefined;
97
+ maxSeconds?: number | undefined;
156
98
  }, {
157
- cpus: number;
158
- cpuKind: "shared";
159
- memoryMb: number;
160
- gpuKind: "a10" | "l40s" | "a100-40gb" | "a100-80gb";
161
- gpus: number;
162
- pool?: string | undefined;
163
- numReplicas?: number | undefined;
164
- regions?: import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion[] | undefined;
165
- }>]>>;
99
+ factor?: number | undefined;
100
+ maxSeconds?: number | undefined;
101
+ }>>;
166
102
  }, "strip", z.ZodTypeAny, {
167
103
  name: string;
168
104
  timeout?: string | undefined;
169
105
  parents?: string[] | undefined;
170
106
  retries?: number | undefined;
171
- compute?: {
172
- numReplicas: number;
173
- cpus: number;
174
- cpuKind: "shared";
175
- memoryMb: number;
176
- pool?: string | undefined;
177
- regions?: import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion[] | undefined;
178
- } | {
179
- numReplicas: number;
180
- cpus: number;
181
- cpuKind: "performance";
182
- memoryMb: number;
183
- pool?: string | undefined;
184
- regions?: import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion[] | undefined;
185
- } | {
186
- numReplicas: number;
187
- cpus: number;
188
- cpuKind: "shared";
189
- memoryMb: number;
190
- gpuKind: "a10" | "l40s" | "a100-40gb" | "a100-80gb";
191
- gpus: number;
192
- pool?: string | undefined;
193
- regions?: import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion[] | undefined;
194
- } | undefined;
195
107
  rate_limits?: {
196
108
  units: string | number;
197
109
  key?: string | undefined;
@@ -206,35 +118,15 @@ export declare const CreateStepSchema: z.ZodObject<{
206
118
  comparator?: WorkerLabelComparator | undefined;
207
119
  weight?: number | undefined;
208
120
  } | undefined> | undefined;
121
+ backoff?: {
122
+ factor?: number | undefined;
123
+ maxSeconds?: number | undefined;
124
+ } | undefined;
209
125
  }, {
210
126
  name: string;
211
127
  timeout?: string | undefined;
212
128
  parents?: string[] | undefined;
213
129
  retries?: number | undefined;
214
- compute?: {
215
- cpus: number;
216
- cpuKind: "shared";
217
- memoryMb: number;
218
- pool?: string | undefined;
219
- numReplicas?: number | undefined;
220
- regions?: import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion[] | undefined;
221
- } | {
222
- cpus: number;
223
- cpuKind: "performance";
224
- memoryMb: number;
225
- pool?: string | undefined;
226
- numReplicas?: number | undefined;
227
- regions?: import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion[] | undefined;
228
- } | {
229
- cpus: number;
230
- cpuKind: "shared";
231
- memoryMb: number;
232
- gpuKind: "a10" | "l40s" | "a100-40gb" | "a100-80gb";
233
- gpus: number;
234
- pool?: string | undefined;
235
- numReplicas?: number | undefined;
236
- regions?: import("./clients/rest/generated/cloud/data-contracts").ManagedWorkerRegion[] | undefined;
237
- } | undefined;
238
130
  rate_limits?: {
239
131
  units: string | number;
240
132
  key?: string | undefined;
@@ -249,6 +141,10 @@ export declare const CreateStepSchema: z.ZodObject<{
249
141
  comparator?: WorkerLabelComparator | undefined;
250
142
  weight?: number | undefined;
251
143
  } | undefined> | undefined;
144
+ backoff?: {
145
+ factor?: number | undefined;
146
+ maxSeconds?: number | undefined;
147
+ } | undefined;
252
148
  }>;
253
149
  export type JsonObject = {
254
150
  [Key in string]: JsonValue;
package/step.js CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -44,7 +54,6 @@ const workflow_1 = require("./workflow");
44
54
  const logger_1 = require("./util/logger");
45
55
  const parse_1 = require("./util/parse");
46
56
  const workflows_1 = require("./protoc/workflows");
47
- const compute_config_1 = require("./clients/worker/compute/compute-config");
48
57
  exports.CreateRateLimitSchema = z.object({
49
58
  key: z.string().optional(),
50
59
  staticKey: z.string().optional(),
@@ -75,7 +84,12 @@ exports.CreateStepSchema = z.object({
75
84
  retries: z.number().optional(),
76
85
  rate_limits: z.array(exports.CreateRateLimitSchema).optional(),
77
86
  worker_labels: z.record(z.lazy(() => exports.DesiredWorkerLabelSchema)).optional(),
78
- compute: compute_config_1.ComputeSchema.optional(),
87
+ backoff: z
88
+ .object({
89
+ factor: z.number().optional(),
90
+ maxSeconds: z.number().optional(),
91
+ })
92
+ .optional(),
79
93
  });
80
94
  class ContextWorker {
81
95
  constructor(worker) {
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.ConfigLoader = void 0;
27
37
  const yaml_1 = require("yaml");
@@ -66,22 +76,6 @@ class ConfigLoader {
66
76
  apiUrl = (_z = (_y = override === null || override === void 0 ? void 0 : override.api_url) !== null && _y !== void 0 ? _y : yaml === null || yaml === void 0 ? void 0 : yaml.api_url) !== null && _z !== void 0 ? _z : this.env('HATCHET_CLIENT_API_URL');
67
77
  }
68
78
  const namespace = (_1 = (_0 = override === null || override === void 0 ? void 0 : override.namespace) !== null && _0 !== void 0 ? _0 : yaml === null || yaml === void 0 ? void 0 : yaml.namespace) !== null && _1 !== void 0 ? _1 : this.env('HATCHET_CLIENT_NAMESPACE');
69
- let rawRunnableActions;
70
- if (override === null || override === void 0 ? void 0 : override.runnable_actions) {
71
- rawRunnableActions = override.runnable_actions;
72
- }
73
- else if (yaml === null || yaml === void 0 ? void 0 : yaml.runnable_actions) {
74
- rawRunnableActions = yaml.runnable_actions;
75
- }
76
- else {
77
- const envActions = this.env('HATCHET_CLOUD_ACTIONS');
78
- if (envActions) {
79
- rawRunnableActions = envActions.split(',');
80
- }
81
- }
82
- const registerId = this.env('HATCHET_CLOUD_REGISTER_ID');
83
- const namespacePrefix = namespace ? `${namespace}_`.toLowerCase() : '';
84
- const runnableActions = rawRunnableActions === null || rawRunnableActions === void 0 ? void 0 : rawRunnableActions.map((action) => namespacePrefix + action.trim());
85
79
  return {
86
80
  token: (_3 = (_2 = override === null || override === void 0 ? void 0 : override.token) !== null && _2 !== void 0 ? _2 : yaml === null || yaml === void 0 ? void 0 : yaml.token) !== null && _3 !== void 0 ? _3 : this.env('HATCHET_CLIENT_TOKEN'),
87
81
  host_port: grpcBroadcastAddress,
@@ -89,9 +83,7 @@ class ConfigLoader {
89
83
  tls_config: tlsConfig,
90
84
  log_level: (_6 = (_5 = (_4 = override === null || override === void 0 ? void 0 : override.log_level) !== null && _4 !== void 0 ? _4 : yaml === null || yaml === void 0 ? void 0 : yaml.log_level) !== null && _5 !== void 0 ? _5 : this.env('HATCHET_CLIENT_LOG_LEVEL')) !== null && _6 !== void 0 ? _6 : 'INFO',
91
85
  tenant_id: tenantId,
92
- namespace: namespacePrefix,
93
- runnable_actions: runnableActions,
94
- cloud_register_id: registerId,
86
+ namespace: namespace ? `${namespace}_`.toLowerCase() : '',
95
87
  };
96
88
  }
97
89
  static get default_yaml_config_path() {
package/util/retrier.js CHANGED
@@ -14,8 +14,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.retrier = retrier;
16
16
  const sleep_1 = __importDefault(require("./sleep"));
17
- const DEFAULT_RETRY_INTERVAL = 5; // seconds
18
- const DEFAULT_RETRY_COUNT = 5;
17
+ const DEFAULT_RETRY_INTERVAL = 1; // seconds
18
+ const DEFAULT_RETRY_COUNT = 8;
19
+ const MAX_JITTER = 400; // milliseconds
19
20
  function retrier(fn_1, logger_1) {
20
21
  return __awaiter(this, arguments, void 0, function* (fn, logger, retries = DEFAULT_RETRY_COUNT, interval = DEFAULT_RETRY_INTERVAL) {
21
22
  let lastError;
@@ -27,7 +28,11 @@ function retrier(fn_1, logger_1) {
27
28
  catch (e) {
28
29
  lastError = e;
29
30
  logger.error(`Error: ${e.message}`);
30
- yield (0, sleep_1.default)(interval * 1000);
31
+ // Calculate exponential backoff with random jitter
32
+ const exponentialDelay = interval * 2 ** i * 1000;
33
+ const jitter = Math.random() * MAX_JITTER;
34
+ const totalDelay = exponentialDelay + jitter;
35
+ yield (0, sleep_1.default)(totalDelay);
31
36
  }
32
37
  }
33
38
  throw lastError;
package/version.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const HATCHET_VERSION = "0.17.0";
package/version.js ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HATCHET_VERSION = void 0;
4
+ exports.HATCHET_VERSION = '0.17.0';