@yieldkit/jobs 0.0.0-stage → 0.1.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 (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +307 -2
  3. package/dist/_virtual/_rolldown/runtime.js +12 -0
  4. package/dist/activity.d.ts +81 -0
  5. package/dist/activity.js +151 -0
  6. package/dist/calendar.d.ts +33 -0
  7. package/dist/calendar.js +205 -0
  8. package/dist/cluster.d.ts +54 -0
  9. package/dist/cluster.js +115 -0
  10. package/dist/cron.d.ts +21 -0
  11. package/dist/cron.js +80 -0
  12. package/dist/dispatch.d.ts +97 -0
  13. package/dist/dispatch.js +140 -0
  14. package/dist/errors.d.ts +194 -0
  15. package/dist/errors.js +132 -0
  16. package/dist/index.d.ts +22 -0
  17. package/dist/index.js +22 -0
  18. package/dist/job.d.ts +306 -0
  19. package/dist/job.js +45 -0
  20. package/dist/ledger-memory.d.ts +64 -0
  21. package/dist/ledger-memory.js +246 -0
  22. package/dist/ledger-retry.js +21 -0
  23. package/dist/ledger-sql-deadline.js +39 -0
  24. package/dist/ledger-sql.d.ts +5 -0
  25. package/dist/ledger-sql.js +332 -0
  26. package/dist/ledger-types.d.ts +340 -0
  27. package/dist/ledger-types.js +71 -0
  28. package/dist/ledger.d.ts +51 -0
  29. package/dist/ledger.js +66 -0
  30. package/dist/logging.d.ts +83 -0
  31. package/dist/logging.js +117 -0
  32. package/dist/maintenance.d.ts +6 -0
  33. package/dist/maintenance.js +115 -0
  34. package/dist/metrics.d.ts +14 -0
  35. package/dist/metrics.js +35 -0
  36. package/dist/migrations.d.ts +21 -0
  37. package/dist/migrations.js +194 -0
  38. package/dist/omit-undefined.js +10 -0
  39. package/dist/params.d.ts +58 -0
  40. package/dist/params.js +97 -0
  41. package/dist/policy.d.ts +225 -0
  42. package/dist/policy.js +247 -0
  43. package/dist/probe.js +67 -0
  44. package/dist/requests-memory.d.ts +36 -0
  45. package/dist/requests-memory.js +142 -0
  46. package/dist/requests.d.ts +195 -0
  47. package/dist/requests.js +242 -0
  48. package/dist/run-key.d.ts +25 -0
  49. package/dist/run-key.js +85 -0
  50. package/dist/run-support.js +212 -0
  51. package/dist/run.d.ts +163 -0
  52. package/dist/run.js +258 -0
  53. package/dist/scheduler.d.ts +56 -0
  54. package/dist/scheduler.js +227 -0
  55. package/dist/settle-hook.d.ts +3 -0
  56. package/dist/settle-hook.js +33 -0
  57. package/dist/storage-options.d.ts +25 -0
  58. package/dist/storage-options.js +60 -0
  59. package/dist/storage.d.ts +53 -0
  60. package/dist/storage.js +75 -0
  61. package/dist/testing/index.d.ts +4 -0
  62. package/dist/testing/index.js +4 -0
  63. package/dist/time-zone.js +83 -0
  64. package/dist/workflow-activities.js +227 -0
  65. package/dist/workflow-retry.js +80 -0
  66. package/dist/workflow-schema.d.ts +207 -0
  67. package/dist/workflow-schema.js +360 -0
  68. package/dist/workflow-settle.js +234 -0
  69. package/dist/workflow.d.ts +17 -0
  70. package/dist/workflow.js +202 -0
  71. package/docs/deployment.md +167 -0
  72. package/docs/jobs.md +200 -0
  73. package/docs/logs-and-metrics.md +129 -0
  74. package/docs/migrations.md +66 -0
  75. package/docs/policy.md +75 -0
  76. package/docs/scheduling.md +149 -0
  77. package/docs/storage.md +138 -0
  78. package/docs/testing.md +144 -0
  79. package/docs/workers-and-clients.md +100 -0
  80. package/package.json +82 -3
@@ -0,0 +1,140 @@
1
+ import { InvalidDispatch, InvalidRunKey } from "./errors.js";
2
+ import { omitUndefined } from "./omit-undefined.js";
3
+ import { decodeJobParams, pickApiParams } from "./params.js";
4
+ import { JobRequests } from "./requests.js";
5
+ import { resolveCallerRunKey, resolveRunKey } from "./run-key.js";
6
+ import { makeJobWorkflow } from "./workflow-schema.js";
7
+ import { Cause, Clock, DateTime, Duration, Effect, Option, Predicate } from "effect";
8
+ import { SecureRandom } from "effect/crypto";
9
+ import { describeError, logWarning, redactLogString } from "@yieldkit/logger";
10
+ // src/dispatch.ts
11
+ /**
12
+ * Starts a job for an external caller: keeps only the params `apiParams` allows, records a request
13
+ * row linked to the workflow's deterministic `executionId`, and dispatches the durable workflow
14
+ * with `trigger: 'api'` without waiting for it. If dispatch fails, the row is marked failed unless
15
+ * a worker already picked it up; the worker can still finish it if the workflow did start. An
16
+ * interrupted dispatch leaves the row pending. The request id is a UUIDv4 drawn from
17
+ * `SecureRandom`. Check `isApiRequestable` and `findDisallowedApiParams` before calling it. An
18
+ * `OnDemand` job fails with `InvalidRunKey`: start it with `dispatchJob`. An invalid cadence fails
19
+ * with `ClusterConfigError` before anything is recorded. Params that do not decode over the job's
20
+ * defaults fail with `InvalidJobParams` before anything is recorded.
21
+ */
22
+ const dispatchApiJobWorkflow = Effect.fn("dispatchApiJobWorkflow")(function* (definition, options) {
23
+ const requests = yield* JobRequests;
24
+ const random = yield* SecureRandom.SecureRandom;
25
+ const workflow = makeJobWorkflow(definition);
26
+ const nowMs = yield* Clock.currentTimeMillis;
27
+ const runKey = yield* resolveRunKey(definition, nowMs, void 0);
28
+ const allowedParams = pickApiParams(definition, options.params);
29
+ yield* decodeJobParams(definition, allowedParams);
30
+ const requestId = yield* random.uuidV4();
31
+ const payload = {
32
+ runKey,
33
+ trigger: "api",
34
+ params: allowedParams,
35
+ force: options.force,
36
+ requestId,
37
+ attemptNonce: requestId
38
+ };
39
+ const executionId = yield* workflow.executionId(payload);
40
+ yield* requests.create({
41
+ id: requestId,
42
+ job: definition.name,
43
+ params: allowedParams,
44
+ force: options.force,
45
+ executionId
46
+ });
47
+ yield* workflow.execute(payload, { discard: true }).pipe(Effect.onError((cause) => Cause.hasInterruptsOnly(cause) ? Effect.void : requests.markDispatchFailed({
48
+ id: requestId,
49
+ job: definition.name,
50
+ errorMessage: redactLogString(describeError(Cause.squash(cause)))
51
+ }).pipe(Effect.catch((error) => logWarning("job.dispatch.record_failed", {
52
+ job: definition.name,
53
+ requestId,
54
+ errorMessage: describeError(error)
55
+ })))));
56
+ return {
57
+ requestId,
58
+ executionId
59
+ };
60
+ });
61
+ /**
62
+ * Milliseconds of a `delay`, or `undefined` unless it is a finite duration of zero or more. A
63
+ * number, and each number among the own values of an object or tuple, is checked before decoding,
64
+ * since `Duration.fromInput` reads `NaN` as zero.
65
+ */
66
+ const delayMillis = (delay) => {
67
+ if ((Predicate.isObjectOrArray(delay) ? Object.values(delay) : [delay]).some((part) => typeof part === "number" && !Number.isFinite(part))) return;
68
+ const decoded = Duration.fromInput(delay);
69
+ if (Option.isNone(decoded) || !Duration.isFinite(decoded.value)) return;
70
+ const millis = Duration.toMillis(decoded.value);
71
+ return millis >= 0 ? millis : void 0;
72
+ };
73
+ /**
74
+ * Epoch milliseconds of `options.runAt`, else of `delay` after `nowMs`, else `undefined`. Fails
75
+ * with `InvalidDispatch` for a `delay` that is not a finite duration of zero or more, or an instant
76
+ * that is not a valid date.
77
+ */
78
+ const runAtMillis = (job, options, nowMs) => {
79
+ if (options.runAt === void 0 && options.delay === void 0) return Effect.undefined;
80
+ const delay = options.delay === void 0 ? void 0 : delayMillis(options.delay);
81
+ if (options.runAt === void 0 && delay === void 0) return Effect.fail(new InvalidDispatch({
82
+ job,
83
+ message: "delay must be a finite duration of zero or more."
84
+ }));
85
+ const runAtMs = options.runAt === void 0 ? nowMs + (delay ?? 0) : epochMillisOf(options.runAt);
86
+ return runAtMs !== void 0 && Option.isSome(DateTime.make(runAtMs)) ? Effect.succeed(runAtMs) : Effect.fail(new InvalidDispatch({
87
+ job,
88
+ message: "runAt must be a valid date."
89
+ }));
90
+ };
91
+ /**
92
+ * Epoch milliseconds of `runAt`, or `undefined` when it is not a `DateTime` holding a valid date.
93
+ */
94
+ const epochMillisOf = (runAt) => {
95
+ if (!DateTime.isDateTime(runAt)) return;
96
+ const ms = DateTime.toEpochMillis(runAt);
97
+ return Number.isFinite(ms) ? ms : void 0;
98
+ };
99
+ /**
100
+ * Starts a run of an `OnDemand` job under a caller-chosen run key, optionally delayed, and returns
101
+ * without waiting for it. The workflow runs on a worker even if the caller exits. Each key is one
102
+ * execution: dispatching it again, with any params, joins that execution instead of starting
103
+ * another, so a retried request does not run the job twice. A failed run retries with backoff
104
+ * (`retry.onDemandBase` to `retry.onDemandCap`) up to `retry.onDemandMaxFailures` failures; after
105
+ * that, `runJob` with `trigger: 'manual'` and the same key runs it again. Runs carry `trigger:
106
+ * 'schedule'`.
107
+ *
108
+ * Fails with `InvalidRunKey` for a job that is not `OnDemand` or a malformed key, with
109
+ * `InvalidJobParams` when the params do not decode, and with `InvalidDispatch` for a `delay` that
110
+ * is not a finite duration of zero or more or a `runAt` that is not a valid date, all before
111
+ * anything is dispatched.
112
+ */
113
+ const dispatchJob = Effect.fn("dispatchJob")(function* (definition, options) {
114
+ if (definition.cadence._tag !== "OnDemand") return yield* new InvalidRunKey({
115
+ job: definition.name,
116
+ message: `dispatchJob starts OnDemand jobs only; "${definition.name}" has a ${definition.cadence._tag} cadence.`
117
+ });
118
+ const nowMs = yield* Clock.currentTimeMillis;
119
+ const runKey = yield* resolveCallerRunKey(definition.name, options.runKey);
120
+ const params = options.params ?? {};
121
+ yield* decodeJobParams(definition, params);
122
+ const runAtMs = yield* runAtMillis(definition.name, options, nowMs);
123
+ const payload = omitUndefined({
124
+ runKey,
125
+ trigger: "schedule",
126
+ params,
127
+ force: false,
128
+ requestId: null,
129
+ attemptNonce: null,
130
+ runAt: runAtMs !== void 0 && runAtMs > nowMs ? DateTime.formatIso(DateTime.makeUnsafe(runAtMs)) : void 0
131
+ });
132
+ const workflow = makeJobWorkflow(definition);
133
+ const executionId = yield* workflow.executionId(payload);
134
+ yield* workflow.execute(payload, { discard: true });
135
+ return {
136
+ runKey,
137
+ executionId
138
+ };
139
+ });
140
+ export { dispatchApiJobWorkflow, dispatchJob };
@@ -0,0 +1,194 @@
1
+ import { Schema } from "effect";
2
+ declare const InvalidJobParams_base: Schema.Class<InvalidJobParams, Schema.TaggedStruct<"InvalidJobParams", {
3
+ /**
4
+ * Name of the job whose parameters failed validation.
5
+ */
6
+ readonly job: Schema.String;
7
+ /**
8
+ * Human-readable summary listing the schema or flag validation issues.
9
+ */
10
+ readonly message: Schema.String;
11
+ }>, import("effect/Cause").YieldableError & {
12
+ /**
13
+ * Nominal marker: only values built by this class's constructor satisfy the type, never a
14
+ * structurally similar object.
15
+ */
16
+ readonly brand: unique symbol;
17
+ }>;
18
+ /**
19
+ * Raised before a run is claimed when param overrides (from `runJob`, the scheduler's `params` or
20
+ * an API request) fail validation against the job's `params.schema`, or when `parseSetFlags` gets a
21
+ * malformed `key=value` flag.
22
+ */
23
+ export declare class InvalidJobParams extends InvalidJobParams_base {}
24
+ declare const InvalidRunKey_base: Schema.Class<InvalidRunKey, Schema.TaggedStruct<"InvalidRunKey", {
25
+ /**
26
+ * Name of the job.
27
+ */
28
+ readonly job: Schema.String;
29
+ /**
30
+ * What is wrong with the run key.
31
+ */
32
+ readonly message: Schema.String;
33
+ }>, import("effect/Cause").YieldableError & {
34
+ /**
35
+ * Nominal marker: only values built by this class's constructor satisfy the type, never a
36
+ * structurally similar object.
37
+ */
38
+ readonly brand: unique symbol;
39
+ }>;
40
+ /**
41
+ * Raised before anything is dispatched or claimed when a caller-chosen run key is missing,
42
+ * malformed, or given for a job whose run keys come from its cadence. Only `OnDemand` jobs take a
43
+ * run key, and they always need one.
44
+ */
45
+ export declare class InvalidRunKey extends InvalidRunKey_base {}
46
+ declare const InvalidDispatch_base: Schema.Class<InvalidDispatch, Schema.TaggedStruct<"InvalidDispatch", {
47
+ /**
48
+ * Name of the job.
49
+ */
50
+ readonly job: Schema.String;
51
+ /**
52
+ * What is wrong with the dispatch options.
53
+ */
54
+ readonly message: Schema.String;
55
+ }>, import("effect/Cause").YieldableError & {
56
+ /**
57
+ * Nominal marker: only values built by this class's constructor satisfy the type, never a
58
+ * structurally similar object.
59
+ */
60
+ readonly brand: unique symbol;
61
+ }>;
62
+ /**
63
+ * Raised by `dispatchJob` before anything is dispatched when `delay` is not a finite duration of
64
+ * zero or more, or `runAt` (or the instant `delay` after now) is not a valid date.
65
+ */
66
+ export declare class InvalidDispatch extends InvalidDispatch_base {}
67
+ declare const DryRunUnsupported_base: Schema.Class<DryRunUnsupported, Schema.TaggedStruct<"DryRunUnsupported", {
68
+ /**
69
+ * Name of the job that lacks a `dryRun` layer.
70
+ */
71
+ readonly job: Schema.String;
72
+ }>, import("effect/Cause").YieldableError & {
73
+ /**
74
+ * Nominal marker: only values built by this class's constructor satisfy the type, never a
75
+ * structurally similar object.
76
+ */
77
+ readonly brand: unique symbol;
78
+ }>;
79
+ /**
80
+ * Raised when `dryRun: true` is requested for a job that does not declare a `dryRun` layer.
81
+ */
82
+ export declare class DryRunUnsupported extends DryRunUnsupported_base {}
83
+ /**
84
+ * `_tag` of `RunClaimLost`, also written as the `errorTag` of outcomes for runs that lost their
85
+ * claim (including a fenced settle that found another owner, where no `RunClaimLost` is raised).
86
+ * Compare against this rather than a string literal.
87
+ */
88
+ export declare const RUN_CLAIM_LOST_TAG = "RunClaimLost";
89
+ declare const RunClaimLost_base: Schema.Class<RunClaimLost, Schema.TaggedStruct<"RunClaimLost", {
90
+ /**
91
+ * Job name whose claim was lost.
92
+ */
93
+ readonly job: Schema.String;
94
+ /**
95
+ * Ledger run key whose claim was lost.
96
+ */
97
+ readonly runKey: Schema.String;
98
+ }>, import("effect/Cause").YieldableError & {
99
+ /**
100
+ * Nominal marker: only values built by this class's constructor satisfy the type, never a
101
+ * structurally similar object.
102
+ */
103
+ readonly brand: unique symbol;
104
+ }>;
105
+ /**
106
+ * Raised when an active run loses ownership of its `(job, run_key)` lease—either because a
107
+ * heartbeat returned `false` or failed for a full lease duration.
108
+ */
109
+ export declare class RunClaimLost extends RunClaimLost_base {}
110
+ /**
111
+ * Redacted failure summary recorded on the ledger, the outcome and the request when a run loses its
112
+ * `(job, run_key)` claim, whether a heartbeat lost it or a fenced settle found another owner.
113
+ */
114
+ export declare const RUN_CLAIM_LOST_MESSAGE = "lost its run claim";
115
+ declare const UnknownJobError_base: Schema.Class<UnknownJobError, Schema.TaggedStruct<"UnknownJobError", {
116
+ /**
117
+ * Unknown job names passed in `only`.
118
+ */
119
+ readonly names: Schema.$Array<Schema.String>;
120
+ }>, import("effect/Cause").YieldableError & {
121
+ /**
122
+ * Nominal marker: only values built by this class's constructor satisfy the type, never a
123
+ * structurally similar object.
124
+ */
125
+ readonly brand: unique symbol;
126
+ }>;
127
+ /**
128
+ * Raised when the scheduler's `only` option names one or more jobs that are not in its job list.
129
+ */
130
+ export declare class UnknownJobError extends UnknownJobError_base {}
131
+ declare const ClusterConfigError_base: Schema.Class<ClusterConfigError, Schema.TaggedStruct<"ClusterConfigError", {
132
+ /**
133
+ * Human-readable explanation of the configuration error.
134
+ */
135
+ readonly message: Schema.String;
136
+ }>, import("effect/Cause").YieldableError & {
137
+ /**
138
+ * Nominal marker: only values built by this class's constructor satisfy the type, never a
139
+ * structurally similar object.
140
+ */
141
+ readonly brand: unique symbol;
142
+ }>;
143
+ /**
144
+ * Raised when cluster, schedule or policy configuration is invalid: a `ShardingConfig` that lacks
145
+ * or misassigns a shard group the jobs need, a job name too long for Cluster's shard ids, a cadence
146
+ * interval that does not divide an hour or a day, a policy duration that is not positive or a count
147
+ * that is not a positive integer.
148
+ */
149
+ export declare class ClusterConfigError extends ClusterConfigError_base {}
150
+ /**
151
+ * Which migration history `JobsNotMigratedError` found behind. The library only checks its own;
152
+ * your Cluster's storage is yours to migrate and check.
153
+ */
154
+ export declare const JobsStorageComponent: Schema.Literals<readonly ["jobs"]>;
155
+ /**
156
+ * A migration history checked by the runtime layers.
157
+ */
158
+ export type JobsStorageComponent = typeof JobsStorageComponent.Type;
159
+ declare const JobsNotMigratedError_base: Schema.Class<JobsNotMigratedError, Schema.TaggedStruct<"JobsNotMigratedError", {
160
+ /**
161
+ * Which migration history is behind.
162
+ */
163
+ readonly component: Schema.Literals<readonly ["jobs"]>;
164
+ /**
165
+ * History table that was checked, as written in SQL (schema-qualified for the library's own).
166
+ */
167
+ readonly table: Schema.String;
168
+ /**
169
+ * Highest migration id recorded in the history, `0` when the table does not exist.
170
+ */
171
+ readonly found: Schema.Int;
172
+ /**
173
+ * Highest migration id the installed code ships.
174
+ */
175
+ readonly expected: Schema.Int;
176
+ /**
177
+ * Operator message naming the table and pointing at `migrate()`.
178
+ */
179
+ readonly message: Schema.String;
180
+ }>, import("effect/Cause").YieldableError & {
181
+ /**
182
+ * Nominal marker: only values built by this class's constructor satisfy the type, never a
183
+ * structurally similar object.
184
+ */
185
+ readonly brand: unique symbol;
186
+ }>;
187
+ /**
188
+ * Raised when a runtime layer starts against a database whose tables are missing or older than the
189
+ * installed code expects. Run `JobStorage.layerMigrations` (or `Migrator` with
190
+ * `JobStorage.migrations`) before starting workers and clients. A newer history than the code knows
191
+ * is accepted.
192
+ */
193
+ export declare class JobsNotMigratedError extends JobsNotMigratedError_base {}
194
+ export {};
package/dist/errors.js ADDED
@@ -0,0 +1,132 @@
1
+ import { Schema } from "effect";
2
+ // src/errors.ts
3
+ /**
4
+ * Raised before a run is claimed when param overrides (from `runJob`, the scheduler's `params` or
5
+ * an API request) fail validation against the job's `params.schema`, or when `parseSetFlags` gets a
6
+ * malformed `key=value` flag.
7
+ */
8
+ var InvalidJobParams = class extends Schema.TaggedError()("InvalidJobParams", {
9
+ /**
10
+ * Name of the job whose parameters failed validation.
11
+ */
12
+ job: Schema.String,
13
+ /**
14
+ * Human-readable summary listing the schema or flag validation issues.
15
+ */
16
+ message: Schema.String
17
+ }) {};
18
+ /**
19
+ * Raised before anything is dispatched or claimed when a caller-chosen run key is missing,
20
+ * malformed, or given for a job whose run keys come from its cadence. Only `OnDemand` jobs take a
21
+ * run key, and they always need one.
22
+ */
23
+ var InvalidRunKey = class extends Schema.TaggedError()("InvalidRunKey", {
24
+ /**
25
+ * Name of the job.
26
+ */
27
+ job: Schema.String,
28
+ /**
29
+ * What is wrong with the run key.
30
+ */
31
+ message: Schema.String
32
+ }) {};
33
+ /**
34
+ * Raised by `dispatchJob` before anything is dispatched when `delay` is not a finite duration of
35
+ * zero or more, or `runAt` (or the instant `delay` after now) is not a valid date.
36
+ */
37
+ var InvalidDispatch = class extends Schema.TaggedError()("InvalidDispatch", {
38
+ /**
39
+ * Name of the job.
40
+ */
41
+ job: Schema.String,
42
+ /**
43
+ * What is wrong with the dispatch options.
44
+ */
45
+ message: Schema.String
46
+ }) {};
47
+ /**
48
+ * Raised when `dryRun: true` is requested for a job that does not declare a `dryRun` layer.
49
+ */
50
+ var DryRunUnsupported = class extends Schema.TaggedError()("DryRunUnsupported", {
51
+ /**
52
+ * Name of the job that lacks a `dryRun` layer.
53
+ */
54
+ job: Schema.String }) {};
55
+ /**
56
+ * `_tag` of `RunClaimLost`, also written as the `errorTag` of outcomes for runs that lost their
57
+ * claim (including a fenced settle that found another owner, where no `RunClaimLost` is raised).
58
+ * Compare against this rather than a string literal.
59
+ */
60
+ const RUN_CLAIM_LOST_TAG = "RunClaimLost";
61
+ /**
62
+ * Raised when an active run loses ownership of its `(job, run_key)` lease—either because a
63
+ * heartbeat returned `false` or failed for a full lease duration.
64
+ */
65
+ var RunClaimLost = class extends Schema.TaggedError()(RUN_CLAIM_LOST_TAG, {
66
+ /**
67
+ * Job name whose claim was lost.
68
+ */
69
+ job: Schema.String,
70
+ /**
71
+ * Ledger run key whose claim was lost.
72
+ */
73
+ runKey: Schema.String
74
+ }) {};
75
+ /**
76
+ * Redacted failure summary recorded on the ledger, the outcome and the request when a run loses its
77
+ * `(job, run_key)` claim, whether a heartbeat lost it or a fenced settle found another owner.
78
+ */
79
+ const RUN_CLAIM_LOST_MESSAGE = "lost its run claim";
80
+ /**
81
+ * Raised when the scheduler's `only` option names one or more jobs that are not in its job list.
82
+ */
83
+ var UnknownJobError = class extends Schema.TaggedError()("UnknownJobError", {
84
+ /**
85
+ * Unknown job names passed in `only`.
86
+ */
87
+ names: Schema.Array(Schema.String) }) {};
88
+ /**
89
+ * Raised when cluster, schedule or policy configuration is invalid: a `ShardingConfig` that lacks
90
+ * or misassigns a shard group the jobs need, a job name too long for Cluster's shard ids, a cadence
91
+ * interval that does not divide an hour or a day, a policy duration that is not positive or a count
92
+ * that is not a positive integer.
93
+ */
94
+ var ClusterConfigError = class extends Schema.TaggedError()("ClusterConfigError", {
95
+ /**
96
+ * Human-readable explanation of the configuration error.
97
+ */
98
+ message: Schema.String }) {};
99
+ /**
100
+ * Which migration history `JobsNotMigratedError` found behind. The library only checks its own;
101
+ * your Cluster's storage is yours to migrate and check.
102
+ */
103
+ const JobsStorageComponent = Schema.Literals(["jobs"]);
104
+ /**
105
+ * Raised when a runtime layer starts against a database whose tables are missing or older than the
106
+ * installed code expects. Run `JobStorage.layerMigrations` (or `Migrator` with
107
+ * `JobStorage.migrations`) before starting workers and clients. A newer history than the code knows
108
+ * is accepted.
109
+ */
110
+ var JobsNotMigratedError = class extends Schema.TaggedError()("JobsNotMigratedError", {
111
+ /**
112
+ * Which migration history is behind.
113
+ */
114
+ component: JobsStorageComponent,
115
+ /**
116
+ * History table that was checked, as written in SQL (schema-qualified for the library's own).
117
+ */
118
+ table: Schema.String,
119
+ /**
120
+ * Highest migration id recorded in the history, `0` when the table does not exist.
121
+ */
122
+ found: Schema.Int,
123
+ /**
124
+ * Highest migration id the installed code ships.
125
+ */
126
+ expected: Schema.Int,
127
+ /**
128
+ * Operator message naming the table and pointing at `migrate()`.
129
+ */
130
+ message: Schema.String
131
+ }) {};
132
+ export { ClusterConfigError, DryRunUnsupported, InvalidDispatch, InvalidJobParams, InvalidRunKey, JobsNotMigratedError, JobsStorageComponent, RUN_CLAIM_LOST_MESSAGE, RUN_CLAIM_LOST_TAG, RunClaimLost, UnknownJobError };
@@ -0,0 +1,22 @@
1
+ import { JobStorageLayerOptions, storage_d_exports } from "./storage.js";
2
+ import { AnyJobDefinition, DailyCadence, DailyWindow, JobApiParamsPolicy, JobCadence, JobContext, JobDefinition, JobServices, JobTrigger, TimeOfDay, defineJob, isApiRequestable, isManualOnceJob } from "./job.js";
3
+ import { ClusterConfigError, DryRunUnsupported, InvalidDispatch, InvalidJobParams, InvalidRunKey, JobsNotMigratedError, JobsStorageComponent, RUN_CLAIM_LOST_MESSAGE, RUN_CLAIM_LOST_TAG, RunClaimLost, UnknownJobError } from "./errors.js";
4
+ import { DecodedJobParams, decodeJobParams, decodeParams, findDisallowedApiParams, parseSetFlags, pickApiParams } from "./params.js";
5
+ import { ClockCadence, ONCE_RUN_KEY, runKeyFor } from "./run-key.js";
6
+ import { MAX_RUN_KEY_LENGTH } from "./calendar.js";
7
+ import { DEFAULT_CRON_CATCH_UP, DEFAULT_DAILY_CHECK_EVERY, DEFAULT_SHARDS_PER_GROUP, JobsPolicy, JobsPolicyOverrides, LeasePolicy, MaintenancePolicy, NextAttemptInput, RetentionPolicy, RetryPolicy, defaultJobsPolicy, heartbeatIntervalFor, nextAttemptAt, onDemandRetryDelay, onceRetryDelay, resolveJobsPolicy } from "./policy.js";
8
+ import { DEFAULT_PREFIX, JobsStorageOptions } from "./storage-options.js";
9
+ import { JobRuns } from "./ledger.js";
10
+ import { ClaimRequest, JobFailureReason, JobRunRecord, JobRunStatus, JobSettleHook, JobSettled, OwnedRun, RecentRunsQuery, RunClaim, RunResult } from "./ledger-types.js";
11
+ import { JobOutcomeSchema, JobWorkflow, JobWorkflowPayload, MAX_CRASH_ATTEMPTS_TAG, OperatorJobParams, WorkerJobParams, WorkflowJobOutcome, WorkflowParamOverrides, makeJobWorkflow, maxCrashAttemptsMessage } from "./workflow-schema.js";
12
+ import { CreateJobRequest, DispatchFailedJobRequest, FinishJobRequest, JobRequestRecord, JobRequestStatus, JobRequests, UpsertStartedJobRequest } from "./requests.js";
13
+ import { DurableStageOptions, JobStageError, durableStage, toJobStageError } from "./activity.js";
14
+ import { JobLogContext, JobLoggingOptions, generateJobRunId, withJobContext, withJobLogging, withJobStage } from "./logging.js";
15
+ import { jobDurationMs, jobLeaseLostTotal, jobRunsTotal } from "./metrics.js";
16
+ import { JobOutcome, RunJobOptions, SkipReason, runAnyJob, runJob } from "./run.js";
17
+ import { DispatchApiJobWorkflowOptions, DispatchJobOptions, DispatchedApiJobWorkflow, DispatchedJob, dispatchApiJobWorkflow, dispatchJob } from "./dispatch.js";
18
+ import { makeAnyJobWorkflowLayer, makeJobWorkflowLayer } from "./workflow.js";
19
+ import { cronForCadence } from "./cron.js";
20
+ import { SchedulerOptions, makeSchedulerLayer, selectWorkerJobs } from "./scheduler.js";
21
+ import { ClusterServices, DEFAULT_SHARD_GROUP, MAINTENANCE_SHARD_GROUP, assignedShardGroupsFor, availableShardGroupsFor, checkShardingConfig, checkWorkerAssignment } from "./cluster.js";
22
+ export { type AnyJobDefinition, type ClaimRequest, type ClockCadence, ClusterConfigError, type ClusterServices, type CreateJobRequest, DEFAULT_CRON_CATCH_UP, DEFAULT_DAILY_CHECK_EVERY, DEFAULT_PREFIX, DEFAULT_SHARDS_PER_GROUP, DEFAULT_SHARD_GROUP, type DailyCadence, type DailyWindow, type DecodedJobParams, type DispatchApiJobWorkflowOptions, type DispatchFailedJobRequest, type DispatchJobOptions, type DispatchedApiJobWorkflow, type DispatchedJob, DryRunUnsupported, type DurableStageOptions, type FinishJobRequest, InvalidDispatch, InvalidJobParams, InvalidRunKey, type JobApiParamsPolicy, type JobCadence, type JobContext, type JobDefinition, type JobFailureReason, type JobLogContext, type JobLoggingOptions, type JobOutcome, JobOutcomeSchema, JobRequestRecord, type JobRequestStatus, JobRequests, JobRunRecord, JobRunStatus, JobRuns, type JobServices, type JobSettleHook, type JobSettled, JobStageError, storage_d_exports as JobStorage, type JobStorageLayerOptions, JobTrigger, type JobWorkflow, JobWorkflowPayload, JobsNotMigratedError, type JobsPolicy, type JobsPolicyOverrides, JobsStorageComponent, type JobsStorageOptions, type LeasePolicy, MAINTENANCE_SHARD_GROUP, MAX_CRASH_ATTEMPTS_TAG, MAX_RUN_KEY_LENGTH, type MaintenancePolicy, type NextAttemptInput, ONCE_RUN_KEY, type OperatorJobParams, type OwnedRun, RUN_CLAIM_LOST_MESSAGE, RUN_CLAIM_LOST_TAG, type RecentRunsQuery, type RetentionPolicy, type RetryPolicy, type RunClaim, RunClaimLost, type RunJobOptions, type RunResult, type SchedulerOptions, type SkipReason, type TimeOfDay, UnknownJobError, type UpsertStartedJobRequest, WorkerJobParams, type WorkflowJobOutcome, type WorkflowParamOverrides, assignedShardGroupsFor, availableShardGroupsFor, checkShardingConfig, checkWorkerAssignment, cronForCadence, decodeJobParams, decodeParams, defaultJobsPolicy, defineJob, dispatchApiJobWorkflow, dispatchJob, durableStage, findDisallowedApiParams, generateJobRunId, heartbeatIntervalFor, isApiRequestable, isManualOnceJob, jobDurationMs, jobLeaseLostTotal, jobRunsTotal, makeAnyJobWorkflowLayer, makeJobWorkflow, makeJobWorkflowLayer, makeSchedulerLayer, maxCrashAttemptsMessage, nextAttemptAt, onDemandRetryDelay, onceRetryDelay, parseSetFlags, pickApiParams, resolveJobsPolicy, runAnyJob, runJob, runKeyFor, selectWorkerJobs, toJobStageError, withJobContext, withJobLogging, withJobStage };
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ import { storage_exports } from "./storage.js";
2
+ import { JobTrigger, defineJob, isApiRequestable, isManualOnceJob } from "./job.js";
3
+ import { ClusterConfigError, DryRunUnsupported, InvalidDispatch, InvalidJobParams, InvalidRunKey, JobsNotMigratedError, JobsStorageComponent, RUN_CLAIM_LOST_MESSAGE, RUN_CLAIM_LOST_TAG, RunClaimLost, UnknownJobError } from "./errors.js";
4
+ import { decodeJobParams, decodeParams, findDisallowedApiParams, parseSetFlags, pickApiParams } from "./params.js";
5
+ import { ONCE_RUN_KEY, runKeyFor } from "./run-key.js";
6
+ import { MAX_RUN_KEY_LENGTH } from "./calendar.js";
7
+ import { DEFAULT_CRON_CATCH_UP, DEFAULT_DAILY_CHECK_EVERY, DEFAULT_SHARDS_PER_GROUP, defaultJobsPolicy, heartbeatIntervalFor, nextAttemptAt, onDemandRetryDelay, onceRetryDelay, resolveJobsPolicy } from "./policy.js";
8
+ import { DEFAULT_PREFIX } from "./storage-options.js";
9
+ import { JobRuns } from "./ledger.js";
10
+ import { JobRunRecord, JobRunStatus } from "./ledger-types.js";
11
+ import { JobRequestRecord, JobRequests } from "./requests.js";
12
+ import { JobStageError, durableStage, toJobStageError } from "./activity.js";
13
+ import { generateJobRunId, withJobContext, withJobLogging, withJobStage } from "./logging.js";
14
+ import { jobDurationMs, jobLeaseLostTotal, jobRunsTotal } from "./metrics.js";
15
+ import { runAnyJob, runJob } from "./run.js";
16
+ import { makeAnyJobWorkflowLayer, makeJobWorkflowLayer } from "./workflow.js";
17
+ import { JobOutcomeSchema, JobWorkflowPayload, MAX_CRASH_ATTEMPTS_TAG, WorkerJobParams, makeJobWorkflow, maxCrashAttemptsMessage } from "./workflow-schema.js";
18
+ import { dispatchApiJobWorkflow, dispatchJob } from "./dispatch.js";
19
+ import { cronForCadence } from "./cron.js";
20
+ import { makeSchedulerLayer, selectWorkerJobs } from "./scheduler.js";
21
+ import { DEFAULT_SHARD_GROUP, MAINTENANCE_SHARD_GROUP, assignedShardGroupsFor, availableShardGroupsFor, checkShardingConfig, checkWorkerAssignment } from "./cluster.js";
22
+ export { ClusterConfigError, DEFAULT_CRON_CATCH_UP, DEFAULT_DAILY_CHECK_EVERY, DEFAULT_PREFIX, DEFAULT_SHARDS_PER_GROUP, DEFAULT_SHARD_GROUP, DryRunUnsupported, InvalidDispatch, InvalidJobParams, InvalidRunKey, JobOutcomeSchema, JobRequestRecord, JobRequests, JobRunRecord, JobRunStatus, JobRuns, JobStageError, storage_exports as JobStorage, JobTrigger, JobWorkflowPayload, JobsNotMigratedError, JobsStorageComponent, MAINTENANCE_SHARD_GROUP, MAX_CRASH_ATTEMPTS_TAG, MAX_RUN_KEY_LENGTH, ONCE_RUN_KEY, RUN_CLAIM_LOST_MESSAGE, RUN_CLAIM_LOST_TAG, RunClaimLost, UnknownJobError, WorkerJobParams, assignedShardGroupsFor, availableShardGroupsFor, checkShardingConfig, checkWorkerAssignment, cronForCadence, decodeJobParams, decodeParams, defaultJobsPolicy, defineJob, dispatchApiJobWorkflow, dispatchJob, durableStage, findDisallowedApiParams, generateJobRunId, heartbeatIntervalFor, isApiRequestable, isManualOnceJob, jobDurationMs, jobLeaseLostTotal, jobRunsTotal, makeAnyJobWorkflowLayer, makeJobWorkflow, makeJobWorkflowLayer, makeSchedulerLayer, maxCrashAttemptsMessage, nextAttemptAt, onDemandRetryDelay, onceRetryDelay, parseSetFlags, pickApiParams, resolveJobsPolicy, runAnyJob, runJob, runKeyFor, selectWorkerJobs, toJobStageError, withJobContext, withJobLogging, withJobStage };