@hatchet-dev/typescript-sdk 1.0.0-alpha2 → 1.0.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 (34) hide show
  1. package/clients/worker/worker.js +4 -4
  2. package/package.json +1 -1
  3. package/v1/declaration.d.ts +1 -1
  4. package/v1/examples/landing_page/durable-excution.d.ts +3 -0
  5. package/v1/examples/landing_page/durable-excution.js +40 -0
  6. package/v1/examples/landing_page/event-signaling.d.ts +6 -0
  7. package/v1/examples/landing_page/event-signaling.js +16 -0
  8. package/v1/examples/landing_page/flow-control.d.ts +6 -0
  9. package/v1/examples/landing_page/flow-control.js +26 -0
  10. package/v1/examples/landing_page/queues.d.ts +3 -0
  11. package/v1/examples/landing_page/queues.js +33 -0
  12. package/v1/examples/landing_page/scheduling.d.ts +1 -0
  13. package/v1/examples/landing_page/scheduling.js +12 -0
  14. package/v1/examples/landing_page/task-routing.d.ts +6 -0
  15. package/v1/examples/landing_page/task-routing.js +25 -0
  16. package/v1/examples/on_failure/workflow.d.ts +1 -1
  17. package/v1/examples/on_failure/workflow.js +4 -5
  18. package/v1/examples/retries/run.d.ts +1 -0
  19. package/v1/examples/retries/run.js +29 -0
  20. package/v1/examples/retries/worker.d.ts +1 -0
  21. package/v1/examples/retries/worker.js +24 -0
  22. package/v1/examples/retries/workflow.d.ts +5 -0
  23. package/v1/examples/retries/workflow.js +53 -0
  24. package/v1/examples/sticky/run.d.ts +1 -0
  25. package/v1/examples/sticky/run.js +29 -0
  26. package/v1/examples/sticky/worker.d.ts +1 -0
  27. package/v1/examples/sticky/worker.js +24 -0
  28. package/v1/examples/sticky/workflow.d.ts +7 -0
  29. package/v1/examples/sticky/workflow.js +32 -0
  30. package/v1/examples/with_timeouts/workflow.d.ts +9 -0
  31. package/v1/examples/with_timeouts/workflow.js +62 -0
  32. package/v1/task.d.ts +1 -1
  33. package/version.d.ts +1 -1
  34. package/version.js +1 -1
@@ -138,7 +138,7 @@ class V0Worker {
138
138
  parents: [],
139
139
  retries: onFailure.retries || ((_c = workflow.taskDefaults) === null || _c === void 0 ? void 0 : _c.retries) || 0,
140
140
  rateLimits: (0, step_1.mapRateLimit)(onFailure.rateLimits || ((_d = workflow.taskDefaults) === null || _d === void 0 ? void 0 : _d.rateLimits)),
141
- workerLabels: toPbWorkerLabel(onFailure.workerLabels || ((_e = workflow.taskDefaults) === null || _e === void 0 ? void 0 : _e.workerLabels)),
141
+ workerLabels: toPbWorkerLabel(onFailure.desiredWorkerLabels || ((_e = workflow.taskDefaults) === null || _e === void 0 ? void 0 : _e.workerLabels)),
142
142
  concurrency: [],
143
143
  backoffFactor: ((_f = onFailure.backoff) === null || _f === void 0 ? void 0 : _f.factor) || ((_h = (_g = workflow.taskDefaults) === null || _g === void 0 ? void 0 : _g.backoff) === null || _h === void 0 ? void 0 : _h.factor),
144
144
  backoffMaxSeconds: ((_j = onFailure.backoff) === null || _j === void 0 ? void 0 : _j.maxSeconds) || ((_l = (_k = workflow.taskDefaults) === null || _k === void 0 ? void 0 : _k.backoff) === null || _l === void 0 ? void 0 : _l.maxSeconds),
@@ -154,7 +154,7 @@ class V0Worker {
154
154
  parents,
155
155
  retries: 0,
156
156
  rateLimits: [],
157
- workerLabels: {},
157
+ desiredWorkerLabels: {},
158
158
  concurrency: [],
159
159
  };
160
160
  }
