@hatchet-dev/typescript-sdk 1.0.1 → 1.0.2
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/package.json +1 -1
- package/v1/client/features/runs.d.ts +1 -1
- package/v1/client/features/runs.js +0 -1
- package/v1/declaration.d.ts +34 -12
- package/v1/declaration.js +46 -0
- package/v1/examples/concurrency-rr/workflow.js +2 -0
- package/v1/examples/on_failure/run.js +1 -1
- package/v1/examples/on_failure/worker.js +1 -1
- package/v1/examples/on_failure/workflow.d.ts +1 -1
- package/v1/examples/on_failure/workflow.js +12 -8
- package/v1/examples/on_success/run.js +0 -2
- package/v1/examples/on_success/worker.js +1 -1
- package/v1/examples/on_success/workflow.d.ts +0 -3
- package/v1/examples/on_success/workflow.js +10 -25
- package/v1/examples/simple/client-run.js +2 -2
- package/v1/task.d.ts +2 -2
- package/version.d.ts +1 -1
- package/version.js +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import WorkflowRunRef from '../../../util/workflow-run-ref';
|
|
2
2
|
import { V1TaskStatus } from '../../../clients/rest/generated/data-contracts';
|
|
3
|
-
import { HatchetClient } from '../client';
|
|
4
3
|
import { WorkflowsClient } from './workflows';
|
|
4
|
+
import { HatchetClient } from '../client';
|
|
5
5
|
export type RunFilter = {
|
|
6
6
|
since: Date;
|
|
7
7
|
until?: Date;
|
|
@@ -19,7 +19,6 @@ class RunsClient {
|
|
|
19
19
|
this.tenantId = client.tenantId;
|
|
20
20
|
this.workflows = client.workflows;
|
|
21
21
|
}
|
|
22
|
-
// TODO expose streaming methods?
|
|
23
22
|
get(run) {
|
|
24
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
24
|
const runId = typeof run === 'string' ? run : yield run.getWorkflowRunId();
|
package/v1/declaration.d.ts
CHANGED
|
@@ -54,18 +54,6 @@ export type CreateBaseWorkflowOpts = {
|
|
|
54
54
|
*/
|
|
55
55
|
onEvents?: string[];
|
|
56
56
|
concurrency?: TaskConcurrency;
|
|
57
|
-
/**
|
|
58
|
-
* (optional) onFailure handler for the workflow.
|
|
59
|
-
* Invoked when any task in the workflow fails.
|
|
60
|
-
* @param ctx The context of the workflow.
|
|
61
|
-
*/
|
|
62
|
-
onFailure?: TaskFn<any, any> | CreateOnFailureTaskOpts<any, any>;
|
|
63
|
-
/**
|
|
64
|
-
* (optional) onSuccess handler for the workflow.
|
|
65
|
-
* Invoked when all tasks in the workflow complete successfully.
|
|
66
|
-
* @param ctx The context of the workflow.
|
|
67
|
-
*/
|
|
68
|
-
onSuccess?: TaskFn<any, any> | CreateOnSuccessTaskOpts<any, any>;
|
|
69
57
|
};
|
|
70
58
|
export type CreateTaskWorkflowOpts<T extends JsonObject = any, K extends JsonObject = any> = CreateBaseWorkflowOpts & CreateBaseTaskOpts<T, K, TaskFn<T, K>>;
|
|
71
59
|
/**
|
|
@@ -138,6 +126,18 @@ export type WorkflowDefinition = CreateWorkflowOpts & {
|
|
|
138
126
|
* The durable tasks that make up this workflow.
|
|
139
127
|
*/
|
|
140
128
|
_durableTasks: CreateWorkflowDurableTaskOpts<any, any>[];
|
|
129
|
+
/**
|
|
130
|
+
* (optional) onFailure handler for the workflow.
|
|
131
|
+
* Invoked when any task in the workflow fails.
|
|
132
|
+
* @param ctx The context of the workflow.
|
|
133
|
+
*/
|
|
134
|
+
onFailure?: TaskFn<any, any> | CreateOnFailureTaskOpts<any, any>;
|
|
135
|
+
/**
|
|
136
|
+
* (optional) onSuccess handler for the workflow.
|
|
137
|
+
* Invoked when all tasks in the workflow complete successfully.
|
|
138
|
+
* @param ctx The context of the workflow.
|
|
139
|
+
*/
|
|
140
|
+
onSuccess?: TaskFn<any, any> | CreateOnSuccessTaskOpts<any, any>;
|
|
141
141
|
};
|
|
142
142
|
/**
|
|
143
143
|
* Represents a workflow that can be executed by Hatchet.
|
|
@@ -256,6 +256,28 @@ export declare class WorkflowDeclaration<T extends JsonObject, K extends JsonObj
|
|
|
256
256
|
name: Name;
|
|
257
257
|
fn: (input: T, ctx: Context<T>) => TaskOutputType<K, Name, L> | Promise<TaskOutputType<K, Name, L>>;
|
|
258
258
|
}) | TaskWorkflowDeclaration<any, any>): CreateWorkflowTaskOpts<T, TaskOutputType<K, Name, L>>;
|
|
259
|
+
/**
|
|
260
|
+
* Adds an onFailure task to the workflow.
|
|
261
|
+
* This will only run if any task in the workflow fails.
|
|
262
|
+
* @template Name The literal string name of the task.
|
|
263
|
+
* @template L The inferred return type of the task function.
|
|
264
|
+
* @param options The task configuration options.
|
|
265
|
+
* @returns The task options that were added.
|
|
266
|
+
*/
|
|
267
|
+
onFailure<Name extends string, L>(options: (Omit<CreateOnFailureTaskOpts<T, TaskOutputType<K, Name, L>>, 'fn'> & {
|
|
268
|
+
fn: (input: T, ctx: Context<T>) => TaskOutputType<K, Name, L> | Promise<TaskOutputType<K, Name, L>>;
|
|
269
|
+
}) | TaskWorkflowDeclaration<any, any>): CreateWorkflowTaskOpts<T, TaskOutputType<K, Name, L>>;
|
|
270
|
+
/**
|
|
271
|
+
* Adds an onSuccess task to the workflow.
|
|
272
|
+
* This will only run if all tasks in the workflow complete successfully.
|
|
273
|
+
* @template Name The literal string name of the task.
|
|
274
|
+
* @template L The inferred return type of the task function.
|
|
275
|
+
* @param options The task configuration options.
|
|
276
|
+
* @returns The task options that were added.
|
|
277
|
+
*/
|
|
278
|
+
onSuccess<Name extends string, L>(options: (Omit<CreateOnSuccessTaskOpts<T, TaskOutputType<K, Name, L>>, 'fn'> & {
|
|
279
|
+
fn: (input: T, ctx: Context<T>) => TaskOutputType<K, Name, L> | Promise<TaskOutputType<K, Name, L>>;
|
|
280
|
+
}) | TaskWorkflowDeclaration<any, any>): CreateWorkflowTaskOpts<T, TaskOutputType<K, Name, L>>;
|
|
259
281
|
/**
|
|
260
282
|
* Adds a durable task to the workflow.
|
|
261
283
|
* The return type will be either the property on K that corresponds to the task name,
|
package/v1/declaration.js
CHANGED
|
@@ -215,6 +215,52 @@ class WorkflowDeclaration extends BaseWorkflowDeclaration {
|
|
|
215
215
|
this.definition._tasks.push(typedOptions);
|
|
216
216
|
return typedOptions;
|
|
217
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Adds an onFailure task to the workflow.
|
|
220
|
+
* This will only run if any task in the workflow fails.
|
|
221
|
+
* @template Name The literal string name of the task.
|
|
222
|
+
* @template L The inferred return type of the task function.
|
|
223
|
+
* @param options The task configuration options.
|
|
224
|
+
* @returns The task options that were added.
|
|
225
|
+
*/
|
|
226
|
+
onFailure(options) {
|
|
227
|
+
var _a;
|
|
228
|
+
let typedOptions;
|
|
229
|
+
if (options instanceof TaskWorkflowDeclaration) {
|
|
230
|
+
typedOptions = options.taskDef;
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
typedOptions = options;
|
|
234
|
+
}
|
|
235
|
+
if (this.definition.onFailure) {
|
|
236
|
+
(_a = this.client) === null || _a === void 0 ? void 0 : _a._v0.logger.warn(`onFailure task will override existing onFailure task`);
|
|
237
|
+
}
|
|
238
|
+
this.definition.onFailure = typedOptions;
|
|
239
|
+
return typedOptions;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Adds an onSuccess task to the workflow.
|
|
243
|
+
* This will only run if all tasks in the workflow complete successfully.
|
|
244
|
+
* @template Name The literal string name of the task.
|
|
245
|
+
* @template L The inferred return type of the task function.
|
|
246
|
+
* @param options The task configuration options.
|
|
247
|
+
* @returns The task options that were added.
|
|
248
|
+
*/
|
|
249
|
+
onSuccess(options) {
|
|
250
|
+
var _a;
|
|
251
|
+
let typedOptions;
|
|
252
|
+
if (options instanceof TaskWorkflowDeclaration) {
|
|
253
|
+
typedOptions = options.taskDef;
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
typedOptions = options;
|
|
257
|
+
}
|
|
258
|
+
if (this.definition.onSuccess) {
|
|
259
|
+
(_a = this.client) === null || _a === void 0 ? void 0 : _a._v0.logger.warn(`onSuccess task will override existing onSuccess task`);
|
|
260
|
+
}
|
|
261
|
+
this.definition.onSuccess = typedOptions;
|
|
262
|
+
return typedOptions;
|
|
263
|
+
}
|
|
218
264
|
/**
|
|
219
265
|
* Adds a durable task to the workflow.
|
|
220
266
|
* The return type will be either the property on K that corresponds to the task name,
|
|
@@ -15,6 +15,7 @@ const hatchet_client_1 = require("../hatchet-client");
|
|
|
15
15
|
const sleep = (ms) => new Promise((resolve) => {
|
|
16
16
|
setTimeout(resolve, ms);
|
|
17
17
|
});
|
|
18
|
+
// ❓ Workflow
|
|
18
19
|
exports.simpleConcurrency = hatchet_client_1.hatchet.workflow({
|
|
19
20
|
name: 'simple-concurrency',
|
|
20
21
|
concurrency: {
|
|
@@ -23,6 +24,7 @@ exports.simpleConcurrency = hatchet_client_1.hatchet.workflow({
|
|
|
23
24
|
expression: 'input.GroupKey',
|
|
24
25
|
},
|
|
25
26
|
});
|
|
27
|
+
// !!
|
|
26
28
|
exports.simpleConcurrency.task({
|
|
27
29
|
name: 'to-lower',
|
|
28
30
|
fn: (input) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -14,7 +14,7 @@ const workflow_1 = require("./workflow");
|
|
|
14
14
|
function main() {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
try {
|
|
17
|
-
const res = yield workflow_1.
|
|
17
|
+
const res = yield workflow_1.failureWorkflow.run({});
|
|
18
18
|
console.log(res);
|
|
19
19
|
}
|
|
20
20
|
catch (e) {
|
|
@@ -14,7 +14,7 @@ const workflow_1 = require("./workflow");
|
|
|
14
14
|
function main() {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
const worker = yield hatchet_client_1.hatchet.worker('always-fail-worker', {
|
|
17
|
-
workflows: [workflow_1.
|
|
17
|
+
workflows: [workflow_1.failureWorkflow],
|
|
18
18
|
});
|
|
19
19
|
yield worker.start();
|
|
20
20
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const failureWorkflow: import("../..").WorkflowDeclaration<any, any>;
|
|
@@ -9,22 +9,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.failureWorkflow = void 0;
|
|
13
13
|
/* eslint-disable no-console */
|
|
14
14
|
const hatchet_client_1 = require("../hatchet-client");
|
|
15
15
|
// ❓ On Failure Task
|
|
16
|
-
exports.
|
|
16
|
+
exports.failureWorkflow = hatchet_client_1.hatchet.workflow({
|
|
17
17
|
name: 'always-fail',
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
});
|
|
19
|
+
exports.failureWorkflow.task({
|
|
20
|
+
name: 'always-fail',
|
|
21
|
+
fn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
throw new Error('intentional failure');
|
|
23
|
+
}),
|
|
24
|
+
});
|
|
25
|
+
exports.failureWorkflow.onFailure({
|
|
26
|
+
name: 'on-failure',
|
|
27
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
28
|
console.log('onFailure for run:', ctx.workflowRunId());
|
|
22
29
|
return {
|
|
23
30
|
'on-failure': 'success',
|
|
24
31
|
};
|
|
25
|
-
},
|
|
26
|
-
fn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
-
throw new Error('intentional failure');
|
|
28
32
|
}),
|
|
29
33
|
});
|
|
30
34
|
// !!
|
|
@@ -14,8 +14,6 @@ const workflow_1 = require("./workflow");
|
|
|
14
14
|
function main() {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
try {
|
|
17
|
-
const res = yield workflow_1.onSuccess.run({});
|
|
18
|
-
console.log(res);
|
|
19
17
|
const res2 = yield workflow_1.onSuccessDag.run({});
|
|
20
18
|
console.log(res2);
|
|
21
19
|
}
|
|
@@ -14,7 +14,7 @@ const workflow_1 = require("./workflow");
|
|
|
14
14
|
function main() {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
const worker = yield hatchet_client_1.hatchet.worker('always-succeed-worker', {
|
|
17
|
-
workflows: [workflow_1.onSuccessDag
|
|
17
|
+
workflows: [workflow_1.onSuccessDag],
|
|
18
18
|
});
|
|
19
19
|
yield worker.start();
|
|
20
20
|
});
|
|
@@ -9,36 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.onSuccessDag =
|
|
12
|
+
exports.onSuccessDag = void 0;
|
|
13
13
|
/* eslint-disable no-console */
|
|
14
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
15
|
// ❓ On Success DAG
|
|
33
16
|
exports.onSuccessDag = hatchet_client_1.hatchet.workflow({
|
|
34
17
|
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
18
|
});
|
|
43
19
|
exports.onSuccessDag.task({
|
|
44
20
|
name: 'always-succeed',
|
|
@@ -56,4 +32,13 @@ exports.onSuccessDag.task({
|
|
|
56
32
|
};
|
|
57
33
|
}),
|
|
58
34
|
});
|
|
35
|
+
// 👀 onSuccess handler will run if all tasks in the workflow succeed
|
|
36
|
+
exports.onSuccessDag.onSuccess({
|
|
37
|
+
fn: (_, ctx) => {
|
|
38
|
+
console.log('onSuccess for run:', ctx.workflowRunId());
|
|
39
|
+
return {
|
|
40
|
+
'on-success': 'success',
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
});
|
|
59
44
|
// !!
|
|
@@ -4,11 +4,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
const hatchet_client_1 = require("../hatchet-client");
|
|
5
5
|
hatchet_client_1.hatchet.run('simple', { Message: 'Hello, World!' });
|
|
6
6
|
hatchet_client_1.hatchet.runNoWait('simple', { Message: 'Hello, World!' }, {});
|
|
7
|
-
hatchet_client_1.hatchet.
|
|
7
|
+
hatchet_client_1.hatchet.schedules.create('simple', {
|
|
8
8
|
triggerAt: new Date(Date.now() + 1000 * 60 * 60 * 24),
|
|
9
9
|
input: { Message: 'Hello, World!' },
|
|
10
10
|
});
|
|
11
|
-
hatchet_client_1.hatchet.
|
|
11
|
+
hatchet_client_1.hatchet.crons.create('simple', {
|
|
12
12
|
name: 'my-cron',
|
|
13
13
|
expression: '0 0 * * *',
|
|
14
14
|
input: { Message: 'Hello, World!' },
|
package/v1/task.d.ts
CHANGED
|
@@ -172,10 +172,10 @@ export type CreateStandaloneDurableTaskOpts<T, K> = CreateBaseTaskOpts<T, K, Dur
|
|
|
172
172
|
* @template T The input type for the task function.
|
|
173
173
|
* @template K The return type of the task function (can be inferred from the return value of fn).
|
|
174
174
|
*/
|
|
175
|
-
export type CreateOnSuccessTaskOpts<T, K> = CreateBaseTaskOpts<T, K, TaskFn<T, K
|
|
175
|
+
export type CreateOnSuccessTaskOpts<T, K> = Omit<CreateBaseTaskOpts<T, K, TaskFn<T, K>>, 'name'>;
|
|
176
176
|
/**
|
|
177
177
|
* Options for configuring the onFailure task that is invoked when a task fails.
|
|
178
178
|
* @template T The input type for the task function.
|
|
179
179
|
* @template K The return type of the task function (can be inferred from the return value of fn).
|
|
180
180
|
*/
|
|
181
|
-
export type CreateOnFailureTaskOpts<T, K> = CreateBaseTaskOpts<T, K, TaskFn<T, K
|
|
181
|
+
export type CreateOnFailureTaskOpts<T, K> = Omit<CreateBaseTaskOpts<T, K, TaskFn<T, K>>, 'name'>;
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.0.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.0.2";
|
package/version.js
CHANGED