@dudousxd/nestjs-durable-core 0.103.0 → 0.105.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/dist/index.cjs +207 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +57 -7
- package/dist/index.d.ts +57 -7
- package/dist/index.js +205 -80
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -246,6 +246,7 @@ __export(index_exports, {
|
|
|
246
246
|
resolveWireTenant: () => resolveWireTenant,
|
|
247
247
|
retentionKeeps: () => retentionKeeps,
|
|
248
248
|
retiredHandoffName: () => retiredHandoffName,
|
|
249
|
+
retryLocalStep: () => retryLocalStep,
|
|
249
250
|
routeFor: () => routeFor,
|
|
250
251
|
rowTenant: () => rowTenant,
|
|
251
252
|
runCompletedEvent: () => runCompletedEvent,
|
|
@@ -274,6 +275,7 @@ __export(index_exports, {
|
|
|
274
275
|
singletonAdmissionDenialPatch: () => singletonAdmissionDenialPatch,
|
|
275
276
|
singletonAdmissionTags: () => singletonAdmissionTags,
|
|
276
277
|
singletonClaimantIds: () => singletonClaimantIds,
|
|
278
|
+
singletonKeyTag: () => singletonKeyTag,
|
|
277
279
|
sqlComparator: () => sqlComparator,
|
|
278
280
|
stepConfigOf: () => stepConfigOf,
|
|
279
281
|
stepId: () => stepId,
|
|
@@ -980,6 +982,27 @@ function backoffDelay(attempt, options) {
|
|
|
980
982
|
return options?.jitter ? Math.round(capped * (0.5 + Math.random() * 0.5)) : capped;
|
|
981
983
|
}
|
|
982
984
|
__name(backoffDelay, "backoffDelay");
|
|
985
|
+
async function retryLocalStep(options, attempt) {
|
|
986
|
+
const maxAttempts = Math.max(1, options?.retries ?? 1);
|
|
987
|
+
for (let n = 1; ; n += 1) {
|
|
988
|
+
try {
|
|
989
|
+
return {
|
|
990
|
+
ok: true,
|
|
991
|
+
value: await attempt(n),
|
|
992
|
+
attempts: n
|
|
993
|
+
};
|
|
994
|
+
} catch (error2) {
|
|
995
|
+
if (error2 instanceof FatalError || n >= maxAttempts) return {
|
|
996
|
+
ok: false,
|
|
997
|
+
error: error2,
|
|
998
|
+
attempts: n
|
|
999
|
+
};
|
|
1000
|
+
const wait = backoffDelay(n, options);
|
|
1001
|
+
if (wait > 0) await new Promise((resolve) => setTimeout(resolve, wait));
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
__name(retryLocalStep, "retryLocalStep");
|
|
983
1006
|
|
|
984
1007
|
// src/bounded-runner.ts
|
|
985
1008
|
var BoundedRunner = class {
|
|
@@ -4909,6 +4932,14 @@ var LEGACY_SCAN_STATUSES = [
|
|
|
4909
4932
|
"cancelling"
|
|
4910
4933
|
];
|
|
4911
4934
|
var byAdmissionOrder = /* @__PURE__ */ __name((a, b) => a.createdAt.getTime() - b.createdAt.getTime() || a.id.localeCompare(b.id), "byAdmissionOrder");
|
|
4935
|
+
function singletonKeyTag(tags) {
|
|
4936
|
+
if (!tags) return void 0;
|
|
4937
|
+
for (let i = tags.length - 1; i >= 0; i -= 1) {
|
|
4938
|
+
if (tags[i].startsWith("singleton:")) return tags[i];
|
|
4939
|
+
}
|
|
4940
|
+
return void 0;
|
|
4941
|
+
}
|
|
4942
|
+
__name(singletonKeyTag, "singletonKeyTag");
|
|
4912
4943
|
function withoutSingletonMarkers(tags) {
|
|
4913
4944
|
return tags?.filter((tag) => !SINGLETON_RESERVED_TAGS.includes(tag));
|
|
4914
4945
|
}
|
|
@@ -4937,7 +4968,7 @@ function singletonClaimantIds(rows, tag) {
|
|
|
4937
4968
|
__name(singletonClaimantIds, "singletonClaimantIds");
|
|
4938
4969
|
function singletonAdmissionTags(runs, runId, tag, workflow, limit) {
|
|
4939
4970
|
if (!Number.isInteger(limit) || limit < 1) throw new Error("singleton limit must be a positive integer");
|
|
4940
|
-
const active = runs.filter((run) => run.workflow === workflow && SINGLETON_ACTIVE_STATUSES.includes(run.status) && run.tags
|
|
4971
|
+
const active = runs.filter((run) => run.workflow === workflow && SINGLETON_ACTIVE_STATUSES.includes(run.status) && singletonKeyTag(run.tags) === tag);
|
|
4941
4972
|
const candidate = active.find((run) => run.id === runId);
|
|
4942
4973
|
if (!candidate) return null;
|
|
4943
4974
|
if (candidate.tags?.includes(SINGLETON_ADMITTED_TAG)) return candidate.tags;
|
|
@@ -4965,7 +4996,7 @@ async function clearTerminalSingletonAdmission(runId, patch, getRun) {
|
|
|
4965
4996
|
__name(clearTerminalSingletonAdmission, "clearTerminalSingletonAdmission");
|
|
4966
4997
|
function singletonAdmissionDenialPatch(runs, runId, tag, workflow, retryWakeAt) {
|
|
4967
4998
|
if (retryWakeAt === void 0) return void 0;
|
|
4968
|
-
const candidate = runs.find((run) => run.id === runId && run.workflow === workflow && run.tags
|
|
4999
|
+
const candidate = runs.find((run) => run.id === runId && run.workflow === workflow && singletonKeyTag(run.tags) === tag && SINGLETON_ACTIVE_STATUSES.includes(run.status));
|
|
4969
5000
|
if (!candidate || candidate.status === "cancelling") return void 0;
|
|
4970
5001
|
return {
|
|
4971
5002
|
status: "suspended",
|
|
@@ -5014,6 +5045,28 @@ function isLockConflict(error2) {
|
|
|
5014
5045
|
return false;
|
|
5015
5046
|
}
|
|
5016
5047
|
__name(isLockConflict, "isLockConflict");
|
|
5048
|
+
var UnparseableStoredInput = class {
|
|
5049
|
+
static {
|
|
5050
|
+
__name(this, "UnparseableStoredInput");
|
|
5051
|
+
}
|
|
5052
|
+
error;
|
|
5053
|
+
constructor(error2) {
|
|
5054
|
+
this.error = error2;
|
|
5055
|
+
}
|
|
5056
|
+
};
|
|
5057
|
+
async function admissionInput(run, parseInput) {
|
|
5058
|
+
if (!parseInput) return run.input;
|
|
5059
|
+
try {
|
|
5060
|
+
return await parseInput(run.input);
|
|
5061
|
+
} catch (err) {
|
|
5062
|
+
return new UnparseableStoredInput(err instanceof SchemaValidationError && err.code === "invalid_input" ? err : new SchemaValidationError(`workflow "${run.workflow}" input`, [
|
|
5063
|
+
{
|
|
5064
|
+
message: err instanceof Error ? err.message : String(err)
|
|
5065
|
+
}
|
|
5066
|
+
], "invalid_input"));
|
|
5067
|
+
}
|
|
5068
|
+
}
|
|
5069
|
+
__name(admissionInput, "admissionInput");
|
|
5017
5070
|
var SingletonGate = class {
|
|
5018
5071
|
static {
|
|
5019
5072
|
__name(this, "SingletonGate");
|
|
@@ -5050,12 +5103,19 @@ var SingletonGate = class {
|
|
|
5050
5103
|
throw new SingletonQueueFullError(workflow, cfg.key(input), cfg.maxQueueDepth);
|
|
5051
5104
|
}
|
|
5052
5105
|
}
|
|
5053
|
-
/**
|
|
5054
|
-
|
|
5106
|
+
/**
|
|
5107
|
+
* Preserve durable holders and atomically claim one of the remaining slots. With `parseInput` (the
|
|
5108
|
+
* workflow's input schema), the key reads the parsed input, the value `run(ctx, input)` gets; a
|
|
5109
|
+
* stored input that no longer parses answers {@link UnparseableStoredInput}, which the caller
|
|
5110
|
+
* must fail the turn with (never run it).
|
|
5111
|
+
*/
|
|
5112
|
+
async admit(run, cfg, parseInput) {
|
|
5055
5113
|
if (!this.deps.store.tryAdmitSingleton) {
|
|
5056
5114
|
throw new Error("Singleton workflows require StateStore.tryAdmitSingleton for atomic durable admission");
|
|
5057
5115
|
}
|
|
5058
|
-
const
|
|
5116
|
+
const keyInput = await admissionInput(run, parseInput);
|
|
5117
|
+
if (keyInput instanceof UnparseableStoredInput) return keyInput;
|
|
5118
|
+
const admitted = await this.claim(run, cfg, this.admissionTag(run, cfg, keyInput, parseInput));
|
|
5059
5119
|
if (admitted && !run.tags?.includes(SINGLETON_ADMITTED_TAG)) {
|
|
5060
5120
|
run.tags = [
|
|
5061
5121
|
...(run.tags ?? []).filter((tag) => tag !== SINGLETON_TRACKED_TAG),
|
|
@@ -5065,17 +5125,43 @@ var SingletonGate = class {
|
|
|
5065
5125
|
return admitted;
|
|
5066
5126
|
}
|
|
5067
5127
|
/**
|
|
5128
|
+
* The exact tag a turn claims under: the key of the parsed input, the tag `start` stamps. A run
|
|
5129
|
+
* queued by an engine that predates `parseInput` was stamped with the key of its RAW input
|
|
5130
|
+
* instead; when the run carries that tag and not the parsed one, it claims under it, so an
|
|
5131
|
+
* upgrade does not strand it. Both are computed from this run's own input, never read off a tag.
|
|
5132
|
+
* Only that case calls the key with the raw input (what the older engine always did), and only
|
|
5133
|
+
* for a run that carries a `singleton:` tag at all; a key that throws on it gets the parsed tag.
|
|
5134
|
+
*/
|
|
5135
|
+
admissionTag(run, cfg, keyInput, parseInput) {
|
|
5136
|
+
const parsed = this.tag(cfg, keyInput);
|
|
5137
|
+
const stamped = singletonKeyTag(run.tags);
|
|
5138
|
+
if (!parseInput || stamped === void 0 || stamped === parsed) return parsed;
|
|
5139
|
+
let raw;
|
|
5140
|
+
try {
|
|
5141
|
+
raw = this.tag(cfg, run.input);
|
|
5142
|
+
} catch {
|
|
5143
|
+
return parsed;
|
|
5144
|
+
}
|
|
5145
|
+
return stamped === raw ? raw : parsed;
|
|
5146
|
+
}
|
|
5147
|
+
/**
|
|
5068
5148
|
* One claim, retried when the database aborts it as a lock conflict. A conflict that outlasts the
|
|
5069
5149
|
* retries answers "not admitted", so the engine releases this turn's lease, instead of stranding
|
|
5070
5150
|
* the run until the lease lapses. It writes nothing to the run: this turn's lease may have lapsed
|
|
5071
5151
|
* during the claim, and another instance may now hold the run, its slot and newer tags. A later
|
|
5072
5152
|
* sweep re-drives the run: recovery once it is unleased, or its timer if it is parked.
|
|
5153
|
+
*
|
|
5154
|
+
* The claim is under the tag the key computes NOW, the one `start` stamped from the same input
|
|
5155
|
+
* (the schema is deterministic). The store admits a run only when it carries that exact tag, so
|
|
5156
|
+
* a run whose stored tags lack it (a caller tag from before callers' `singleton:` tags were
|
|
5157
|
+
* dropped, a run started before the workflow became a singleton) is never admitted under some
|
|
5158
|
+
* other key; it waits instead.
|
|
5073
5159
|
*/
|
|
5074
|
-
async claim(run, cfg) {
|
|
5160
|
+
async claim(run, cfg, tag) {
|
|
5075
5161
|
const admit = this.deps.store.tryAdmitSingleton;
|
|
5076
5162
|
for (let attempt = 1; ; attempt += 1) {
|
|
5077
5163
|
try {
|
|
5078
|
-
return await admit.call(this.deps.store, run.id,
|
|
5164
|
+
return await admit.call(this.deps.store, run.id, tag, run.workflow, cfg.limit ?? 1, this.retryWakeAt());
|
|
5079
5165
|
} catch (error2) {
|
|
5080
5166
|
if (!isLockConflict(error2)) throw error2;
|
|
5081
5167
|
if (attempt >= ADMISSION_ATTEMPTS) return false;
|
|
@@ -5093,7 +5179,7 @@ var SingletonGate = class {
|
|
|
5093
5179
|
async wakeNext(settled) {
|
|
5094
5180
|
const cfg = this.deps.configFor(settled);
|
|
5095
5181
|
if (!cfg) return;
|
|
5096
|
-
const tag = settled.tags
|
|
5182
|
+
const tag = singletonKeyTag(settled.tags);
|
|
5097
5183
|
if (!tag) return;
|
|
5098
5184
|
const gated = (await this.deps.store.listRuns({
|
|
5099
5185
|
tag,
|
|
@@ -6146,7 +6232,6 @@ function createWorkflowCtx(host, runId, compensations, workflow = "", searchAttr
|
|
|
6146
6232
|
});
|
|
6147
6233
|
return existing.output;
|
|
6148
6234
|
}
|
|
6149
|
-
const maxAttempts = Math.max(1, options?.retries ?? 1);
|
|
6150
6235
|
const startedAt = /* @__PURE__ */ new Date();
|
|
6151
6236
|
await host.startStep({
|
|
6152
6237
|
runId,
|
|
@@ -6157,60 +6242,59 @@ function createWorkflowCtx(host, runId, compensations, workflow = "", searchAttr
|
|
|
6157
6242
|
enqueuedAt: startedAt,
|
|
6158
6243
|
startedAt
|
|
6159
6244
|
});
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
seq: current,
|
|
6196
|
-
name,
|
|
6197
|
-
kind: "local",
|
|
6198
|
-
error: {
|
|
6199
|
-
message: err instanceof Error ? err.message : String(err),
|
|
6200
|
-
stack: err instanceof Error ? err.stack : void 0,
|
|
6201
|
-
...codeAndDetails(err)
|
|
6202
|
-
},
|
|
6203
|
-
events,
|
|
6204
|
-
attempts: attempt,
|
|
6205
|
-
enqueuedAt: startedAt,
|
|
6206
|
-
startedAt
|
|
6207
|
-
});
|
|
6208
|
-
throw err;
|
|
6209
|
-
}
|
|
6210
|
-
const wait = backoffDelay(attempt, options);
|
|
6211
|
-
if (wait > 0) await new Promise((resolve) => setTimeout(resolve, wait));
|
|
6212
|
-
}
|
|
6245
|
+
let events = [];
|
|
6246
|
+
const outcome = await retryLocalStep(options, async (attempt) => {
|
|
6247
|
+
const attemptEvents = [];
|
|
6248
|
+
events = attemptEvents;
|
|
6249
|
+
const invocation = {
|
|
6250
|
+
runId,
|
|
6251
|
+
workflow,
|
|
6252
|
+
stepName: name,
|
|
6253
|
+
seq: current,
|
|
6254
|
+
attempt
|
|
6255
|
+
};
|
|
6256
|
+
const body = /* @__PURE__ */ __name(() => {
|
|
6257
|
+
const logger = createStepLogger(attemptEvents, host.clock);
|
|
6258
|
+
return runInStepScope(scopeOwner, name, () => runInStepLogger(logger, () => fn(logger)));
|
|
6259
|
+
}, "body");
|
|
6260
|
+
const output = host.interceptStep ? await host.interceptStep(invocation, body) : await body();
|
|
6261
|
+
await host.completeStep({
|
|
6262
|
+
runId,
|
|
6263
|
+
seq: current,
|
|
6264
|
+
name,
|
|
6265
|
+
kind: "local",
|
|
6266
|
+
output,
|
|
6267
|
+
events: attemptEvents,
|
|
6268
|
+
attempts: attempt,
|
|
6269
|
+
enqueuedAt: startedAt,
|
|
6270
|
+
startedAt
|
|
6271
|
+
});
|
|
6272
|
+
return output;
|
|
6273
|
+
});
|
|
6274
|
+
if (outcome.ok) {
|
|
6275
|
+
if (options?.compensate) compensations.push({
|
|
6276
|
+
name,
|
|
6277
|
+
fn: options.compensate
|
|
6278
|
+
});
|
|
6279
|
+
return outcome.value;
|
|
6213
6280
|
}
|
|
6281
|
+
const err = outcome.error;
|
|
6282
|
+
await host.failStep({
|
|
6283
|
+
runId,
|
|
6284
|
+
seq: current,
|
|
6285
|
+
name,
|
|
6286
|
+
kind: "local",
|
|
6287
|
+
error: {
|
|
6288
|
+
message: err instanceof Error ? err.message : String(err),
|
|
6289
|
+
stack: err instanceof Error ? err.stack : void 0,
|
|
6290
|
+
...codeAndDetails(err)
|
|
6291
|
+
},
|
|
6292
|
+
events,
|
|
6293
|
+
attempts: outcome.attempts,
|
|
6294
|
+
enqueuedAt: startedAt,
|
|
6295
|
+
startedAt
|
|
6296
|
+
});
|
|
6297
|
+
throw err;
|
|
6214
6298
|
}, "localStep");
|
|
6215
6299
|
const transaction = /* @__PURE__ */ __name(async (name, fn) => {
|
|
6216
6300
|
if (!store.transaction) {
|
|
@@ -7242,9 +7326,30 @@ function tenantScopedKey(namespace, key) {
|
|
|
7242
7326
|
return namespace && namespace !== "default" ? `${namespace}/${key}` : key;
|
|
7243
7327
|
}
|
|
7244
7328
|
__name(tenantScopedKey, "tenantScopedKey");
|
|
7329
|
+
function failingBody(error2) {
|
|
7330
|
+
return async () => {
|
|
7331
|
+
throw error2;
|
|
7332
|
+
};
|
|
7333
|
+
}
|
|
7334
|
+
__name(failingBody, "failingBody");
|
|
7335
|
+
function storedInputError(invalid) {
|
|
7336
|
+
return {
|
|
7337
|
+
message: invalid.error.message,
|
|
7338
|
+
code: "invalid_input",
|
|
7339
|
+
retryable: false,
|
|
7340
|
+
details: {
|
|
7341
|
+
issues: invalid.error.issues
|
|
7342
|
+
}
|
|
7343
|
+
};
|
|
7344
|
+
}
|
|
7345
|
+
__name(storedInputError, "storedInputError");
|
|
7346
|
+
function callerTags(tags) {
|
|
7347
|
+
return tags?.filter((tag) => !tag.startsWith(SINGLETON_TAG_PREFIX));
|
|
7348
|
+
}
|
|
7349
|
+
__name(callerTags, "callerTags");
|
|
7350
|
+
var SINGLETON_TAG_PREFIX = "singleton:";
|
|
7245
7351
|
function singletonKeyOf(run) {
|
|
7246
|
-
|
|
7247
|
-
return tag?.slice("singleton:".length);
|
|
7352
|
+
return singletonKeyTag(run.tags)?.slice("singleton:".length);
|
|
7248
7353
|
}
|
|
7249
7354
|
__name(singletonKeyOf, "singletonKeyOf");
|
|
7250
7355
|
function conventionSingleton(run, announced, wire) {
|
|
@@ -8264,6 +8369,7 @@ var WorkflowEngine = class _WorkflowEngine {
|
|
|
8264
8369
|
concurrency: opts?.concurrency,
|
|
8265
8370
|
executionTimeoutMs: opts?.executionTimeout != null ? parseDuration(opts.executionTimeout) : void 0,
|
|
8266
8371
|
validateInput: opts?.validateInput,
|
|
8372
|
+
parseInput: opts?.parseInput,
|
|
8267
8373
|
searchAttributesSchema: opts?.searchAttributesSchema,
|
|
8268
8374
|
onEvent: opts?.onEvent,
|
|
8269
8375
|
eventBatch: opts?.eventBatch,
|
|
@@ -9965,24 +10071,31 @@ var WorkflowEngine = class _WorkflowEngine {
|
|
|
9965
10071
|
if (!registered) {
|
|
9966
10072
|
throw new Error(pinned === void 0 ? `workflow ${name} is not registered` : `workflow ${versionKey(name, pinned)} is not registered \u2014 a pinned start never falls back to the newest version (registered: ${this.registeredVersions(name)})`);
|
|
9967
10073
|
}
|
|
9968
|
-
|
|
10074
|
+
const check = registered;
|
|
10075
|
+
const parseAndValidate = /* @__PURE__ */ __name(async () => {
|
|
10076
|
+
const parsed = check.parseInput ? await check.parseInput(input) : input;
|
|
10077
|
+
await check.validateInput?.(parsed);
|
|
10078
|
+
return parsed;
|
|
10079
|
+
}, "parseAndValidate");
|
|
10080
|
+
let keyInput;
|
|
10081
|
+
if (parkUnroutable && (registered.validateInput || registered.parseInput)) {
|
|
9969
10082
|
try {
|
|
9970
|
-
await
|
|
10083
|
+
keyInput = await parseAndValidate();
|
|
9971
10084
|
} catch (err) {
|
|
9972
10085
|
throw new TenantStartInvalid(err);
|
|
9973
10086
|
}
|
|
9974
10087
|
} else {
|
|
9975
|
-
await
|
|
10088
|
+
keyInput = await parseAndValidate();
|
|
9976
10089
|
}
|
|
9977
10090
|
const prior = await this.store.getRun(runId);
|
|
9978
10091
|
if (prior) return this.existingStartResult(prior);
|
|
9979
|
-
const quota = await resolveConcurrency(opts?.concurrency, registered.concurrency,
|
|
10092
|
+
const quota = await resolveConcurrency(opts?.concurrency, registered.concurrency, keyInput);
|
|
9980
10093
|
if (quota) await assertConcurrency(this.store, name, quota);
|
|
9981
10094
|
const now = /* @__PURE__ */ new Date();
|
|
9982
10095
|
const stampedTags = [
|
|
9983
|
-
...opts?.tags ?? [],
|
|
10096
|
+
...callerTags(opts?.tags) ?? [],
|
|
9984
10097
|
...registered.singleton ? [
|
|
9985
|
-
this.singletons.tag(registered.singleton,
|
|
10098
|
+
this.singletons.tag(registered.singleton, keyInput)
|
|
9986
10099
|
] : [],
|
|
9987
10100
|
...quota ? [
|
|
9988
10101
|
concurrencyTag(quota.key)
|
|
@@ -9991,9 +10104,9 @@ var WorkflowEngine = class _WorkflowEngine {
|
|
|
9991
10104
|
VERSION_UNDECLARED_TAG
|
|
9992
10105
|
] : []
|
|
9993
10106
|
];
|
|
9994
|
-
const tags = mergeTags(registered.tags, stampedTags)?.filter((tag) => !SINGLETON_RESERVED_TAGS.includes(tag));
|
|
10107
|
+
const tags = mergeTags(callerTags(registered.tags), stampedTags)?.filter((tag) => !SINGLETON_RESERVED_TAGS.includes(tag));
|
|
9995
10108
|
if (registered.singleton) {
|
|
9996
|
-
await this.singletons.assertCapacity(name, registered.singleton,
|
|
10109
|
+
await this.singletons.assertCapacity(name, registered.singleton, keyInput);
|
|
9997
10110
|
}
|
|
9998
10111
|
const startAtMs = opts?.startAt instanceof Date ? opts.startAt.getTime() : opts?.startAt;
|
|
9999
10112
|
const delayed = startAtMs !== void 0 && Number.isFinite(startAtMs) && startAtMs > this.clock();
|
|
@@ -10082,7 +10195,7 @@ var WorkflowEngine = class _WorkflowEngine {
|
|
|
10082
10195
|
};
|
|
10083
10196
|
const now = /* @__PURE__ */ new Date();
|
|
10084
10197
|
const tags = mergeTags(void 0, [
|
|
10085
|
-
...opts?.tags ?? [],
|
|
10198
|
+
...callerTags(opts?.tags) ?? [],
|
|
10086
10199
|
...singleton ? [
|
|
10087
10200
|
this.singletons.tag(singleton, input)
|
|
10088
10201
|
] : [],
|
|
@@ -10262,7 +10375,7 @@ var WorkflowEngine = class _WorkflowEngine {
|
|
|
10262
10375
|
namespace: poolNamespace(opts.namespace) ?? this.namespace,
|
|
10263
10376
|
input,
|
|
10264
10377
|
// The same derived tags an admitted or parked start carries, so quota-key queries find it.
|
|
10265
|
-
tags: mergeTags(opts.tags, [
|
|
10378
|
+
tags: mergeTags(callerTags(opts.tags), [
|
|
10266
10379
|
...opts.concurrency ? [
|
|
10267
10380
|
concurrencyTag(opts.concurrency.key)
|
|
10268
10381
|
] : [],
|
|
@@ -13789,8 +13902,17 @@ ${run.workflowVersion}`;
|
|
|
13789
13902
|
...await this.sourceTraceOf(run)
|
|
13790
13903
|
});
|
|
13791
13904
|
}
|
|
13792
|
-
if (registered.singleton
|
|
13793
|
-
|
|
13905
|
+
if (registered.singleton) {
|
|
13906
|
+
const admission = await this.singletons.admit(run, registered.singleton, registered.parseInput);
|
|
13907
|
+
if (admission instanceof UnparseableStoredInput) {
|
|
13908
|
+
const result = await this.settleRun(run, {
|
|
13909
|
+
kind: "failed",
|
|
13910
|
+
error: storedInputError(admission)
|
|
13911
|
+
});
|
|
13912
|
+
await this.releaseLeaseBestEffort(run.id);
|
|
13913
|
+
return result;
|
|
13914
|
+
}
|
|
13915
|
+
if (!admission) return this.singletonWaitResult(run);
|
|
13794
13916
|
}
|
|
13795
13917
|
const wfToken = tenantGroup(sanitizeQueueToken(remote.group), void 0);
|
|
13796
13918
|
let wfPlan = await this.planRoute(wfToken, registered.requires);
|
|
@@ -14301,7 +14423,7 @@ ${run.workflowVersion}`;
|
|
|
14301
14423
|
output: cmd.output,
|
|
14302
14424
|
error: cmd.error,
|
|
14303
14425
|
events: cmd.events,
|
|
14304
|
-
attempts: 1,
|
|
14426
|
+
attempts: cmd.attempts ?? 1,
|
|
14305
14427
|
enqueuedAt: startedAt,
|
|
14306
14428
|
startedAt,
|
|
14307
14429
|
finishedAt,
|
|
@@ -14827,7 +14949,8 @@ ${run.workflowVersion}`;
|
|
|
14827
14949
|
attempt: void 0
|
|
14828
14950
|
}, () => this.runExecutionTurn(run, fn, registered));
|
|
14829
14951
|
}
|
|
14830
|
-
async runExecutionTurn(run,
|
|
14952
|
+
async runExecutionTurn(run, registeredFn, registered) {
|
|
14953
|
+
let fn = registeredFn;
|
|
14831
14954
|
if (run.status === "cancelling") this.cancelRequested.add(run.id);
|
|
14832
14955
|
if (run.status === "pending") {
|
|
14833
14956
|
if (!await this.markStarted(run, registered?.singleton !== void 0)) {
|
|
@@ -14843,8 +14966,10 @@ ${run.workflowVersion}`;
|
|
|
14843
14966
|
});
|
|
14844
14967
|
}
|
|
14845
14968
|
await this.noteServedWakes(run.id);
|
|
14846
|
-
if (run.status !== "cancelling" && registered?.singleton
|
|
14847
|
-
|
|
14969
|
+
if (run.status !== "cancelling" && registered?.singleton) {
|
|
14970
|
+
const admission = await this.singletons.admit(run, registered.singleton, registered.parseInput);
|
|
14971
|
+
if (admission instanceof UnparseableStoredInput) fn = failingBody(admission.error);
|
|
14972
|
+
else if (!admission) return this.singletonWaitResult(run);
|
|
14848
14973
|
}
|
|
14849
14974
|
const stickyOk = this.stickyEligible(run);
|
|
14850
14975
|
let cont = stickyOk ? this.takeContinuation(run, fn) : void 0;
|
|
@@ -19329,6 +19454,7 @@ __name(settleResultsWithPlainCalls, "settleResultsWithPlainCalls");
|
|
|
19329
19454
|
resolveWireTenant,
|
|
19330
19455
|
retentionKeeps,
|
|
19331
19456
|
retiredHandoffName,
|
|
19457
|
+
retryLocalStep,
|
|
19332
19458
|
routeFor,
|
|
19333
19459
|
rowTenant,
|
|
19334
19460
|
runCompletedEvent,
|
|
@@ -19357,6 +19483,7 @@ __name(settleResultsWithPlainCalls, "settleResultsWithPlainCalls");
|
|
|
19357
19483
|
singletonAdmissionDenialPatch,
|
|
19358
19484
|
singletonAdmissionTags,
|
|
19359
19485
|
singletonClaimantIds,
|
|
19486
|
+
singletonKeyTag,
|
|
19360
19487
|
sqlComparator,
|
|
19361
19488
|
stepConfigOf,
|
|
19362
19489
|
stepId,
|