@hatchet-dev/typescript-sdk 1.24.2 → 1.25.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/package.json +8 -7
- package/v1/client/client.d.ts +1 -3
- package/v1/client/client.js +2 -6
- package/v1/client/worker/worker-internal.d.ts +5 -0
- package/v1/client/worker/worker-internal.js +19 -2
- package/v1/declaration.d.ts +2 -2
- package/v1/examples/bulk_operations/cancel.d.ts +1 -0
- package/v1/examples/bulk_operations/cancel.js +52 -0
- package/v1/examples/concurrency_cancel_in_progress/workflow.js +2 -0
- package/v1/examples/concurrency_cancel_newest/workflow.js +2 -0
- package/v1/examples/dag_match_condition/complex-workflow.js +15 -0
- package/v1/examples/slot_cost/workflow.d.ts +2 -0
- package/v1/examples/slot_cost/workflow.js +29 -0
- package/v1/examples/timeout/worker.js +2 -0
- package/v1/task.d.ts +11 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hatchet-dev/typescript-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.25.0",
|
|
4
4
|
"description": "Background task orchestration & visibility for developers",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"@types/jest": "^29.5.14",
|
|
39
39
|
"@types/node": "^22.13.14",
|
|
40
40
|
"autoprefixer": "^10.4.27",
|
|
41
|
+
"postcss": "^8.5.10",
|
|
41
42
|
"dotenv-cli": "^7.4.4",
|
|
42
43
|
"eslint": "^10.0.3",
|
|
43
44
|
"eslint-config-prettier": "^10.1.8",
|
|
@@ -58,11 +59,11 @@
|
|
|
58
59
|
"@anthropic-ai/claude-agent-sdk": "^0.3.148",
|
|
59
60
|
"@grpc/grpc-js": "^1.14.3",
|
|
60
61
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
61
|
-
"@openai/agents": "0.
|
|
62
|
+
"@openai/agents": "0.12.1",
|
|
62
63
|
"@opentelemetry/api": "^1.9.0",
|
|
63
64
|
"@opentelemetry/core": "^2.0.0",
|
|
64
|
-
"@opentelemetry/exporter-trace-otlp-grpc": "^0.
|
|
65
|
-
"@opentelemetry/instrumentation": "^0.
|
|
65
|
+
"@opentelemetry/exporter-trace-otlp-grpc": "^0.220.0",
|
|
66
|
+
"@opentelemetry/instrumentation": "^0.220.0",
|
|
66
67
|
"@opentelemetry/sdk-trace-base": "^2.0.0",
|
|
67
68
|
"prom-client": "^15.1.3",
|
|
68
69
|
"typedoc": "^0.28.17",
|
|
@@ -90,11 +91,11 @@
|
|
|
90
91
|
"@anthropic-ai/claude-agent-sdk": "^0.3.148",
|
|
91
92
|
"@grpc/grpc-js": "^1.14.3",
|
|
92
93
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
93
|
-
"@openai/agents": "0.
|
|
94
|
+
"@openai/agents": "0.12.1",
|
|
94
95
|
"@opentelemetry/api": "^1.9.0",
|
|
95
96
|
"@opentelemetry/core": "^2.0.0",
|
|
96
|
-
"@opentelemetry/exporter-trace-otlp-grpc": "^0.
|
|
97
|
-
"@opentelemetry/instrumentation": "^0.
|
|
97
|
+
"@opentelemetry/exporter-trace-otlp-grpc": "^0.220.0",
|
|
98
|
+
"@opentelemetry/instrumentation": "^0.220.0",
|
|
98
99
|
"@opentelemetry/sdk-trace-base": "^2.0.0",
|
|
99
100
|
"prom-client": "^15.1.3"
|
|
100
101
|
},
|
package/v1/client/client.d.ts
CHANGED
|
@@ -46,8 +46,6 @@ export declare class HatchetClient<GlobalInput extends Record<string, any> = {},
|
|
|
46
46
|
/** The tenant ID for the Hatchet client */
|
|
47
47
|
tenantId: string;
|
|
48
48
|
logger: Logger;
|
|
49
|
-
_isV1: boolean | undefined;
|
|
50
|
-
get isV1(): boolean;
|
|
51
49
|
/**
|
|
52
50
|
* Creates a new Hatchet client instance.
|
|
53
51
|
* @param config - Optional configuration for the client
|
|
@@ -132,7 +130,7 @@ export declare class HatchetClient<GlobalInput extends Record<string, any> = {},
|
|
|
132
130
|
* @param options - Configuration options for the workflow run
|
|
133
131
|
* @returns A WorkflowRunRef containing the run ID and methods to interact with the run
|
|
134
132
|
*/
|
|
135
|
-
runNoWait<I extends InputType = UnknownInputType, O extends OutputType = void>(workflow: BaseWorkflowDeclaration<I, O> | LegacyWorkflow | string, input: I, options
|
|
133
|
+
runNoWait<I extends InputType = UnknownInputType, O extends OutputType = void>(workflow: BaseWorkflowDeclaration<I, O> | LegacyWorkflow | string, input: I, options?: RunOpts): Promise<WorkflowRunRef<O>>;
|
|
136
134
|
/**
|
|
137
135
|
* Triggers a workflow run and waits for the result.
|
|
138
136
|
* @template I - The input type for the workflow
|
package/v1/client/client.js
CHANGED
|
@@ -54,9 +54,6 @@ class HatchetClient {
|
|
|
54
54
|
}
|
|
55
55
|
return this._v0;
|
|
56
56
|
}
|
|
57
|
-
get isV1() {
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
57
|
/**
|
|
61
58
|
* Creates a new Hatchet client instance.
|
|
62
59
|
* @param config - Optional configuration for the client
|
|
@@ -66,7 +63,6 @@ class HatchetClient {
|
|
|
66
63
|
*/
|
|
67
64
|
constructor(config, options, axiosConfig) {
|
|
68
65
|
var _a;
|
|
69
|
-
this._isV1 = true;
|
|
70
66
|
try {
|
|
71
67
|
const loaded = config_loader_1.ConfigLoader.loadClientConfig(config, {
|
|
72
68
|
path: options === null || options === void 0 ? void 0 : options.config_path,
|
|
@@ -185,8 +181,8 @@ class HatchetClient {
|
|
|
185
181
|
* @param options - Configuration options for the workflow run
|
|
186
182
|
* @returns A WorkflowRunRef containing the run ID and methods to interact with the run
|
|
187
183
|
*/
|
|
188
|
-
runNoWait(
|
|
189
|
-
return __awaiter(this,
|
|
184
|
+
runNoWait(workflow_1, input_1) {
|
|
185
|
+
return __awaiter(this, arguments, void 0, function* (workflow, input, options = {}) {
|
|
190
186
|
const name = (0, legacy_transformer_1.getWorkflowName)(workflow);
|
|
191
187
|
return this.admin.runWorkflow(name, input, options);
|
|
192
188
|
});
|
|
@@ -87,6 +87,11 @@ export declare class InternalWorker {
|
|
|
87
87
|
handleAction(action: Action): Promise<void | Error>;
|
|
88
88
|
upsertLabels(labels: WorkerLabels): Promise<WorkerLabels>;
|
|
89
89
|
}
|
|
90
|
+
/** Durable tasks stay on the durable pool; slotCost applies only to the default pool. */
|
|
91
|
+
export declare function mapSlotRequestsPb(task: {
|
|
92
|
+
slotRequests?: Record<string, number>;
|
|
93
|
+
slotCost?: number;
|
|
94
|
+
}, isDurable: boolean): Record<string, number>;
|
|
90
95
|
export declare function mapRateLimitPb(limits: CreateWorkflowTaskOpts<any, any>['rateLimits']): CreateStepRateLimit[];
|
|
91
96
|
export declare function resolveExecutionTimeout(task: {
|
|
92
97
|
executionTimeout?: Duration;
|
|
@@ -53,6 +53,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
53
53
|
};
|
|
54
54
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
55
|
exports.InternalWorker = void 0;
|
|
56
|
+
exports.mapSlotRequestsPb = mapSlotRequestsPb;
|
|
56
57
|
exports.mapRateLimitPb = mapRateLimitPb;
|
|
57
58
|
exports.resolveExecutionTimeout = resolveExecutionTimeout;
|
|
58
59
|
exports.resolveScheduleTimeout = resolveScheduleTimeout;
|
|
@@ -206,7 +207,7 @@ class InternalWorker {
|
|
|
206
207
|
backoffFactor: ((_g = onFailure.backoff) === null || _g === void 0 ? void 0 : _g.factor) || ((_j = (_h = workflow.taskDefaults) === null || _h === void 0 ? void 0 : _h.backoff) === null || _j === void 0 ? void 0 : _j.factor),
|
|
207
208
|
backoffMaxSeconds: ((_k = onFailure.backoff) === null || _k === void 0 ? void 0 : _k.maxSeconds) || ((_m = (_l = workflow.taskDefaults) === null || _l === void 0 ? void 0 : _l.backoff) === null || _m === void 0 ? void 0 : _m.maxSeconds),
|
|
208
209
|
isDurable: false,
|
|
209
|
-
slotRequests:
|
|
210
|
+
slotRequests: mapSlotRequestsPb(onFailure, false),
|
|
210
211
|
};
|
|
211
212
|
}
|
|
212
213
|
let onSuccessTask;
|
|
@@ -316,7 +317,7 @@ class InternalWorker {
|
|
|
316
317
|
backoffMaxSeconds: ((_j = task.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),
|
|
317
318
|
conditions: (0, transformer_1.taskConditionsToPb)(task, this.client.config.namespace),
|
|
318
319
|
isDurable: durableTaskSet.has(task),
|
|
319
|
-
slotRequests: task
|
|
320
|
+
slotRequests: mapSlotRequestsPb(task, durableTaskSet.has(task)),
|
|
320
321
|
concurrency: task.concurrency
|
|
321
322
|
? Array.isArray(task.concurrency)
|
|
322
323
|
? task.concurrency
|
|
@@ -863,6 +864,22 @@ function getLeaves(tasks) {
|
|
|
863
864
|
function isLeafTask(task, allTasks) {
|
|
864
865
|
return !allTasks.some((t) => { var _a; return (_a = t.parents) === null || _a === void 0 ? void 0 : _a.some((p) => p.name === task.name); });
|
|
865
866
|
}
|
|
867
|
+
/** Durable tasks stay on the durable pool; slotCost applies only to the default pool. */
|
|
868
|
+
function mapSlotRequestsPb(task, isDurable) {
|
|
869
|
+
if (task.slotRequests) {
|
|
870
|
+
return task.slotRequests;
|
|
871
|
+
}
|
|
872
|
+
if (isDurable) {
|
|
873
|
+
return { durable: 1 };
|
|
874
|
+
}
|
|
875
|
+
if (task.slotCost !== undefined) {
|
|
876
|
+
if (!Number.isInteger(task.slotCost) || task.slotCost <= 0) {
|
|
877
|
+
throw new Error(`slotCost must be a positive integer, got: ${task.slotCost}`);
|
|
878
|
+
}
|
|
879
|
+
return { default: task.slotCost };
|
|
880
|
+
}
|
|
881
|
+
return { default: 1 };
|
|
882
|
+
}
|
|
866
883
|
function mapRateLimitPb(limits) {
|
|
867
884
|
if (!limits) {
|
|
868
885
|
return [];
|
package/v1/declaration.d.ts
CHANGED
|
@@ -425,7 +425,7 @@ export declare class WorkflowDeclaration<I extends InputType = UnknownInputType,
|
|
|
425
425
|
* @param options The task configuration options.
|
|
426
426
|
* @returns The task options that were added.
|
|
427
427
|
*/
|
|
428
|
-
task<Name extends string, Fn extends Name extends keyof O ? (input: I & MiddlewareBefore, ctx: Context<I & MiddlewareBefore>) => O[Name] extends OutputType ? O[Name] | Promise<O[Name]> : void : (input: I & MiddlewareBefore, ctx: Context<I & MiddlewareBefore>) => void, FnReturn = ReturnType<Fn> extends Promise<infer P> ? P : ReturnType<Fn>, TO extends OutputType = Name extends keyof O ? O[Name] extends OutputType ? O[Name] : never : FnReturn extends OutputType ? FnReturn : never>(options: (Omit<CreateWorkflowTaskOpts<I, TO>, 'fn'> & {
|
|
428
|
+
task<Name extends string, Fn extends (Name extends keyof O ? (input: I & MiddlewareBefore, ctx: Context<I & MiddlewareBefore>) => O[Name] extends OutputType ? O[Name] | Promise<O[Name]> : void : (input: I & MiddlewareBefore, ctx: Context<I & MiddlewareBefore>) => void), FnReturn = ReturnType<Fn> extends Promise<infer P> ? P : ReturnType<Fn>, TO extends OutputType = Name extends keyof O ? O[Name] extends OutputType ? O[Name] : never : FnReturn extends OutputType ? FnReturn : never>(options: (Omit<CreateWorkflowTaskOpts<I, TO>, 'fn'> & {
|
|
429
429
|
name: Name;
|
|
430
430
|
fn?: Fn;
|
|
431
431
|
}) | TaskWorkflowDeclaration<I, TO>): CreateWorkflowTaskOpts<I, TO>;
|
|
@@ -460,7 +460,7 @@ export declare class WorkflowDeclaration<I extends InputType = UnknownInputType,
|
|
|
460
460
|
* @param options The task configuration options.
|
|
461
461
|
* @returns The task options that were added.
|
|
462
462
|
*/
|
|
463
|
-
durableTask<Name extends string, Fn extends Name extends keyof O ? (input: I & MiddlewareBefore, ctx: DurableContext<I & MiddlewareBefore>) => O[Name] extends OutputType ? O[Name] | Promise<O[Name]> : void : (input: I & MiddlewareBefore, ctx: DurableContext<I & MiddlewareBefore>) => void, FnReturn = ReturnType<Fn> extends Promise<infer P> ? P : ReturnType<Fn>, TO extends OutputType = Name extends keyof O ? O[Name] extends OutputType ? O[Name] : never : FnReturn extends OutputType ? FnReturn : never>(options: Omit<CreateWorkflowTaskOpts<I, TO>, 'fn'> & {
|
|
463
|
+
durableTask<Name extends string, Fn extends (Name extends keyof O ? (input: I & MiddlewareBefore, ctx: DurableContext<I & MiddlewareBefore>) => O[Name] extends OutputType ? O[Name] | Promise<O[Name]> : void : (input: I & MiddlewareBefore, ctx: DurableContext<I & MiddlewareBefore>) => void), FnReturn = ReturnType<Fn> extends Promise<infer P> ? P : ReturnType<Fn>, TO extends OutputType = Name extends keyof O ? O[Name] extends OutputType ? O[Name] : never : FnReturn extends OutputType ? FnReturn : never>(options: Omit<CreateWorkflowTaskOpts<I, TO>, 'fn' | 'slotCost'> & {
|
|
464
464
|
name: Name;
|
|
465
465
|
fn: Fn;
|
|
466
466
|
}): CreateWorkflowDurableTaskOpts<I, TO>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
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 data_contracts_1 = require("../../../clients/rest/generated/data-contracts");
|
|
13
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
14
|
+
function main() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
var _a, _b, _c;
|
|
17
|
+
// > Setup
|
|
18
|
+
const workflows = yield hatchet_client_1.hatchet.workflows.list();
|
|
19
|
+
if (!((_a = workflows.rows) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
20
|
+
throw new Error('no workflows found');
|
|
21
|
+
}
|
|
22
|
+
const [workflow] = workflows.rows;
|
|
23
|
+
// !!
|
|
24
|
+
// > List runs
|
|
25
|
+
const workflowRuns = yield hatchet_client_1.hatchet.runs.list({
|
|
26
|
+
workflowNames: [workflow.name],
|
|
27
|
+
});
|
|
28
|
+
// !!
|
|
29
|
+
// > Cancel by run ids
|
|
30
|
+
const runIds = (_c = (_b = workflowRuns.rows) === null || _b === void 0 ? void 0 : _b.map((run) => run.metadata.id)) !== null && _c !== void 0 ? _c : [];
|
|
31
|
+
// to replay runs by their ids, use `hatchet.runs.replay` instead
|
|
32
|
+
yield hatchet_client_1.hatchet.runs.cancel({ ids: runIds });
|
|
33
|
+
// !!
|
|
34
|
+
// > Cancel by filters
|
|
35
|
+
// to replay runs matching filters, use `hatchet.runs.replay` instead
|
|
36
|
+
yield hatchet_client_1.hatchet.runs.cancel({
|
|
37
|
+
filters: {
|
|
38
|
+
since: new Date(Date.now() - 24 * 60 * 60 * 1000),
|
|
39
|
+
until: new Date(),
|
|
40
|
+
statuses: [data_contracts_1.V1TaskStatus.RUNNING],
|
|
41
|
+
workflowNames: [workflow.name],
|
|
42
|
+
additionalMetadata: { key: 'value' },
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
// !!
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (require.main === module) {
|
|
49
|
+
main()
|
|
50
|
+
.catch(console.error)
|
|
51
|
+
.finally(() => process.exit(0));
|
|
52
|
+
}
|
|
@@ -16,6 +16,7 @@ exports.concurrencyCancelInProgressWorkflow = void 0;
|
|
|
16
16
|
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
17
17
|
const v1_1 = require("../..");
|
|
18
18
|
const hatchet_client_1 = require("../hatchet-client");
|
|
19
|
+
// > Cancel In Progress
|
|
19
20
|
exports.concurrencyCancelInProgressWorkflow = hatchet_client_1.hatchet.workflow({
|
|
20
21
|
name: 'concurrencycancelinprogress',
|
|
21
22
|
concurrency: {
|
|
@@ -24,6 +25,7 @@ exports.concurrencyCancelInProgressWorkflow = hatchet_client_1.hatchet.workflow(
|
|
|
24
25
|
limitStrategy: v1_1.ConcurrencyLimitStrategy.CANCEL_IN_PROGRESS,
|
|
25
26
|
},
|
|
26
27
|
});
|
|
28
|
+
// !!
|
|
27
29
|
const step1 = exports.concurrencyCancelInProgressWorkflow.task({
|
|
28
30
|
name: 'step1',
|
|
29
31
|
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -16,6 +16,7 @@ exports.concurrencyCancelNewestWorkflow = void 0;
|
|
|
16
16
|
const sleep_1 = __importDefault(require("../../../util/sleep"));
|
|
17
17
|
const v1_1 = require("../..");
|
|
18
18
|
const hatchet_client_1 = require("../hatchet-client");
|
|
19
|
+
// > Cancel Newest
|
|
19
20
|
exports.concurrencyCancelNewestWorkflow = hatchet_client_1.hatchet.workflow({
|
|
20
21
|
name: 'concurrencycancelnewest',
|
|
21
22
|
concurrency: {
|
|
@@ -24,6 +25,7 @@ exports.concurrencyCancelNewestWorkflow = hatchet_client_1.hatchet.workflow({
|
|
|
24
25
|
limitStrategy: v1_1.ConcurrencyLimitStrategy.CANCEL_NEWEST,
|
|
25
26
|
},
|
|
26
27
|
});
|
|
28
|
+
// !!
|
|
27
29
|
const step1 = exports.concurrencyCancelNewestWorkflow.task({
|
|
28
30
|
name: 'step1',
|
|
29
31
|
fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -87,6 +87,21 @@ const waitForEvent = exports.taskConditionWorkflow.task({
|
|
|
87
87
|
},
|
|
88
88
|
});
|
|
89
89
|
// !!
|
|
90
|
+
// > Add multiple or groups
|
|
91
|
+
exports.taskConditionWorkflow.task({
|
|
92
|
+
name: 'waitForOrGroups',
|
|
93
|
+
parents: [start],
|
|
94
|
+
waitFor: [
|
|
95
|
+
(0, conditions_1.Or)(new parent_condition_1.ParentCondition(start, 'output.randomNumber > 50'), new conditions_1.SleepCondition('30s')),
|
|
96
|
+
(0, conditions_1.Or)(new parent_condition_1.ParentCondition(start, 'output.randomNumber > 50'), new conditions_1.UserEventCondition('payment:processed', 'true')),
|
|
97
|
+
],
|
|
98
|
+
fn: () => {
|
|
99
|
+
return {
|
|
100
|
+
randomNumber: Math.floor(Math.random() * 100) + 1,
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
// !!
|
|
90
105
|
// > Add sum
|
|
91
106
|
exports.taskConditionWorkflow.task({
|
|
92
107
|
name: 'sum',
|
|
@@ -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
|
+
exports.weenie = exports.omega = void 0;
|
|
13
|
+
// > Slot cost
|
|
14
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
15
|
+
exports.omega = hatchet_client_1.hatchet.task({
|
|
16
|
+
name: 'omega',
|
|
17
|
+
slotCost: 5,
|
|
18
|
+
fn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
console.log('heavy work');
|
|
20
|
+
}),
|
|
21
|
+
});
|
|
22
|
+
exports.weenie = hatchet_client_1.hatchet.task({
|
|
23
|
+
name: 'weenie',
|
|
24
|
+
slotCost: 1,
|
|
25
|
+
fn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
console.log('light work');
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
// !!
|
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const hatchet_client_1 = require("../hatchet-client");
|
|
13
13
|
const workflow_1 = require("./workflow");
|
|
14
|
+
// > Slots
|
|
14
15
|
function main() {
|
|
15
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
17
|
const worker = yield hatchet_client_1.hatchet.worker('timeout-worker', {
|
|
@@ -20,6 +21,7 @@ function main() {
|
|
|
20
21
|
yield worker.start();
|
|
21
22
|
});
|
|
22
23
|
}
|
|
24
|
+
// !!
|
|
23
25
|
if (require.main === module) {
|
|
24
26
|
main();
|
|
25
27
|
}
|
package/v1/task.d.ts
CHANGED
|
@@ -120,6 +120,16 @@ export type CreateBaseTaskOpts<I extends InputType = UnknownInputType, O extends
|
|
|
120
120
|
* (optional) the concurrency options for the task
|
|
121
121
|
*/
|
|
122
122
|
concurrency?: Concurrency | Concurrency[];
|
|
123
|
+
/**
|
|
124
|
+
* (optional) the number of default worker slots this task consumes.
|
|
125
|
+
*
|
|
126
|
+
* A worker has a fixed number of slots (default 100), and a normal task consumes one. Set slotCost
|
|
127
|
+
* higher for a task that needs more memory or CPU, so a worker runs fewer of them at once. A single
|
|
128
|
+
* worker must have that many free slots to run it. Not available on durable tasks.
|
|
129
|
+
*
|
|
130
|
+
* default: 1
|
|
131
|
+
*/
|
|
132
|
+
slotCost?: number;
|
|
123
133
|
/** @internal */
|
|
124
134
|
slotRequests?: Record<string, number>;
|
|
125
135
|
};
|
|
@@ -187,7 +197,7 @@ export type CreateWorkflowTaskOpts<I extends InputType = UnknownInputType, O ext
|
|
|
187
197
|
* @template I The input type for the task function.
|
|
188
198
|
* @template O The return type of the task function (can be inferred from the return value of fn).
|
|
189
199
|
*/
|
|
190
|
-
export type CreateWorkflowDurableTaskOpts<I extends InputType = UnknownInputType, O extends OutputType = void, C extends DurableTaskFn<I, O> = DurableTaskFn<I, O>> = CreateWorkflowTaskOpts<I, O, C> & {
|
|
200
|
+
export type CreateWorkflowDurableTaskOpts<I extends InputType = UnknownInputType, O extends OutputType = void, C extends DurableTaskFn<I, O> = DurableTaskFn<I, O>> = Omit<CreateWorkflowTaskOpts<I, O, C>, 'slotCost'> & {
|
|
191
201
|
/**
|
|
192
202
|
* Eviction policy for the durable task. Controls TTL-based eviction and capacity-based eviction.
|
|
193
203
|
* Defaults to the built-in eviction policy when omitted or `undefined`.
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.25.0";
|
package/version.js
CHANGED