@@ -169,7 +169,7 @@ class V0Worker {
169
169
  parents,
170
170
  retries: onSuccess.retries || ((_p = workflow.taskDefaults) === null || _p === void 0 ? void 0 : _p.retries) || 0,
171
171
  rateLimits: onSuccess.rateLimits || ((_q = workflow.taskDefaults) === null || _q === void 0 ? void 0 : _q.rateLimits),
172
- workerLabels: onSuccess.workerLabels || ((_r = workflow.taskDefaults) === null || _r === void 0 ? void 0 : _r.workerLabels),
172
+ desiredWorkerLabels: onSuccess.desiredWorkerLabels || ((_r = workflow.taskDefaults) === null || _r === void 0 ? void 0 : _r.workerLabels),
173
173
  concurrency: onSuccess.concurrency || ((_s = workflow.taskDefaults) === null || _s === void 0 ? void 0 : _s.concurrency),
174
174
  backoff: onSuccess.backoff || ((_t = workflow.taskDefaults) === null || _t === void 0 ? void 0 : _t.backoff),
175
175
  };
@@ -213,7 +213,7 @@ class V0Worker {
213
213
  userData: '{}',
214
214
  retries: task.retries || ((_e = workflow.taskDefaults) === null || _e === void 0 ? void 0 : _e.retries) || 0,
215
215
  rateLimits: (0, step_1.mapRateLimit)(task.rateLimits || ((_f = workflow.taskDefaults) === null || _f === void 0 ? void 0 : _f.rateLimits)),
216
- workerLabels: toPbWorkerLabel(task.workerLabels || ((_g = workflow.taskDefaults) === null || _g === void 0 ? void 0 : _g.workerLabels)),
216
+ workerLabels: toPbWorkerLabel(task.desiredWorkerLabels || ((_g = workflow.taskDefaults) === null || _g === void 0 ? void 0 : _g.workerLabels)),
217
217
  backoffFactor: ((_h = task.backoff) === null || _h === void 0 ? void 0 : _h.factor) || ((_k = (_j = workflow.taskDefaults) === null || _j === void 0 ? void 0 : _j.backoff) === null || _k === void 0 ? void 0 : _k.factor),
218
218
  backoffMaxSeconds: ((_l = task.backoff) === null || _l === void 0 ? void 0 : _l.maxSeconds) || ((_o = (_m = workflow.taskDefaults) === null || _m === void 0 ? void 0 : _m.backoff) === null || _o === void 0 ? void 0 : _o.maxSeconds),
219
219
  conditions: (0, transformer_1.taskConditionsToPb)(task),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "1.0.0-alpha2",
3
+ "version": "1.0.0",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -120,7 +120,7 @@ export type TaskDefaults = {
120
120
  * - weight: Priority weight for worker selection
121
121
  * - comparator: Custom comparison logic for label matching
122
122
  */
123
- workerLabels?: CreateWorkflowTaskOpts<any, any>['workerLabels'];
123
+ workerLabels?: CreateWorkflowTaskOpts<any, any>['desiredWorkerLabels'];
124
124
  /**
125
125
  * (optional) the concurrency options for the task.
126
126
  */
@@ -0,0 +1,3 @@
1
+ export type SimpleInput = {
2
+ Message: string;
3
+ };
@@ -0,0 +1,40 @@
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 @typescript-eslint/no-unused-vars */
13
+ const conditions_1 = require("../../conditions");
14
+ const hatchet_client_1 = require("../hatchet-client");
15
+ function main() {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ // ❓ Declaring a Durable Task
18
+ const simple = hatchet_client_1.hatchet.durableTask({
19
+ name: 'simple',
20
+ fn: (input, ctx) => __awaiter(this, void 0, void 0, function* () {
21
+ yield ctx.waitFor((0, conditions_1.Or)({
22
+ eventKey: 'user:pay',
23
+ expression: 'input.Status == "PAID"',
24
+ }, {
25
+ sleepFor: '24h',
26
+ }));
27
+ return {
28
+ TransformedMessage: input.Message.toLowerCase(),
29
+ };
30
+ }),
31
+ });
32
+ // !!
33
+ // ❓ Running a Task
34
+ const result = yield simple.run({ Message: 'Hello, World!' });
35
+ // !!
36
+ });
37
+ }
38
+ if (require.main === module) {
39
+ main();
40
+ }
@@ -0,0 +1,6 @@
1
+ export type SimpleInput = {
2
+ Message: string;
3
+ };
4
+ export declare const simple: import("../..").TaskWorkflowDeclaration<SimpleInput, {
5
+ TransformedMessage: string;
6
+ }>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.simple = void 0;
4
+ const hatchet_client_1 = require("../hatchet-client");
5
+ // ❓ Trigger on an event
6
+ exports.simple = hatchet_client_1.hatchet.task({
7
+ name: 'simple',
8
+ onEvents: ['user:created'],
9
+ fn: (input) => {
10
+ // ...
11
+ return {
12
+ TransformedMessage: input.Message.toLowerCase(),
13
+ };
14
+ },
15
+ });
16
+ // !!
@@ -0,0 +1,6 @@
1
+ export type SimpleInput = {
2
+ Message: string;
3
+ };
4
+ export declare const simple: import("../..").TaskWorkflowDeclaration<SimpleInput, {
5
+ TransformedMessage: string;
6
+ }>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.simple = void 0;
4
+ const workflows_1 = require("../../../protoc/v1/workflows");
5
+ const hatchet_client_1 = require("../hatchet-client");
6
+ // ❓ Process what you can handle
7
+ exports.simple = hatchet_client_1.hatchet.task({
8
+ name: 'simple',
9
+ concurrency: {
10
+ expression: 'input.user_id',
11
+ limitStrategy: workflows_1.ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
12
+ maxRuns: 1,
13
+ },
14
+ rateLimits: [
15
+ {
16
+ key: 'api_throttle',
17
+ units: 1,
18
+ },
19
+ ],
20
+ fn: (input) => {
21
+ return {
22
+ TransformedMessage: input.Message.toLowerCase(),
23
+ };
24
+ },
25
+ });
26
+ // !!
@@ -0,0 +1,3 @@
1
+ export type SimpleInput = {
2
+ Message: string;
3
+ };
@@ -0,0 +1,33 @@
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 @typescript-eslint/no-unused-vars */
13
+ const hatchet_client_1 = require("../hatchet-client");
14
+ function main() {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ // ❓ Declaring a Task
17
+ const simple = hatchet_client_1.hatchet.task({
18
+ name: 'simple',
19
+ fn: (input) => {
20
+ return {
21
+ TransformedMessage: input.Message.toLowerCase(),
22
+ };
23
+ },
24
+ });
25
+ // !!
26
+ // ❓ Running a Task
27
+ const result = yield simple.run({ Message: 'Hello, World!' });
28
+ // !!
29
+ });
30
+ }
31
+ if (require.main === module) {
32
+ main();
33
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const flow_control_1 = require("./flow-control");
4
+ // ❓ Schedules and Crons
5
+ const tomorrow = new Date(Date.now() + 1000 * 60 * 60 * 24);
6
+ const scheduled = flow_control_1.simple.schedule(tomorrow, {
7
+ Message: 'Hello, World!',
8
+ });
9
+ const cron = flow_control_1.simple.cron('every-day', '0 0 * * *', {
10
+ Message: 'Hello, World!',
11
+ });
12
+ // !!
@@ -0,0 +1,6 @@
1
+ export type SimpleInput = {
2
+ Message: string;
3
+ };
4
+ export declare const simple: import("../..").TaskWorkflowDeclaration<SimpleInput, {
5
+ TransformedMessage: string;
6
+ }>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.simple = void 0;
4
+ const hatchet_client_1 = require("../hatchet-client");
5
+ // ❓ Route tasks to workers with matching labels
6
+ exports.simple = hatchet_client_1.hatchet.task({
7
+ name: 'simple',
8
+ desiredWorkerLabels: {
9
+ cpu: {
10
+ value: '2x',
11
+ },
12
+ },
13
+ fn: (input) => {
14
+ return {
15
+ TransformedMessage: input.Message.toLowerCase(),
16
+ };
17
+ },
18
+ });
19
+ hatchet_client_1.hatchet.worker('task-routing-worker', {
20
+ workflows: [exports.simple],
21
+ labels: {
22
+ cpu: process.env.CPU_LABEL,
23
+ },
24
+ });
25
+ // !!
@@ -1 +1 @@
1
- export declare const alwaysFail: import("../..").WorkflowDeclaration<any, any>;
1
+ export declare const alwaysFail: import("../..").TaskWorkflowDeclaration<import("../../..").JsonObject, never>;
@@ -13,19 +13,18 @@ exports.alwaysFail = void 0;
13
13
  /* eslint-disable no-console */
14
14
  const hatchet_client_1 = require("../hatchet-client");
15
15
  // ❓ On Failure Task
16
- exports.alwaysFail = hatchet_client_1.hatchet.workflow({
16
+ exports.alwaysFail = hatchet_client_1.hatchet.task({
17
17
  name: 'always-fail',
18
+ // the onFailure function is called when the task fails
19
+ // note: not guaranteed to be called on the same worker
18
20
  onFailure: (input, ctx) => {
19
21
  console.log('onFailure for run:', ctx.workflowRunId());
20
22
  return {
21
23
  'on-failure': 'success',
22
24
  };
23
25
  },
24
- });
25
- // !!
26
- exports.alwaysFail.task({
27
- name: 'always-fail',
28
26
  fn: () => __awaiter(void 0, void 0, void 0, function* () {
29
27
  throw new Error('intentional failure');
30
28
  }),
31
29
  });
30
+ // !!
@@ -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.retries.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 hatchet_client_1 = require("../hatchet-client");
13
+ const workflow_1 = require("./workflow");
14
+ function main() {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const worker = yield hatchet_client_1.hatchet.worker('always-fail-worker', {
17
+ workflows: [workflow_1.retries],
18
+ });
19
+ yield worker.start();
20
+ });
21
+ }
22
+ if (require.main === module) {
23
+ main();
24
+ }
@@ -0,0 +1,5 @@
1
+ export declare const retries: import("../..").TaskWorkflowDeclaration<import("../../..").JsonObject, never>;
2
+ export declare const retriesWithCount: import("../..").TaskWorkflowDeclaration<import("../../..").JsonObject, {
3
+ message: string;
4
+ }>;
5
+ export declare const withBackoff: import("../..").TaskWorkflowDeclaration<import("../../..").JsonObject, never>;
@@ -0,0 +1,53 @@
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
+ exports.withBackoff = exports.retriesWithCount = exports.retries = void 0;
13
+ /* eslint-disable no-console */
14
+ const hatchet_client_1 = require("../hatchet-client");
15
+ // ❓ Simple Step Retries
16
+ exports.retries = hatchet_client_1.hatchet.task({
17
+ name: 'retries',
18
+ retries: 3,
19
+ fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
20
+ throw new Error('intentional failure');
21
+ }),
22
+ });
23
+ // !!
24
+ // ❓ Step Retries with Count
25
+ exports.retriesWithCount = hatchet_client_1.hatchet.task({
26
+ name: 'retriesWithCount',
27
+ retries: 3,
28
+ fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
29
+ // ❓ Get the current retry count
30
+ const retryCount = ctx.retryCount();
31
+ console.log(`Retry count: ${retryCount}`);
32
+ if (retryCount < 2) {
33
+ throw new Error('intentional failure');
34
+ }
35
+ return {
36
+ message: 'success',
37
+ };
38
+ }),
39
+ });
40
+ // !!
41
+ // ❓ Step Retries with Backoff
42
+ exports.withBackoff = hatchet_client_1.hatchet.task({
43
+ name: 'withBackoff',
44
+ retries: 3,
45
+ backoff: {
46
+ factor: 2,
47
+ maxSeconds: 10,
48
+ },
49
+ fn: () => __awaiter(void 0, void 0, void 0, function* () {
50
+ throw new Error('intentional failure');
51
+ }),
52
+ });
53
+ // !!
@@ -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("../retries/workflow");
14
+ function main() {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ try {
17
+ const res = yield workflow_1.retries.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 hatchet_client_1 = require("../hatchet-client");
13
+ const workflow_1 = require("../retries/workflow");
14
+ function main() {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const worker = yield hatchet_client_1.hatchet.worker('always-fail-worker', {
17
+ workflows: [workflow_1.retries],
18
+ });
19
+ yield worker.start();
20
+ });
21
+ }
22
+ if (require.main === module) {
23
+ main();
24
+ }
@@ -0,0 +1,7 @@
1
+ export declare const sticky: import("../..").TaskWorkflowDeclaration<import("../../..").JsonObject, {
2
+ result: {
3
+ value: {
4
+ Value: number;
5
+ };
6
+ };
7
+ }>;
@@ -0,0 +1,32 @@
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
+ exports.sticky = void 0;
13
+ /* eslint-disable no-console */
14
+ const workflows_1 = require("../../../protoc/workflows");
15
+ const hatchet_client_1 = require("../hatchet-client");
16
+ const workflow_1 = require("../child_workflows/workflow");
17
+ // ❓ Sticky Task
18
+ exports.sticky = hatchet_client_1.hatchet.task({
19
+ name: 'sticky',
20
+ retries: 3,
21
+ sticky: workflows_1.StickyStrategy.SOFT,
22
+ fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
23
+ // specify a child workflow to run on the same worker
24
+ const result = yield ctx.runChild(workflow_1.child, {
25
+ N: 1,
26
+ }, { sticky: true });
27
+ return {
28
+ result,
29
+ };
30
+ }),
31
+ });
32
+ // !!
@@ -0,0 +1,9 @@
1
+ export type SimpleInput = {
2
+ Message: string;
3
+ };
4
+ export declare const withTimeouts: import("../..").TaskWorkflowDeclaration<SimpleInput, {
5
+ TransformedMessage: string;
6
+ }>;
7
+ export declare const refreshTimeout: import("../..").TaskWorkflowDeclaration<SimpleInput, {
8
+ TransformedMessage: string;
9
+ }>;
@@ -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
+ exports.refreshTimeout = exports.withTimeouts = void 0;
16
+ // ❓ Declaring a Task
17
+ const sleep_1 = __importDefault(require("../../../util/sleep"));
18
+ const hatchet_client_1 = require("../hatchet-client");
19
+ // ❓ Execution Timeout
20
+ exports.withTimeouts = hatchet_client_1.hatchet.task({
21
+ name: 'with-timeouts',
22
+ // time the task can wait in the queue before it is cancelled
23
+ scheduleTimeout: '10s',
24
+ // time the task can run before it is cancelled
25
+ executionTimeout: '10s',
26
+ fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
27
+ // wait 15 seconds
28
+ yield (0, sleep_1.default)(15000);
29
+ // get the abort controller
30
+ const { controller } = ctx;
31
+ // if the abort controller is aborted, throw an error
32
+ if (controller.signal.aborted) {
33
+ throw new Error('cancelled');
34
+ }
35
+ return {
36
+ TransformedMessage: input.Message.toLowerCase(),
37
+ };
38
+ }),
39
+ });
40
+ // !!
41
+ // ❓ Refresh Timeout
42
+ exports.refreshTimeout = hatchet_client_1.hatchet.task({
43
+ name: 'refresh-timeout',
44
+ executionTimeout: '10s',
45
+ scheduleTimeout: '10s',
46
+ fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
47
+ // adds 15 seconds to the execution timeout
48
+ ctx.refreshTimeout('15s');
49
+ yield (0, sleep_1.default)(15000);
50
+ // get the abort controller
51
+ const { controller } = ctx;
52
+ // now this condition will not be met
53
+ // if the abort controller is aborted, throw an error
54
+ if (controller.signal.aborted) {
55
+ throw new Error('cancelled');
56
+ }
57
+ return {
58
+ TransformedMessage: input.Message.toLowerCase(),
59
+ };
60
+ }),
61
+ });
62
+ // !!
package/v1/task.d.ts CHANGED
@@ -89,7 +89,7 @@ export type CreateBaseTaskOpts<T, K, C> = {
89
89
  * - weight: Priority weight for worker selection
90
90
  * - comparator: Custom comparison logic for label matching
91
91
  */
92
- workerLabels?: CreateStep<T, K>['worker_labels'];
92
+ desiredWorkerLabels?: CreateStep<T, K>['worker_labels'];
93
93
  /**
94
94
  * (optional) the concurrency options for the task
95
95
  */
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const HATCHET_VERSION = "1.0.0-alpha2";
1
+ export declare const HATCHET_VERSION = "1.0.0";
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-alpha2';
4
+ exports.HATCHET_VERSION = '1.0.0';