@hatchet-dev/typescript-sdk 1.0.0-alpha1 → 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.
- package/clients/admin/admin-client.d.ts +15 -20
- package/clients/admin/admin-client.js +21 -17
- package/clients/hatchet-client/hatchet-client.d.ts +5 -4
- package/clients/hatchet-client/hatchet-client.js +6 -4
- package/clients/listeners/durable-listener/durable-listener-client.d.ts +25 -0
- package/clients/listeners/durable-listener/durable-listener-client.js +30 -0
- package/clients/listeners/durable-listener/pooled-durable-listener-client.d.ts +43 -0
- package/clients/listeners/durable-listener/pooled-durable-listener-client.js +241 -0
- package/clients/{listener/listener-client.d.ts → listeners/run-listener/child-listener-client.d.ts} +8 -8
- package/clients/{listener/listener-client.js → listeners/run-listener/child-listener-client.js} +8 -19
- package/clients/{listener/child-listener-client.d.ts → listeners/run-listener/pooled-child-listener-client.d.ts} +5 -5
- package/clients/{listener/child-listener-client.js → listeners/run-listener/pooled-child-listener-client.js} +5 -5
- package/clients/rest/generated/Api.d.ts +49 -2
- package/clients/rest/generated/Api.js +30 -0
- package/clients/rest/generated/data-contracts.d.ts +88 -82
- package/clients/rest/generated/data-contracts.js +8 -1
- package/clients/worker/worker.d.ts +5 -1
- package/clients/worker/worker.js +173 -2
- package/examples/affinity-workers.js +5 -1
- package/examples/api.js +1 -1
- package/examples/bulk-fanout-worker.js +1 -1
- package/examples/byo-logger.js +4 -0
- package/examples/concurrency/cancel-in-progress/concurrency-event.js +2 -2
- package/examples/concurrency/group-round-robin/concurrency-event.js +1 -1
- package/examples/crons/programatic-crons.js +4 -4
- package/examples/dag-worker.js +0 -1
- package/examples/example-event.js +2 -2
- package/examples/logger.js +2 -0
- package/examples/on-failure.js +1 -1
- package/examples/rate-limit/events.js +3 -3
- package/examples/scheduled-runs/programatic-schedules.js +4 -4
- package/examples/sticky-worker-with-check.js +2 -2
- package/examples/sticky-worker.js +5 -0
- package/index.d.ts +1 -3
- package/index.js +1 -3
- package/package.json +2 -2
- package/protoc/dispatcher/dispatcher.d.ts +2 -0
- package/protoc/dispatcher/dispatcher.js +1 -1
- package/protoc/events/events.js +1 -1
- package/protoc/google/protobuf/timestamp.js +1 -1
- package/protoc/v1/dispatcher.d.ts +77 -0
- package/protoc/v1/dispatcher.js +341 -0
- package/protoc/v1/shared/condition.d.ts +59 -0
- package/protoc/v1/shared/condition.js +549 -0
- package/protoc/v1/workflows.d.ts +263 -0
- package/protoc/v1/workflows.js +1823 -0
- package/protoc/workflows/workflows.js +1 -1
- package/step.d.ts +173 -47
- package/step.js +208 -64
- package/util/sleep.d.ts +7 -0
- package/util/sleep.js +7 -0
- package/util/workflow-run-ref.d.ts +8 -2
- package/util/workflow-run-ref.js +13 -0
- package/v1/client/client.d.ts +125 -7
- package/v1/client/client.interface.d.ts +9 -1
- package/v1/client/client.js +148 -17
- package/v1/client/duration.d.ts +7 -0
- package/v1/client/duration.js +2 -0
- package/v1/client/features/index.d.ts +5 -0
- package/v1/client/features/index.js +21 -0
- package/v1/client/features/metrics.d.ts +14 -0
- package/v1/client/features/metrics.js +45 -0
- package/v1/client/features/ratelimits.d.ts +20 -0
- package/v1/client/features/ratelimits.js +40 -0
- package/v1/client/features/runs.d.ts +15 -0
- package/v1/client/features/runs.js +60 -0
- package/v1/client/features/workers.d.ts +14 -0
- package/v1/client/features/workers.js +56 -0
- package/v1/client/features/workflows.d.ts +17 -0
- package/v1/client/features/workflows.js +93 -0
- package/v1/client/worker.d.ts +25 -15
- package/v1/client/worker.js +76 -47
- package/v1/conditions/base.d.ts +18 -0
- package/v1/conditions/base.js +18 -0
- package/v1/conditions/index.d.ts +31 -0
- package/v1/conditions/index.js +91 -0
- package/v1/conditions/parent-condition.d.ts +40 -0
- package/v1/conditions/parent-condition.js +36 -0
- package/v1/conditions/sleep-condition.d.ts +47 -0
- package/v1/conditions/sleep-condition.js +38 -0
- package/v1/conditions/transformer.d.ts +5 -0
- package/v1/conditions/transformer.js +52 -0
- package/v1/conditions/user-event-condition.d.ts +50 -0
- package/v1/conditions/user-event-condition.js +39 -0
- package/v1/declaration.d.ts +309 -0
- package/v1/declaration.js +296 -0
- package/v1/examples/child_workflows/worker.js +2 -2
- package/v1/examples/child_workflows/workflow.d.ts +2 -2
- package/v1/examples/child_workflows/workflow.js +5 -3
- package/v1/examples/concurrency-rr/load.js +2 -2
- package/v1/examples/concurrency-rr/worker.js +2 -2
- package/v1/examples/concurrency-rr/workflow.d.ts +1 -1
- package/v1/examples/concurrency-rr/workflow.js +2 -3
- package/v1/examples/dag/worker.js +2 -2
- package/v1/examples/dag/workflow.d.ts +1 -1
- package/v1/examples/dag/workflow.js +3 -3
- package/v1/examples/dag_match_condition/event.js +28 -0
- package/v1/examples/dag_match_condition/run.d.ts +1 -0
- package/v1/examples/dag_match_condition/run.js +25 -0
- package/v1/examples/dag_match_condition/worker.d.ts +1 -0
- package/{examples/playground.js → v1/examples/dag_match_condition/worker.js} +7 -22
- package/v1/examples/dag_match_condition/workflow.d.ts +11 -0
- package/v1/examples/dag_match_condition/workflow.js +41 -0
- package/v1/examples/deep/worker.js +2 -2
- package/v1/examples/deep/workflow.d.ts +6 -6
- package/v1/examples/deep/workflow.js +7 -7
- package/v1/examples/durable-sleep/event.d.ts +1 -0
- package/v1/examples/durable-sleep/event.js +28 -0
- package/v1/examples/durable-sleep/run.d.ts +1 -0
- package/v1/examples/durable-sleep/run.js +30 -0
- package/v1/examples/durable-sleep/worker.d.ts +1 -0
- package/v1/examples/durable-sleep/worker.js +24 -0
- package/v1/examples/durable-sleep/workflow.d.ts +1 -0
- package/v1/examples/durable-sleep/workflow.js +37 -0
- package/v1/examples/inferred-typing/run.d.ts +1 -0
- package/v1/examples/inferred-typing/run.js +41 -0
- package/v1/examples/inferred-typing/worker.d.ts +1 -0
- package/v1/examples/inferred-typing/worker.js +24 -0
- package/v1/examples/inferred-typing/workflow.d.ts +15 -0
- package/v1/examples/inferred-typing/workflow.js +44 -0
- package/v1/examples/landing_page/durable-excution.d.ts +3 -0
- package/v1/examples/landing_page/durable-excution.js +40 -0
- package/v1/examples/landing_page/event-signaling.d.ts +6 -0
- package/v1/examples/landing_page/event-signaling.js +16 -0
- package/v1/examples/landing_page/flow-control.d.ts +6 -0
- package/v1/examples/landing_page/flow-control.js +26 -0
- package/v1/examples/landing_page/queues.d.ts +3 -0
- package/v1/examples/landing_page/queues.js +33 -0
- package/v1/examples/landing_page/scheduling.d.ts +1 -0
- package/v1/examples/landing_page/scheduling.js +12 -0
- package/v1/examples/landing_page/task-routing.d.ts +6 -0
- package/v1/examples/landing_page/task-routing.js +25 -0
- package/v1/examples/legacy/run.js +2 -2
- package/v1/examples/legacy/worker.js +2 -2
- package/v1/examples/on_cron/worker.d.ts +1 -0
- package/v1/examples/on_cron/worker.js +24 -0
- package/v1/examples/on_cron/workflow.d.ts +10 -0
- package/v1/examples/on_cron/workflow.js +21 -0
- package/v1/examples/on_event/event.js +3 -2
- package/v1/examples/on_event/worker.js +2 -2
- package/v1/examples/on_event/workflow.d.ts +4 -4
- package/v1/examples/on_event/workflow.js +6 -3
- package/v1/examples/on_event copy/event.d.ts +1 -0
- package/v1/examples/on_event copy/event.js +26 -0
- package/v1/examples/on_event copy/worker.d.ts +1 -0
- package/v1/examples/on_event copy/worker.js +24 -0
- package/v1/examples/on_event copy/workflow.d.ts +16 -0
- package/v1/examples/on_event copy/workflow.js +35 -0
- package/v1/examples/on_failure/worker.js +2 -2
- package/v1/examples/on_failure/workflow.d.ts +1 -1
- package/v1/examples/on_failure/workflow.js +18 -8
- package/v1/examples/on_success/run.d.ts +1 -0
- package/v1/examples/on_success/run.js +31 -0
- package/v1/examples/on_success/worker.d.ts +1 -0
- package/v1/examples/on_success/worker.js +24 -0
- package/v1/examples/on_success/workflow.d.ts +4 -0
- package/v1/examples/on_success/workflow.js +59 -0
- package/v1/examples/retries/run.d.ts +1 -0
- package/v1/examples/retries/run.js +29 -0
- package/v1/examples/retries/worker.d.ts +1 -0
- package/v1/examples/retries/worker.js +24 -0
- package/v1/examples/retries/workflow.d.ts +5 -0
- package/v1/examples/retries/workflow.js +53 -0
- package/v1/examples/simple/client-run.d.ts +1 -0
- package/v1/examples/simple/client-run.js +16 -0
- package/v1/examples/simple/cron.js +6 -2
- package/v1/examples/simple/delay.js +2 -2
- package/v1/examples/simple/enqueue.d.ts +1 -0
- package/v1/examples/simple/enqueue.js +43 -0
- package/v1/examples/simple/run.js +8 -3
- package/v1/examples/simple/schedule.js +11 -5
- package/v1/examples/simple/stub-workflow.d.ts +9 -0
- package/v1/examples/simple/stub-workflow.js +17 -0
- package/v1/examples/simple/worker.js +7 -2
- package/v1/examples/simple/workflow.d.ts +4 -3
- package/v1/examples/simple/workflow.js +5 -5
- package/v1/examples/sticky/run.d.ts +1 -0
- package/v1/examples/sticky/run.js +29 -0
- package/v1/examples/sticky/worker.d.ts +1 -0
- package/v1/examples/sticky/worker.js +24 -0
- package/v1/examples/sticky/workflow.d.ts +7 -0
- package/v1/examples/sticky/workflow.js +32 -0
- package/v1/examples/with_timeouts/workflow.d.ts +9 -0
- package/v1/examples/with_timeouts/workflow.js +62 -0
- package/v1/index.d.ts +5 -0
- package/v1/index.js +20 -0
- package/v1/task.d.ts +144 -14
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/v1/workflow.d.ts +0 -158
- package/v1/workflow.js +0 -145
- /package/{examples/playground.d.ts → v1/examples/dag_match_condition/event.d.ts} +0 -0
- /package/v1/examples/{client.d.ts → hatchet-client.d.ts} +0 -0
- /package/v1/examples/{client.js → hatchet-client.js} +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
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.onSuccessDag = exports.onSuccess = void 0;
|
|
13
|
+
/* eslint-disable no-console */
|
|
14
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
15
|
+
// ❓ On Success Task
|
|
16
|
+
exports.onSuccess = hatchet_client_1.hatchet.task({
|
|
17
|
+
name: 'run-on-success',
|
|
18
|
+
// 👀 onSuccess handler will run if the fn task succeeds
|
|
19
|
+
onSuccess: (_, ctx) => {
|
|
20
|
+
console.log('onSuccess for run:', ctx.workflowRunId());
|
|
21
|
+
return {
|
|
22
|
+
'on-success': 'success',
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
fn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
return {
|
|
27
|
+
'always-succeed': 'success',
|
|
28
|
+
};
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
31
|
+
// !!
|
|
32
|
+
// ❓ On Success DAG
|
|
33
|
+
exports.onSuccessDag = hatchet_client_1.hatchet.workflow({
|
|
34
|
+
name: 'on-success-dag',
|
|
35
|
+
// 👀 onSuccess handler will run if all tasks in the workflow succeed
|
|
36
|
+
onSuccess: (_, ctx) => {
|
|
37
|
+
console.log('onSuccess for run:', ctx.workflowRunId());
|
|
38
|
+
return {
|
|
39
|
+
'on-success': 'success',
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
exports.onSuccessDag.task({
|
|
44
|
+
name: 'always-succeed',
|
|
45
|
+
fn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
return {
|
|
47
|
+
'always-succeed': 'success',
|
|
48
|
+
};
|
|
49
|
+
}),
|
|
50
|
+
});
|
|
51
|
+
exports.onSuccessDag.task({
|
|
52
|
+
name: 'always-succeed2',
|
|
53
|
+
fn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
+
return {
|
|
55
|
+
'always-succeed': 'success',
|
|
56
|
+
};
|
|
57
|
+
}),
|
|
58
|
+
});
|
|
59
|
+
// !!
|
|
@@ -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,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// ❓ Client Run Methods
|
|
4
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
5
|
+
hatchet_client_1.hatchet.run('simple', { Message: 'Hello, World!' });
|
|
6
|
+
hatchet_client_1.hatchet.runNoWait('simple', { Message: 'Hello, World!' }, {});
|
|
7
|
+
hatchet_client_1.hatchet.schedule.create('simple', {
|
|
8
|
+
triggerAt: new Date(Date.now() + 1000 * 60 * 60 * 24),
|
|
9
|
+
input: { Message: 'Hello, World!' },
|
|
10
|
+
});
|
|
11
|
+
hatchet_client_1.hatchet.cron.create('simple', {
|
|
12
|
+
name: 'my-cron',
|
|
13
|
+
expression: '0 0 * * *',
|
|
14
|
+
input: { Message: 'Hello, World!' },
|
|
15
|
+
});
|
|
16
|
+
// !!
|
|
@@ -9,16 +9,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const
|
|
12
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
13
13
|
const workflow_1 = require("./workflow");
|
|
14
14
|
function main() {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
// ❓ Create
|
|
16
17
|
const cron = yield workflow_1.simple.cron('simple-daily', '0 0 * * *', {
|
|
17
18
|
Message: 'hello',
|
|
18
19
|
});
|
|
20
|
+
// it may be useful to save the cron id for later
|
|
21
|
+
const cronId = cron.metadata.id;
|
|
22
|
+
// !!
|
|
19
23
|
// eslint-disable-next-line no-console
|
|
20
24
|
console.log(cron.metadata.id);
|
|
21
|
-
yield
|
|
25
|
+
yield hatchet_client_1.hatchet.crons.delete(cron);
|
|
22
26
|
});
|
|
23
27
|
}
|
|
24
28
|
if (require.main === module) {
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const
|
|
12
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
13
13
|
const workflow_1 = require("./workflow");
|
|
14
14
|
function main() {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -19,7 +19,7 @@ function main() {
|
|
|
19
19
|
});
|
|
20
20
|
// eslint-disable-next-line no-console
|
|
21
21
|
console.log(scheduled.metadata.id);
|
|
22
|
-
yield
|
|
22
|
+
yield hatchet_client_1.hatchet.schedules.delete(scheduled);
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
if (require.main === module) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
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 import/no-duplicates */
|
|
13
|
+
/* eslint-disable no-console */
|
|
14
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
15
|
+
// ❓ Enqueuing a Workflow (Fire and Forget)
|
|
16
|
+
const workflow_1 = require("./workflow");
|
|
17
|
+
// ...
|
|
18
|
+
function main() {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
// 👀 Enqueue the workflow
|
|
21
|
+
const run = yield workflow_1.simple.runNoWait({
|
|
22
|
+
Message: 'hello',
|
|
23
|
+
});
|
|
24
|
+
// 👀 Get the run ID of the workflow
|
|
25
|
+
const runId = yield run.getWorkflowRunId();
|
|
26
|
+
// It may be helpful to store the run ID of the workflow
|
|
27
|
+
// in a database or other persistent storage for later use
|
|
28
|
+
console.log(runId);
|
|
29
|
+
// !!
|
|
30
|
+
// ❓ Subscribing to results
|
|
31
|
+
// the return object of the enqueue method is a WorkflowRunRef which includes a listener for the result of the workflow
|
|
32
|
+
const result = yield run.result();
|
|
33
|
+
console.log(result);
|
|
34
|
+
// if you need to subscribe to the result of the workflow at a later time, you can use the runRef method and the stored runId
|
|
35
|
+
const ref = hatchet_client_1.hatchet.runRef(runId);
|
|
36
|
+
const result2 = yield ref.result();
|
|
37
|
+
console.log(result2);
|
|
38
|
+
// !!
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (require.main === module) {
|
|
42
|
+
main();
|
|
43
|
+
}
|
|
@@ -9,14 +9,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
/* eslint-disable no-console */
|
|
13
|
+
// ❓ Running a Workflow with Results
|
|
12
14
|
const workflow_1 = require("./workflow");
|
|
15
|
+
// ...
|
|
13
16
|
function main() {
|
|
14
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
// 👀 Run the workflow with results
|
|
15
19
|
const res = yield workflow_1.simple.run({
|
|
16
|
-
Message: '
|
|
20
|
+
Message: 'HeLlO WoRlD',
|
|
17
21
|
});
|
|
18
|
-
//
|
|
19
|
-
console.log(res.
|
|
22
|
+
// 👀 Access the results of the workflow
|
|
23
|
+
console.log(res.TransformedMessage);
|
|
24
|
+
// !!
|
|
20
25
|
});
|
|
21
26
|
}
|
|
22
27
|
if (require.main === module) {
|
|
@@ -9,17 +9,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
|
|
12
|
+
/* eslint-disable no-console */
|
|
13
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
13
14
|
const workflow_1 = require("./workflow");
|
|
14
15
|
function main() {
|
|
15
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
|
|
17
|
+
// ❓ Create a Scheduled Run
|
|
18
|
+
const runAt = new Date(new Date().setHours(12, 0, 0, 0) + 24 * 60 * 60 * 1000);
|
|
17
19
|
const scheduled = yield workflow_1.simple.schedule(runAt, {
|
|
18
20
|
Message: 'hello',
|
|
19
21
|
});
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
// 👀 Get the scheduled run ID of the workflow
|
|
23
|
+
// it may be helpful to store the scheduled run ID of the workflow
|
|
24
|
+
// in a database or other persistent storage for later use
|
|
25
|
+
const scheduledRunId = scheduled.metadata.id;
|
|
26
|
+
console.log(scheduledRunId);
|
|
27
|
+
// !!
|
|
28
|
+
yield hatchet_client_1.hatchet.schedules.delete(scheduled);
|
|
23
29
|
});
|
|
24
30
|
}
|
|
25
31
|
if (require.main === module) {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.simple = void 0;
|
|
4
|
+
// ❓ Declaring an External Workflow Reference
|
|
5
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
6
|
+
// declare the workflow with the same name as the
|
|
7
|
+
// workflow name on the worker
|
|
8
|
+
exports.simple = hatchet_client_1.hatchet.workflow({
|
|
9
|
+
name: 'simple',
|
|
10
|
+
});
|
|
11
|
+
// you can use all the same run methods on the stub
|
|
12
|
+
// with full type-safety
|
|
13
|
+
exports.simple.run({ Message: 'Hello, World!' });
|
|
14
|
+
exports.simple.runNoWait({ Message: 'Hello, World!' });
|
|
15
|
+
exports.simple.schedule(new Date(), { Message: 'Hello, World!' });
|
|
16
|
+
exports.simple.cron('my-cron', '0 0 * * *', { Message: 'Hello, World!' });
|
|
17
|
+
// !!
|
|
@@ -9,12 +9,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
|
|
12
|
+
// ❓ Declaring a Worker
|
|
13
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
13
14
|
const workflow_1 = require("./workflow");
|
|
14
15
|
function main() {
|
|
15
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
const worker = yield
|
|
17
|
+
const worker = yield hatchet_client_1.hatchet.worker('simple-worker', {
|
|
18
|
+
// 👀 Declare the workflows that the worker can execute
|
|
17
19
|
workflows: [workflow_1.simple],
|
|
20
|
+
// 👀 Declare the number of concurrent task runs the worker can accept
|
|
21
|
+
slots: 100,
|
|
18
22
|
});
|
|
19
23
|
yield worker.start();
|
|
20
24
|
});
|
|
@@ -22,3 +26,4 @@ function main() {
|
|
|
22
26
|
if (require.main === module) {
|
|
23
27
|
main();
|
|
24
28
|
}
|
|
29
|
+
// !!
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
type SimpleInput = {
|
|
1
|
+
export type SimpleInput = {
|
|
2
2
|
Message: string;
|
|
3
3
|
};
|
|
4
|
-
export declare const simple: import("
|
|
5
|
-
|
|
4
|
+
export declare const simple: import("../..").TaskWorkflowDeclaration<SimpleInput, {
|
|
5
|
+
TransformedMessage: string;
|
|
6
|
+
}>;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.simple = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
// ❓ Declaring a Task
|
|
5
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
6
|
+
exports.simple = hatchet_client_1.hatchet.task({
|
|
6
7
|
name: 'simple',
|
|
7
|
-
});
|
|
8
|
-
exports.simple.task({
|
|
9
|
-
name: 'to-lower',
|
|
10
8
|
fn: (input) => {
|
|
11
9
|
return {
|
|
12
10
|
TransformedMessage: input.Message.toLowerCase(),
|
|
13
11
|
};
|
|
14
12
|
},
|
|
15
13
|
});
|
|
14
|
+
// !!
|
|
15
|
+
// see ./worker.ts and ./run.ts for how to run the workflow
|
|
@@ -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,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/index.d.ts
CHANGED
package/v1/index.js
CHANGED
|
@@ -1 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./client/client"), exports);
|
|
18
|
+
__exportStar(require("./client/features"), exports);
|
|
19
|
+
__exportStar(require("./client/worker"), exports);
|
|
20
|
+
__exportStar(require("./declaration"), exports);
|
|
21
|
+
__exportStar(require("./conditions"), exports);
|