@hatchet-dev/typescript-sdk 1.36.0 → 1.38.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/rest/generated/Api.d.ts +59 -1
- package/clients/rest/generated/Api.js +10 -0
- package/clients/rest/generated/data-contracts.d.ts +7 -0
- package/package.json +1 -1
- package/protoc/dispatcher/dispatcher.d.ts +4 -0
- package/protoc/dispatcher/dispatcher.js +42 -2
- package/protoc/v1/streams.d.ts +18 -0
- package/protoc/v1/streams.js +115 -1
- package/protoc-es/dispatcher/dispatcher_pb.d.ts +12 -0
- package/protoc-es/dispatcher/dispatcher_pb.js +1 -1
- package/protoc-es/v1/streams_pb.d.ts +35 -0
- package/protoc-es/v1/streams_pb.js +12 -2
- package/v1/client/duration.js +3 -3
- package/v1/client/features/streams.d.ts +10 -1
- package/v1/client/features/streams.js +15 -1
- package/v1/client/worker/engine-version.d.ts +2 -0
- package/v1/client/worker/engine-version.js +7 -0
- package/v1/client/worker/worker-internal.d.ts +2 -0
- package/v1/client/worker/worker-internal.js +20 -1
- package/v1/examples/durable-streams/run.d.ts +6 -0
- package/v1/examples/durable-streams/run.js +192 -0
- package/v1/examples/durable-streams/worker.d.ts +1 -0
- package/v1/examples/durable-streams/worker.js +24 -0
- package/v1/examples/durable-streams/workflow.d.ts +9 -0
- package/v1/examples/durable-streams/workflow.js +47 -0
- package/v1/examples/e2e-worker.js +59 -53
- package/v1/examples/retry_after/run.d.ts +1 -0
- package/v1/examples/retry_after/run.js +21 -0
- package/v1/examples/retry_after/worker.d.ts +1 -0
- package/v1/examples/retry_after/worker.js +24 -0
- package/v1/examples/retry_after/workflow.d.ts +9 -0
- package/v1/examples/retry_after/workflow.js +40 -0
- package/v1/task.d.ts +13 -0
- package/v1/task.js +14 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -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
|
+
exports.retryAfterExponentialBackoff = exports.retryAfterUpstreamDelay = void 0;
|
|
13
|
+
const task_1 = require("../../task");
|
|
14
|
+
const hatchet_client_1 = require("../hatchet-client");
|
|
15
|
+
// > Retry after an upstream-provided delay
|
|
16
|
+
exports.retryAfterUpstreamDelay = hatchet_client_1.hatchet.task({
|
|
17
|
+
name: 'retry-after-upstream-delay',
|
|
18
|
+
retries: 5,
|
|
19
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
if (ctx.retryCount() < input.failingAttempts) {
|
|
21
|
+
throw new task_1.RetryAfterError('upstream rate limited', { after: '2s' });
|
|
22
|
+
}
|
|
23
|
+
return { attempt: ctx.retryCount() };
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
// !!
|
|
27
|
+
// > Exponential backoff with full jitter
|
|
28
|
+
exports.retryAfterExponentialBackoff = hatchet_client_1.hatchet.task({
|
|
29
|
+
name: 'retry-after-exponential-backoff',
|
|
30
|
+
retries: 3,
|
|
31
|
+
fn: (input, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
if (ctx.retryCount() < input.failingAttempts) {
|
|
33
|
+
throw new task_1.RetryAfterError('upstream unavailable', {
|
|
34
|
+
after: Math.random() * Math.min(2 ** ctx.retryCount(), 60) * 1000,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return { attempt: ctx.retryCount() };
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
// !!
|
package/v1/task.d.ts
CHANGED
|
@@ -96,6 +96,19 @@ export type IdempotencyConfig = TTLBasedIdempotencyConfig | StatusBasedIdempoten
|
|
|
96
96
|
export declare class NonRetryableError extends Error {
|
|
97
97
|
constructor(message?: string);
|
|
98
98
|
}
|
|
99
|
+
export type RetryAfterOpts = {
|
|
100
|
+
/**
|
|
101
|
+
* The delay before the next attempt, e.g. `'90s'`, `{ minutes: 5 }`, or a number of milliseconds.
|
|
102
|
+
*/
|
|
103
|
+
after: Duration;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Throw from a task to retry it after a delay of its choosing. The retry counts against the task's `retries`.
|
|
107
|
+
*/
|
|
108
|
+
export declare class RetryAfterError extends Error {
|
|
109
|
+
readonly afterMs: number;
|
|
110
|
+
constructor(message: string | undefined, opts: RetryAfterOpts);
|
|
111
|
+
}
|
|
99
112
|
export type TaskFn<I extends InputType = UnknownInputType, O extends OutputType = void, C = Context<I>> = (input: I, ctx: C) => O | Promise<O>;
|
|
100
113
|
export type DurableTaskFn<I extends InputType = UnknownInputType, O extends OutputType = void> = TaskFn<I, O, DurableContext<I>>;
|
|
101
114
|
/**
|
package/v1/task.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NonRetryableError = exports.WorkerLabelComparator = exports.ConcurrencyLimitStrategy = void 0;
|
|
3
|
+
exports.RetryAfterError = exports.NonRetryableError = exports.WorkerLabelComparator = exports.ConcurrencyLimitStrategy = void 0;
|
|
4
4
|
const workflows_1 = require("../protoc/v1/workflows");
|
|
5
5
|
Object.defineProperty(exports, "ConcurrencyLimitStrategy", { enumerable: true, get: function () { return workflows_1.ConcurrencyLimitStrategy; } });
|
|
6
|
+
const duration_1 = require("./client/duration");
|
|
6
7
|
const trigger_1 = require("../protoc/v1/shared/trigger");
|
|
7
8
|
Object.defineProperty(exports, "WorkerLabelComparator", { enumerable: true, get: function () { return trigger_1.WorkerLabelComparator; } });
|
|
8
9
|
class NonRetryableError extends Error {
|
|
@@ -13,3 +14,15 @@ class NonRetryableError extends Error {
|
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
16
|
exports.NonRetryableError = NonRetryableError;
|
|
17
|
+
/**
|
|
18
|
+
* Throw from a task to retry it after a delay of its choosing. The retry counts against the task's `retries`.
|
|
19
|
+
*/
|
|
20
|
+
class RetryAfterError extends Error {
|
|
21
|
+
constructor(message, opts) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.name = 'RetryAfterError';
|
|
24
|
+
this.afterMs = Math.max(Math.round((0, duration_1.durationToMs)(opts.after)), 0);
|
|
25
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.RetryAfterError = RetryAfterError;
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HATCHET_VERSION = "1.
|
|
1
|
+
export declare const HATCHET_VERSION = "1.38.0";
|
package/version.js
CHANGED