@plitzi/sdk-actions 0.39.13 → 0.39.15
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/CHANGELOG.md +20 -0
- package/dist/chunks/{grants-BsD-WlLE.mjs → grants-ZR79buug.mjs} +2 -14
- package/dist/chunks/{load-tw8iAgZy.mjs → load-CBBAXiBR.mjs} +1 -1
- package/dist/chunks/{module-Baod2T6h.mjs → module-BGt8qxNC.mjs} +75 -80
- package/dist/chunks/{queueDocument-DCBWcxe_.mjs → queueDocument-BsYXkDDZ.mjs} +1 -1
- package/dist/chunks/{queueRules-UGZNkho0.mjs → queueRules-CJ9Huag3.mjs} +29 -29
- package/dist/chunks/{taskCatalog-J9hBMCsz.mjs → taskCatalog-GrTxD29I.mjs} +1 -1
- package/dist/engine/jobs/codeChanged.d.ts +15 -0
- package/dist/engine/runtime/kvStore.d.ts +3 -3
- package/dist/engine/runtime/redisKv.d.ts +3 -4
- package/dist/engine/types.d.ts +7 -4
- package/dist/functions/index.mjs +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +57 -12
- package/dist/mongo/index.mjs +5 -10
- package/dist/mysql/index.mjs +9 -8
- package/dist/realtime/index.mjs +1 -1
- package/dist/sqlite/index.mjs +6 -11
- package/dist/types/config.d.ts +5 -5
- package/dist/worker/index.mjs +4 -4
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @plitzi/sdk-actions
|
|
2
2
|
|
|
3
|
+
## 0.39.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 359fd04: Released with every `@plitzi` package at this version. What changed in each, and what to do when you upgrade, is in
|
|
8
|
+
`@plitzi/cli`'s `CHANGELOG.md`: one copy of the notes, not one per package.
|
|
9
|
+
- Updated dependencies [359fd04]
|
|
10
|
+
- @plitzi/sdk-kernel@0.39.15
|
|
11
|
+
- @plitzi/sdk-shared@0.39.15
|
|
12
|
+
|
|
13
|
+
## 0.39.14
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- f1922cf: Released with every `@plitzi` package at this version. What changed in each, and what to do when you upgrade, is in
|
|
18
|
+
`@plitzi/cli`'s `CHANGELOG.md`: one copy of the notes, not one per package.
|
|
19
|
+
- Updated dependencies [f1922cf]
|
|
20
|
+
- @plitzi/sdk-kernel@0.39.14
|
|
21
|
+
- @plitzi/sdk-shared@0.39.14
|
|
22
|
+
|
|
3
23
|
## 0.39.13
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
|
@@ -8,7 +8,6 @@ var KV_METHODS = {
|
|
|
8
8
|
set: true,
|
|
9
9
|
delete: true,
|
|
10
10
|
increment: true,
|
|
11
|
-
expire: true,
|
|
12
11
|
swap: true
|
|
13
12
|
};
|
|
14
13
|
/**
|
|
@@ -67,27 +66,16 @@ var createMapKv = (entries, changed = () => void 0) => {
|
|
|
67
66
|
if (entries.delete(key)) changed();
|
|
68
67
|
return Promise.resolve();
|
|
69
68
|
},
|
|
70
|
-
increment: (key, amount) => {
|
|
69
|
+
increment: (key, amount, ttlSeconds) => {
|
|
71
70
|
const current = read(key);
|
|
72
71
|
const base = Number(current?.value ?? 0);
|
|
73
72
|
const next = (Number.isFinite(base) ? base : 0) + amount;
|
|
74
73
|
write(key, {
|
|
75
74
|
value: String(next),
|
|
76
|
-
expiresAt: current?.expiresAt
|
|
75
|
+
expiresAt: current?.expiresAt ?? expiry(ttlSeconds)
|
|
77
76
|
});
|
|
78
77
|
return Promise.resolve(next);
|
|
79
78
|
},
|
|
80
|
-
expire: (key, ttlSeconds) => {
|
|
81
|
-
const current = read(key);
|
|
82
|
-
if (current) {
|
|
83
|
-
entries.set(key, {
|
|
84
|
-
...current,
|
|
85
|
-
expiresAt: expiry(ttlSeconds)
|
|
86
|
-
});
|
|
87
|
-
changed();
|
|
88
|
-
}
|
|
89
|
-
return Promise.resolve();
|
|
90
|
-
},
|
|
91
79
|
swap: (key, expected, next, ttlSeconds) => {
|
|
92
80
|
if (read(key)?.value !== expected) return Promise.resolve(false);
|
|
93
81
|
write(key, {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as buildFunctions } from "./module-
|
|
1
|
+
import { i as buildFunctions } from "./module-BGt8qxNC.mjs";
|
|
2
2
|
import { isRecord } from "@plitzi/sdk-shared/helpers";
|
|
3
3
|
import { readFunctionsSource } from "@plitzi/sdk-shared/actions";
|
|
4
4
|
import { readFile, readdir } from "node:fs/promises";
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { a as emptyState,
|
|
1
|
+
import { a as emptyState, m as SET_ASIDE_WORDS, o as queueOver, r as applyRule, s as queueRules } from "./queueRules-CJ9Huag3.mjs";
|
|
2
2
|
import { a as triggerParams, i as findTriggerNode, n as RunLimitReached, r as limitOf, t as ActionRunError } from "./errors-bCBfIe7c.mjs";
|
|
3
|
-
import { i as KV_METHODS, n as MAX_GRANT_SECONDS, o as createMemoryKv, t as DEFAULT_GRANT_SECONDS } from "./grants-
|
|
3
|
+
import { i as KV_METHODS, n as MAX_GRANT_SECONDS, o as createMemoryKv, t as DEFAULT_GRANT_SECONDS } from "./grants-ZR79buug.mjs";
|
|
4
4
|
import { cappedResponse, fetchOutbound, isBlockedHost } from "@plitzi/sdk-kernel/outbound";
|
|
5
5
|
import { BODYLESS_METHODS, DEFAULT_READ_ENDPOINT, EMPTY_RESPONSE_METHODS } from "@plitzi/sdk-shared/connectors";
|
|
6
6
|
import { processTwig, processTwigParam, resolveStepParam } from "@plitzi/sdk-shared/helpers/twigWrapper";
|
|
7
7
|
import { createCipheriv, createDecipheriv, createHash, createHmac, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
8
|
+
import { serverLog } from "@plitzi/sdk-kernel/log";
|
|
8
9
|
import { isRecord } from "@plitzi/sdk-shared/helpers";
|
|
9
10
|
import { DEFAULT_FUNCTION_ASKED_LIMITS, FAILURE_HANDLER_TASK, FLOW_DELAY_MAX_MS, FUNCTION_ASKED_KEYS, FUNCTION_ROUTES_PREFIX, PLUGIN_ROUTES_SEGMENT, accessRefusal, actionAccessOf, cronFiresBetween, cronNextFire, exportsByDefault, isFunctionsDefinitionFile, isFunctionsSourcePath, isKnownTimeZone, isSingleEmailAddress, isTerminalJobStatus, readSmtpCredential, triggerAccess, triggerInput } from "@plitzi/sdk-shared/actions";
|
|
10
11
|
import path from "node:path";
|
|
11
|
-
import { serverLog } from "@plitzi/sdk-kernel/log";
|
|
12
12
|
import { overloaded, processLoad, sampleProcessMemory } from "@plitzi/sdk-kernel/stats";
|
|
13
13
|
import { getHeapStatistics } from "node:v8";
|
|
14
14
|
import { ActionRefusal, FUNCTION_SIZES, FUNCTION_SIZE_NAMES, FunctionFailure, changeKv, changeListEntry, defineFunctions, functionSizesWithin, isActionRefusal, isFunctionLimit, isFunctionSize, isStreamedRouteAnswer, refusalCodeOf, responseOf, wireRequestOf, wireResponseFrom, wireResponseOf } from "@plitzi/sdk-shared/functions";
|
|
@@ -385,76 +385,6 @@ var readKeptCall = async (queue, spaceId, jobId, ticket) => {
|
|
|
385
385
|
}
|
|
386
386
|
}
|
|
387
387
|
};
|
|
388
|
-
// src/engine/jobs/codeMarks.ts
|
|
389
|
-
/**
|
|
390
|
-
* The queue, marking each action job it is given whose action runs the space's own code (`target.code`) — read off its
|
|
391
|
-
* document as it is queued, wherever from: a schedule's fire, a run set for later, a call kept for when a runner is
|
|
392
|
-
* back. What lets a worker whose runs wait for a runner with room go on taking the jobs that need none
|
|
393
|
-
* (`claim({ takes: 'light' })`). A mark that misses costs only that: the job waits beside the others, as before.
|
|
394
|
-
*/
|
|
395
|
-
var codeMarkingQueue = (queue, lookups, runsCode) => ({
|
|
396
|
-
...queue,
|
|
397
|
-
enqueue: async (job) => {
|
|
398
|
-
const { target } = job;
|
|
399
|
-
if (target.kind !== "action" || target.code) return queue.enqueue(job);
|
|
400
|
-
const entry = await lookups.getAction(job.spaceId, target.name, target.at).catch((error) => {
|
|
401
|
-
serverLog.warn("Actions", `job ${job.id}: queued without reading whether its action runs the space's code`, error);
|
|
402
|
-
});
|
|
403
|
-
return queue.enqueue(entry && runsCode(entry.document) ? {
|
|
404
|
-
...job,
|
|
405
|
-
target: {
|
|
406
|
-
...target,
|
|
407
|
-
code: true
|
|
408
|
-
}
|
|
409
|
-
} : job);
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
// src/engine/jobs/memoryQueue.ts
|
|
413
|
-
/** Every method of the queue, for the copy a server's workers share (`FleetStores`, `core/server/fleet/link.ts`). */
|
|
414
|
-
var JOB_QUEUE_METHODS = {
|
|
415
|
-
now: true,
|
|
416
|
-
enqueue: true,
|
|
417
|
-
claim: true,
|
|
418
|
-
heartbeat: true,
|
|
419
|
-
settle: true,
|
|
420
|
-
write: true,
|
|
421
|
-
dueSchedules: true,
|
|
422
|
-
advanceSchedule: true,
|
|
423
|
-
putSchedules: true,
|
|
424
|
-
listJobs: true,
|
|
425
|
-
listJobGroups: true,
|
|
426
|
-
listAcross: true,
|
|
427
|
-
summarize: true,
|
|
428
|
-
countDue: true,
|
|
429
|
-
flow: true,
|
|
430
|
-
getJob: true,
|
|
431
|
-
listSchedules: true,
|
|
432
|
-
requeue: true,
|
|
433
|
-
cancel: true,
|
|
434
|
-
pause: true,
|
|
435
|
-
resume: true,
|
|
436
|
-
cancelPending: true,
|
|
437
|
-
cancelWaiting: true,
|
|
438
|
-
resumeWaiting: true
|
|
439
|
-
};
|
|
440
|
-
/**
|
|
441
|
-
* The default queue: one process's Maps.
|
|
442
|
-
*
|
|
443
|
-
* Correct for a deployment that runs ONE replica, which is most self-hosted ones, and honest about the rest — a
|
|
444
|
-
* second replica running on this gets its own schedules and its own jobs, so a nightly digest goes out twice. The
|
|
445
|
-
* cure is any store the replicas share, behind the same {@link JobQueue} seam.
|
|
446
|
-
*
|
|
447
|
-
* It keeps the contract exactly, rather than approximately: enqueue is idempotent by id, a claim reaps lapsed
|
|
448
|
-
* leases, and every instant is read here rather than accepted from a caller. A test that passes against this one
|
|
449
|
-
* is testing the rules a shared store has to keep too.
|
|
450
|
-
*/
|
|
451
|
-
var createMemoryJobQueue = ({ retainFinished = 500, clock = Date.now } = {}) => {
|
|
452
|
-
const rules = queueRules(emptyState(), {
|
|
453
|
-
retainFinished,
|
|
454
|
-
clock
|
|
455
|
-
});
|
|
456
|
-
return queueOver((method, args) => Promise.resolve(applyRule(rules, method, args)));
|
|
457
|
-
};
|
|
458
388
|
// src/engine/jobs/endings.ts
|
|
459
389
|
/** How a job ends badly: given up, set aside at a limit, or out of attempts — and what its line says. */
|
|
460
390
|
/**
|
|
@@ -568,6 +498,76 @@ var limitEndings = ({ workerId, settle, release, nextMinuteMs }) => async (job,
|
|
|
568
498
|
});
|
|
569
499
|
return true;
|
|
570
500
|
};
|
|
501
|
+
// src/engine/jobs/codeMarks.ts
|
|
502
|
+
/**
|
|
503
|
+
* The queue, marking each action job it is given whose action runs the space's own code (`target.code`) — read off its
|
|
504
|
+
* document as it is queued, wherever from: a schedule's fire, a run set for later, a call kept for when a runner is
|
|
505
|
+
* back. What lets a worker whose runs wait for a runner with room go on taking the jobs that need none
|
|
506
|
+
* (`claim({ takes: 'light' })`). A mark that misses costs only that: the job waits beside the others, as before.
|
|
507
|
+
*/
|
|
508
|
+
var codeMarkingQueue = (queue, lookups, runsCode) => ({
|
|
509
|
+
...queue,
|
|
510
|
+
enqueue: async (job) => {
|
|
511
|
+
const { target } = job;
|
|
512
|
+
if (target.kind !== "action" || target.code) return queue.enqueue(job);
|
|
513
|
+
const entry = await lookups.getAction(job.spaceId, target.name, target.at).catch((error) => {
|
|
514
|
+
serverLog.warn("Actions", `job ${job.id}: queued without reading whether its action runs the space's code`, error);
|
|
515
|
+
});
|
|
516
|
+
return queue.enqueue(entry && runsCode(entry.document) ? {
|
|
517
|
+
...job,
|
|
518
|
+
target: {
|
|
519
|
+
...target,
|
|
520
|
+
code: true
|
|
521
|
+
}
|
|
522
|
+
} : job);
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
// src/engine/jobs/memoryQueue.ts
|
|
526
|
+
/** Every method of the queue, for the copy a server's workers share (`FleetStores`, `core/server/fleet/link.ts`). */
|
|
527
|
+
var JOB_QUEUE_METHODS = {
|
|
528
|
+
now: true,
|
|
529
|
+
enqueue: true,
|
|
530
|
+
claim: true,
|
|
531
|
+
heartbeat: true,
|
|
532
|
+
settle: true,
|
|
533
|
+
write: true,
|
|
534
|
+
dueSchedules: true,
|
|
535
|
+
advanceSchedule: true,
|
|
536
|
+
putSchedules: true,
|
|
537
|
+
listJobs: true,
|
|
538
|
+
listJobGroups: true,
|
|
539
|
+
listAcross: true,
|
|
540
|
+
summarize: true,
|
|
541
|
+
countDue: true,
|
|
542
|
+
flow: true,
|
|
543
|
+
getJob: true,
|
|
544
|
+
listSchedules: true,
|
|
545
|
+
requeue: true,
|
|
546
|
+
cancel: true,
|
|
547
|
+
pause: true,
|
|
548
|
+
resume: true,
|
|
549
|
+
cancelPending: true,
|
|
550
|
+
cancelWaiting: true,
|
|
551
|
+
resumeWaiting: true
|
|
552
|
+
};
|
|
553
|
+
/**
|
|
554
|
+
* The default queue: one process's Maps.
|
|
555
|
+
*
|
|
556
|
+
* Correct for a deployment that runs ONE replica, which is most self-hosted ones, and honest about the rest — a
|
|
557
|
+
* second replica running on this gets its own schedules and its own jobs, so a nightly digest goes out twice. The
|
|
558
|
+
* cure is any store the replicas share, behind the same {@link JobQueue} seam.
|
|
559
|
+
*
|
|
560
|
+
* It keeps the contract exactly, rather than approximately: enqueue is idempotent by id, a claim reaps lapsed
|
|
561
|
+
* leases, and every instant is read here rather than accepted from a caller. A test that passes against this one
|
|
562
|
+
* is testing the rules a shared store has to keep too.
|
|
563
|
+
*/
|
|
564
|
+
var createMemoryJobQueue = ({ retainFinished = 500, clock = Date.now } = {}) => {
|
|
565
|
+
const rules = queueRules(emptyState(), {
|
|
566
|
+
retainFinished,
|
|
567
|
+
clock
|
|
568
|
+
});
|
|
569
|
+
return queueOver((method, args) => Promise.resolve(applyRule(rules, method, args)));
|
|
570
|
+
};
|
|
571
571
|
// src/engine/jobs/failureStreak.ts
|
|
572
572
|
/** How long a pass may keep failing before it is reported as the error it has become. */
|
|
573
573
|
var FAILURE_STREAK_ESCALATION_MS = 6e4;
|
|
@@ -2019,12 +2019,7 @@ var createKvStore = (adapter, { prefix = "kv:" } = {}) => {
|
|
|
2019
2019
|
},
|
|
2020
2020
|
set: (key, value, ttlSeconds) => adapter.set(prefixed(key), JSON.stringify(value), ttlSeconds),
|
|
2021
2021
|
delete: (key) => adapter.delete(prefixed(key)),
|
|
2022
|
-
increment:
|
|
2023
|
-
const full = prefixed(key);
|
|
2024
|
-
const value = await adapter.increment(full, amount);
|
|
2025
|
-
if (ttlSeconds !== void 0 && value === amount) await adapter.expire(full, ttlSeconds);
|
|
2026
|
-
return value;
|
|
2027
|
-
},
|
|
2022
|
+
increment: (key, amount, ttlSeconds) => adapter.increment(prefixed(key), amount, ttlSeconds),
|
|
2028
2023
|
swap: (key, expected, next, ttlSeconds) => adapter.swap(prefixed(key), expected === void 0 ? void 0 : JSON.stringify(expected), JSON.stringify(next), ttlSeconds),
|
|
2029
2024
|
listPut: async (list, entry, options = {}) => {
|
|
2030
2025
|
const problem = listIdProblem(entry.id);
|
|
@@ -7135,4 +7130,4 @@ var createActionsModule = (given) => {
|
|
|
7135
7130
|
}
|
|
7136
7131
|
return module;
|
|
7137
7132
|
};
|
|
7138
|
-
export { schedulesFor as A, fleetJobQueue as C, DEFAULT_MAX_ATTEMPTS as D, createScheduler as E,
|
|
7133
|
+
export { schedulesFor as A, fleetJobQueue as C, DEFAULT_MAX_ATTEMPTS as D, createScheduler as E, keepCall as F, readKeptCall as I, fetchConnectorRecords as L, SET_ASIDE_LIMITS as M, KEPT_CALLS_PER_SPACE as N, scheduleFor as O, KEPT_CALL_MS as P, rebaseMedia as R, ACTIONS_FLEET_STORES as S, createJobWorker as T, DEFAULT_LIMITS as _, createTaskRegistry as a, MAX_LIST_ENTRIES as b, oauthCallbackUrlOn as c, DEFAULT_FUNCTION_LIMITS as d, taskName as f, spaceKvPatterns as g, precheckRun as h, buildFunctions as i, createMemoryJobQueue as j, scheduleJobId as k, readManifest as l, createSigning as m, functionsInHand as n, DEFAULT_FUNCTION_JOB_LIMITS as o, MIN_SIGNING_SECRET_LENGTH as p, FunctionsBuildError as r, jobViewOf as s, createActionsModule as t, DEFAULT_FUNCTION_CEILINGS as u, createKvStore as v, fleetKv as w, createActionJobs as x, MAX_LIST_BYTES as y, writeConnectorRecord as z };
|
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
import { isRecord } from "@plitzi/sdk-shared/helpers";
|
|
2
2
|
import { isTerminalJobStatus } from "@plitzi/sdk-shared/actions";
|
|
3
|
+
// src/engine/jobs/memoryNeeds.ts
|
|
4
|
+
/**
|
|
5
|
+
* What a job needs once the worker running it died, in the words every store writes: the in-process ones through
|
|
6
|
+
* `queueRules`, Mongo and MySQL in their own queries — each composing the same sentences from these parts.
|
|
7
|
+
*
|
|
8
|
+
* A worker dies for many reasons — a node lost, a deploy past its grace — and the job is simply run again. But one that
|
|
9
|
+
* died near its memory (it said so: `heartbeat`'s `nearMemoryLimit`), or a second in a row to die running the same job,
|
|
10
|
+
* was taken down by the job: run again on the same size, it ends that one too, and the next. That job needs more than
|
|
11
|
+
* the worker could hold, when the claims say what their workers may (`JobClaimMemory`).
|
|
12
|
+
*/
|
|
13
|
+
/** What the history says of an attempt nobody reported. */
|
|
14
|
+
var LOST_ERROR = "the worker holding this job stopped reporting";
|
|
15
|
+
/** {@link lostError}'s words around what the worker could hold. */
|
|
16
|
+
var LOST_MEMORY_WORDS = [`${LOST_ERROR} near its memory — it could hold `, " MiB, so the job runs next on a worker that may hold more"];
|
|
17
|
+
/** {@link setAsideError}'s words around what the job needs more than, and what the largest worker may hold. */
|
|
18
|
+
var SET_ASIDE_WORDS = [
|
|
19
|
+
"Set aside: a worker died running it — it needs more than ",
|
|
20
|
+
" MiB, and the largest worker here may hold ",
|
|
21
|
+
" MiB. Give a worker more memory, then resume it."
|
|
22
|
+
];
|
|
23
|
+
/** Whether the job took its worker down: it neared its memory holding it, or the attempt before was lost too. */
|
|
24
|
+
var outgrewWorker = (job) => job.nearMemoryLimit === true || job.history.at(-1)?.status === "lost";
|
|
25
|
+
/** The least a job needs after the worker holding it died: more than that one could hold when the job took it down. */
|
|
26
|
+
var needsAfterLoss = (needsMb, holderMb, outgrew) => holderMb === void 0 || !outgrew ? needsMb : Math.max(needsMb ?? 0, holderMb + 1);
|
|
27
|
+
/** Why a job waits after its worker died: for a larger one, when it took that worker down and it said its size. */
|
|
28
|
+
var lostError = (holderMb, outgrew) => holderMb === void 0 || !outgrew ? LOST_ERROR : `${LOST_MEMORY_WORDS[0]}${String(holderMb)}${LOST_MEMORY_WORDS[1]}`;
|
|
29
|
+
/** Why a job is set aside: no worker of the deployment may hold what it needs. */
|
|
30
|
+
var setAsideError = (needsMb, ceilingMb) => `${SET_ASIDE_WORDS[0]}${String(needsMb - 1)}${SET_ASIDE_WORDS[1]}${String(ceilingMb)}${SET_ASIDE_WORDS[2]}`;
|
|
3
31
|
// src/engine/jobs/flow.ts
|
|
4
32
|
var MINUTE = 6e4;
|
|
5
33
|
var p95 = (values) => {
|
|
@@ -85,34 +113,6 @@ var groupJobs = (newestFirst) => {
|
|
|
85
113
|
}
|
|
86
114
|
return [...groups.values()];
|
|
87
115
|
};
|
|
88
|
-
// src/engine/jobs/memoryNeeds.ts
|
|
89
|
-
/**
|
|
90
|
-
* What a job needs once the worker running it died, in the words every store writes: the in-process ones through
|
|
91
|
-
* `queueRules`, Mongo and MySQL in their own queries — each composing the same sentences from these parts.
|
|
92
|
-
*
|
|
93
|
-
* A worker dies for many reasons — a node lost, a deploy past its grace — and the job is simply run again. But one that
|
|
94
|
-
* died near its memory (it said so: `heartbeat`'s `nearMemoryLimit`), or a second in a row to die running the same job,
|
|
95
|
-
* was taken down by the job: run again on the same size, it ends that one too, and the next. That job needs more than
|
|
96
|
-
* the worker could hold, when the claims say what their workers may (`JobClaimMemory`).
|
|
97
|
-
*/
|
|
98
|
-
/** What the history says of an attempt nobody reported. */
|
|
99
|
-
var LOST_ERROR = "the worker holding this job stopped reporting";
|
|
100
|
-
/** {@link lostError}'s words around what the worker could hold. */
|
|
101
|
-
var LOST_MEMORY_WORDS = [`${LOST_ERROR} near its memory — it could hold `, " MiB, so the job runs next on a worker that may hold more"];
|
|
102
|
-
/** {@link setAsideError}'s words around what the job needs more than, and what the largest worker may hold. */
|
|
103
|
-
var SET_ASIDE_WORDS = [
|
|
104
|
-
"Set aside: a worker died running it — it needs more than ",
|
|
105
|
-
" MiB, and the largest worker here may hold ",
|
|
106
|
-
" MiB. Give a worker more memory, then resume it."
|
|
107
|
-
];
|
|
108
|
-
/** Whether the job took its worker down: it neared its memory holding it, or the attempt before was lost too. */
|
|
109
|
-
var outgrewWorker = (job) => job.nearMemoryLimit === true || job.history.at(-1)?.status === "lost";
|
|
110
|
-
/** The least a job needs after the worker holding it died: more than that one could hold when the job took it down. */
|
|
111
|
-
var needsAfterLoss = (needsMb, holderMb, outgrew) => holderMb === void 0 || !outgrew ? needsMb : Math.max(needsMb ?? 0, holderMb + 1);
|
|
112
|
-
/** Why a job waits after its worker died: for a larger one, when it took that worker down and it said its size. */
|
|
113
|
-
var lostError = (holderMb, outgrew) => holderMb === void 0 || !outgrew ? LOST_ERROR : `${LOST_MEMORY_WORDS[0]}${String(holderMb)}${LOST_MEMORY_WORDS[1]}`;
|
|
114
|
-
/** Why a job is set aside: no worker of the deployment may hold what it needs. */
|
|
115
|
-
var setAsideError = (needsMb, ceilingMb) => `${SET_ASIDE_WORDS[0]}${String(needsMb - 1)}${SET_ASIDE_WORDS[1]}${String(ceilingMb)}${SET_ASIDE_WORDS[2]}`;
|
|
116
116
|
// src/engine/jobs/waitingRules.ts
|
|
117
117
|
/**
|
|
118
118
|
* What an operator does to the jobs that have not started, at once — the in-process stores' half of `cancelWaiting` and
|
|
@@ -605,4 +605,4 @@ var queueOver = (access) => ({
|
|
|
605
605
|
cancelWaiting: (...args) => access("cancelWaiting", args),
|
|
606
606
|
resumeWaiting: (...args) => access("resumeWaiting", args)
|
|
607
607
|
});
|
|
608
|
-
export {
|
|
608
|
+
export { outgrewWorker as _, emptyState as a, scheduleKey as c, flowOf as d, LOST_ERROR as f, needsAfterLoss as g, lostError as h, changedBy as i, statusCounts as l, SET_ASIDE_WORDS as m, WAITING_STATUSES as n, queueOver as o, LOST_MEMORY_WORDS as p, applyRule as r, queueRules as s, NEEDING_STATUSES as t, waitingKindOf as u };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { JobQueue } from '../../types';
|
|
2
|
+
import { Job } from '@plitzi/sdk-shared';
|
|
3
|
+
/**
|
|
4
|
+
* Whether a job was set aside for what its own code did — stopped at a limit its run reached (its CPU, its memory, its
|
|
5
|
+
* calls…), or failing every attempt — rather than by hand, at its plan's allowance (`quota`), or because a worker died
|
|
6
|
+
* running it (that one waits for a worker large enough, not for new code).
|
|
7
|
+
*/
|
|
8
|
+
export declare const setAsideByItsCode: (job: Pick<Job, "status" | "history" | "attempts" | "maxAttempts">) => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* A space's code changed — its functions or its actions saved: every job of it set aside for what its code did goes back
|
|
11
|
+
* in the queue, to run as the code now is. A schedule waiting on one fires again with it (`scheduleHold`); one that
|
|
12
|
+
* meets the same limit is set aside again, and its schedule waits again — one run, not a fire a minute. What was set
|
|
13
|
+
* aside by hand, at the plan's allowance or for a larger worker stays where it is. Answers the jobs it put back.
|
|
14
|
+
*/
|
|
15
|
+
export declare const resumeAfterCodeChange: (queue: JobQueue, spaceId: number) => Promise<string[]>;
|
|
@@ -19,9 +19,9 @@ export type KvStoreConfig = {
|
|
|
19
19
|
* written by something else is answered as the string it is rather than failing.
|
|
20
20
|
* 2. **A counter's TTL is set once, by whoever created it, and never extended.** A window refreshed on every hit
|
|
21
21
|
* never closes while traffic keeps arriving — which is a rate limit that stops limiting exactly when it is
|
|
22
|
-
* being leant on. The
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* being leant on. The adapter's `increment` gives it in the same atomic step that creates the counter: set in a
|
|
23
|
+
* second step, a store that failed it (a Redis that timed out between `INCRBY` and `EXPIRE`) kept the counter
|
|
24
|
+
* for good, and a rate limit's window never opened again.
|
|
25
25
|
* 3. **Nothing is caught.** This is not a cache: a miss means the rate limit did not count and the idempotency key
|
|
26
26
|
* was not seen, so an adapter that cannot answer fails the run rather than being read as "no value".
|
|
27
27
|
*
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ActionKvAdapter } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* The commands this adapter sends, typed by shape rather than by a client library: ioredis answers them as they are,
|
|
4
|
-
* and any client that speaks them does. `eval` is for
|
|
4
|
+
* and any client that speaks them does. `eval` is for what Redis has no single command for: `swap`, and an increment
|
|
5
|
+
* that gives the counter its lifetime in the same step.
|
|
5
6
|
*/
|
|
6
7
|
export type RedisKvClient = {
|
|
7
8
|
get: (key: string) => Promise<string | null>;
|
|
@@ -10,8 +11,6 @@ export type RedisKvClient = {
|
|
|
10
11
|
(key: string, value: string, mode: 'EX', seconds: number): Promise<unknown>;
|
|
11
12
|
};
|
|
12
13
|
del: (key: string) => Promise<number>;
|
|
13
|
-
incrby: (key: string, amount: number) => Promise<number>;
|
|
14
|
-
expire: (key: string, seconds: number) => Promise<number>;
|
|
15
14
|
eval: (script: string, keys: number, ...args: (string | number)[]) => Promise<unknown>;
|
|
16
15
|
};
|
|
17
16
|
export type RedisKvOptions = {
|
|
@@ -19,7 +18,7 @@ export type RedisKvOptions = {
|
|
|
19
18
|
prefix?: string;
|
|
20
19
|
};
|
|
21
20
|
/**
|
|
22
|
-
* An {@link ActionKvAdapter} over Redis: each operation one command, and `swap` one script.
|
|
21
|
+
* An {@link ActionKvAdapter} over Redis: each operation one command, and `swap` and `increment` one script each.
|
|
23
22
|
*
|
|
24
23
|
* `client` may be a function, for a deployment whose connection comes and goes — it is asked on every call, and a
|
|
25
24
|
* client it cannot give is its to refuse (throwing), never this adapter's to read as "no value".
|
package/dist/engine/types.d.ts
CHANGED
|
@@ -52,10 +52,13 @@ export type ActionKvAdapter = {
|
|
|
52
52
|
get: (key: string) => Promise<string | undefined>;
|
|
53
53
|
set: (key: string, value: string, ttlSeconds?: number) => Promise<void>;
|
|
54
54
|
delete: (key: string) => Promise<void>;
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Adds to a counter and answers the NEW total, in ONE atomic step — this is what get-then-set cannot be. A counter
|
|
57
|
+
* it creates (absent, or past its lifetime) is given `ttlSeconds` in that same step, and a live one keeps its own —
|
|
58
|
+
* or, holding none, takes `ttlSeconds`. Never a separate step after: a store that failed the second one kept the
|
|
59
|
+
* counter for good (a Redis that timed out between `INCRBY` and `EXPIRE` did).
|
|
60
|
+
*/
|
|
61
|
+
increment: (key: string, amount: number, ttlSeconds?: number) => Promise<number>;
|
|
59
62
|
/**
|
|
60
63
|
* Writes `next` only if the key still holds `expected` — or, with `expected` undefined, only if it holds nothing (a
|
|
61
64
|
* key past its lifetime holds nothing). Answers whether it wrote. Must be atomic: it is what lets two writers
|
package/dist/functions/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as oauthCallbackUrlOn, d as DEFAULT_FUNCTION_LIMITS, i as buildFunctions, l as readManifest, n as functionsInHand, o as DEFAULT_FUNCTION_JOB_LIMITS, r as FunctionsBuildError, t as createActionsModule, u as DEFAULT_FUNCTION_CEILINGS } from "../chunks/module-
|
|
2
|
-
import { i as readFunctionsDir, n as loadFunctions, r as loadFunctionsSource } from "../chunks/load-
|
|
1
|
+
import { c as oauthCallbackUrlOn, d as DEFAULT_FUNCTION_LIMITS, i as buildFunctions, l as readManifest, n as functionsInHand, o as DEFAULT_FUNCTION_JOB_LIMITS, r as FunctionsBuildError, t as createActionsModule, u as DEFAULT_FUNCTION_CEILINGS } from "../chunks/module-BGt8qxNC.mjs";
|
|
2
|
+
import { i as readFunctionsDir, n as loadFunctions, r as loadFunctionsSource } from "../chunks/load-CBBAXiBR.mjs";
|
|
3
3
|
import { t as credentialsFromEnv } from "../chunks/credentials-DwxZeAvH.mjs";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
import { FUNCTIONS_PROTOCOL, FunctionFailure, failedAnswerOf, readResponseMessage } from "@plitzi/sdk-shared/functions";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { fetchConnectorRecords, rebaseMedia, writeConnectorRecord } from './connectors/engine';
|
|
2
2
|
export { createConnectorResolver } from './connectors/resolver';
|
|
3
3
|
export { KEPT_CALL_MS, KEPT_CALLS_PER_SPACE } from './engine/jobs/calls';
|
|
4
|
+
export { resumeAfterCodeChange, setAsideByItsCode } from './engine/jobs/codeChanged';
|
|
4
5
|
export { createFileJobQueue } from './engine/jobs/fileQueue';
|
|
5
6
|
export { createActionJobs } from './engine/jobs/jobs';
|
|
6
7
|
export { createMemoryJobQueue } from './engine/jobs/memoryQueue';
|
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,53 @@
|
|
|
1
|
-
import { A as schedulesFor, C as fleetJobQueue, D as DEFAULT_MAX_ATTEMPTS, E as createScheduler,
|
|
2
|
-
import { n as describeTask, r as createConnectorResolver, t as describeCatalog } from "./chunks/taskCatalog-
|
|
3
|
-
import { n as stateOf, t as documentOf } from "./chunks/queueDocument-
|
|
4
|
-
import { a as emptyState, i as changedBy, l as statusCounts, o as queueOver, r as applyRule, s as queueRules } from "./chunks/queueRules-
|
|
1
|
+
import { A as schedulesFor, C as fleetJobQueue, D as DEFAULT_MAX_ATTEMPTS, E as createScheduler, L as fetchConnectorRecords, M as SET_ASIDE_LIMITS, N as KEPT_CALLS_PER_SPACE, O as scheduleFor, P as KEPT_CALL_MS, R as rebaseMedia, T as createJobWorker, _ as DEFAULT_LIMITS, a as createTaskRegistry, b as MAX_LIST_ENTRIES, f as taskName, g as spaceKvPatterns, j as createMemoryJobQueue, k as scheduleJobId, m as createSigning, p as MIN_SIGNING_SECRET_LENGTH, s as jobViewOf, t as createActionsModule, v as createKvStore, w as fleetKv, x as createActionJobs, y as MAX_LIST_BYTES, z as writeConnectorRecord } from "./chunks/module-BGt8qxNC.mjs";
|
|
2
|
+
import { n as describeTask, r as createConnectorResolver, t as describeCatalog } from "./chunks/taskCatalog-GrTxD29I.mjs";
|
|
3
|
+
import { n as stateOf, t as documentOf } from "./chunks/queueDocument-BsYXkDDZ.mjs";
|
|
4
|
+
import { a as emptyState, i as changedBy, l as statusCounts, o as queueOver, r as applyRule, s as queueRules } from "./chunks/queueRules-CJ9Huag3.mjs";
|
|
5
5
|
import { a as triggerParams, t as ActionRunError } from "./chunks/errors-bCBfIe7c.mjs";
|
|
6
|
-
import { a as createMapKv, o as createMemoryKv } from "./chunks/grants-
|
|
6
|
+
import { a as createMapKv, o as createMemoryKv } from "./chunks/grants-ZR79buug.mjs";
|
|
7
7
|
import { createActionRealtime, n as publishJobView, r as createRealtimeHub, t as createRealtimeRetained } from "./realtime/index.mjs";
|
|
8
8
|
import { t as credentialsFromEnv } from "./chunks/credentials-DwxZeAvH.mjs";
|
|
9
9
|
import { hasValidToken } from "@plitzi/sdk-shared/helpers/twigWrapper";
|
|
10
|
+
import { serverLog } from "@plitzi/sdk-kernel/log";
|
|
10
11
|
import fs from "node:fs";
|
|
11
12
|
import { parseCron, readSmtpCredential, triggerHasStaleVerify, triggerVerify } from "@plitzi/sdk-shared/actions";
|
|
12
13
|
import path from "node:path";
|
|
13
14
|
import { writeFileAtomic } from "@plitzi/sdk-kernel/files";
|
|
14
|
-
|
|
15
|
+
// src/engine/jobs/codeChanged.ts
|
|
16
|
+
/** How many of a space's jobs set aside are read at a time. */
|
|
17
|
+
var PAGE = 200;
|
|
18
|
+
/**
|
|
19
|
+
* Whether a job was set aside for what its own code did — stopped at a limit its run reached (its CPU, its memory, its
|
|
20
|
+
* calls…), or failing every attempt — rather than by hand, at its plan's allowance (`quota`), or because a worker died
|
|
21
|
+
* running it (that one waits for a worker large enough, not for new code).
|
|
22
|
+
*/
|
|
23
|
+
var setAsideByItsCode = (job) => {
|
|
24
|
+
if (job.status !== "paused") return false;
|
|
25
|
+
const last = job.history.at(-1);
|
|
26
|
+
if (last?.limit !== void 0) return last.limit !== "quota" && SET_ASIDE_LIMITS.has(last.limit);
|
|
27
|
+
return last?.status === "failed" && job.attempts >= job.maxAttempts;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* A space's code changed — its functions or its actions saved: every job of it set aside for what its code did goes back
|
|
31
|
+
* in the queue, to run as the code now is. A schedule waiting on one fires again with it (`scheduleHold`); one that
|
|
32
|
+
* meets the same limit is set aside again, and its schedule waits again — one run, not a fire a minute. What was set
|
|
33
|
+
* aside by hand, at the plan's allowance or for a larger worker stays where it is. Answers the jobs it put back.
|
|
34
|
+
*/
|
|
35
|
+
var resumeAfterCodeChange = async (queue, spaceId) => {
|
|
36
|
+
const setAside = [];
|
|
37
|
+
for (;;) {
|
|
38
|
+
const { jobs, total } = await queue.listJobs({
|
|
39
|
+
spaceIds: [spaceId],
|
|
40
|
+
status: "paused",
|
|
41
|
+
limit: PAGE,
|
|
42
|
+
offset: setAside.length
|
|
43
|
+
});
|
|
44
|
+
setAside.push(...jobs);
|
|
45
|
+
if (jobs.length === 0 || setAside.length >= total) break;
|
|
46
|
+
}
|
|
47
|
+
const again = setAside.filter(setAsideByItsCode);
|
|
48
|
+
const resumed = await Promise.all(again.map((job) => queue.resume([spaceId], job.id)));
|
|
49
|
+
return again.filter((_, index) => resumed[index]).map((job) => job.id);
|
|
50
|
+
};
|
|
15
51
|
// src/engine/fileStore.ts
|
|
16
52
|
var holderIn = (lock) => {
|
|
17
53
|
try {
|
|
@@ -483,7 +519,19 @@ end
|
|
|
483
519
|
return 1
|
|
484
520
|
`;
|
|
485
521
|
/**
|
|
486
|
-
* An
|
|
522
|
+
* An increment and its lifetime as ONE step: `INCRBY`, then — when the counter holds no lifetime, which is what one it
|
|
523
|
+
* just created holds — `EXPIRE`, with nothing in between. Two commands left the key for good when Redis timed out on
|
|
524
|
+
* the second. A live counter keeps the lifetime it has, so a window never stretches on a hit.
|
|
525
|
+
*/
|
|
526
|
+
var INCREMENT = `
|
|
527
|
+
local total = redis.call('INCRBY', KEYS[1], ARGV[1])
|
|
528
|
+
if ARGV[2] ~= '' and redis.call('TTL', KEYS[1]) == -1 then
|
|
529
|
+
redis.call('EXPIRE', KEYS[1], tonumber(ARGV[2]))
|
|
530
|
+
end
|
|
531
|
+
return total
|
|
532
|
+
`;
|
|
533
|
+
/**
|
|
534
|
+
* An {@link ActionKvAdapter} over Redis: each operation one command, and `swap` and `increment` one script each.
|
|
487
535
|
*
|
|
488
536
|
* `client` may be a function, for a deployment whose connection comes and goes — it is asked on every call, and a
|
|
489
537
|
* client it cannot give is its to refuse (throwing), never this adapter's to read as "no value".
|
|
@@ -499,10 +547,7 @@ var createRedisKv = (client, { prefix = "" } = {}) => {
|
|
|
499
547
|
delete: async (name) => {
|
|
500
548
|
await redis().del(key(name));
|
|
501
549
|
},
|
|
502
|
-
increment: (name, amount) => redis().
|
|
503
|
-
expire: async (name, ttlSeconds) => {
|
|
504
|
-
await redis().expire(key(name), ttlSeconds);
|
|
505
|
-
},
|
|
550
|
+
increment: async (name, amount, ttlSeconds) => Number(await redis().eval(INCREMENT, 1, key(name), amount, ttlSeconds === void 0 ? "" : ttlSeconds)),
|
|
506
551
|
swap: async (name, expected, next, ttlSeconds) => await redis().eval(SWAP, 1, key(name), expected === void 0 ? "absent" : "equals", expected ?? "", next, ttlSeconds === void 0 ? "" : ttlSeconds) === 1
|
|
507
552
|
};
|
|
508
553
|
};
|
|
@@ -557,4 +602,4 @@ var createJobControl = ({ queue, realtime }) => {
|
|
|
557
602
|
}
|
|
558
603
|
};
|
|
559
604
|
};
|
|
560
|
-
export { ActionRunError, DEFAULT_LIMITS, DEFAULT_MAX_ATTEMPTS, FileInUseError, KEPT_CALLS_PER_SPACE, KEPT_CALL_MS, MAX_LIST_BYTES, MAX_LIST_ENTRIES, MIN_SIGNING_SECRET_LENGTH, checkAction, createActionJobs, createActionRealtime, createActionsModule, createConnectorResolver, createFileJobQueue, createFileKv, createJobControl, createJobWorker, createKvStore, createMemoryJobQueue, createMemoryKv, createRedisKv, createRejectLogger, createRunLogger, createScheduler, createSigning, createTaskRegistry, credentialsFromEnv, describeCatalog, describeTask, fetchConnectorRecords, fleetJobQueue, fleetKv, rebaseMedia, scheduleFor, scheduleJobId, schedulesFor, spaceKvPatterns, statusCounts, taskName, writeConnectorRecord };
|
|
605
|
+
export { ActionRunError, DEFAULT_LIMITS, DEFAULT_MAX_ATTEMPTS, FileInUseError, KEPT_CALLS_PER_SPACE, KEPT_CALL_MS, MAX_LIST_BYTES, MAX_LIST_ENTRIES, MIN_SIGNING_SECRET_LENGTH, checkAction, createActionJobs, createActionRealtime, createActionsModule, createConnectorResolver, createFileJobQueue, createFileKv, createJobControl, createJobWorker, createKvStore, createMemoryJobQueue, createMemoryKv, createRedisKv, createRejectLogger, createRunLogger, createScheduler, createSigning, createTaskRegistry, credentialsFromEnv, describeCatalog, describeTask, fetchConnectorRecords, fleetJobQueue, fleetKv, rebaseMedia, resumeAfterCodeChange, scheduleFor, scheduleJobId, schedulesFor, setAsideByItsCode, spaceKvPatterns, statusCounts, taskName, writeConnectorRecord };
|
package/dist/mongo/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as flowOf, f as LOST_ERROR, l as statusCounts, m as SET_ASIDE_WORDS, n as WAITING_STATUSES, p as LOST_MEMORY_WORDS, t as NEEDING_STATUSES, u as waitingKindOf } from "../chunks/queueRules-CJ9Huag3.mjs";
|
|
2
2
|
import { t as createStoreClock } from "../chunks/storeClock-Btm7EaVm.mjs";
|
|
3
3
|
import { TERMINAL_JOB_STATUSES } from "@plitzi/sdk-shared/actions";
|
|
4
4
|
// src/mongo/claimable.ts
|
|
@@ -840,8 +840,9 @@ var createMongoKv = ({ db, collection = "action_kv" }) => {
|
|
|
840
840
|
delete: async (key) => {
|
|
841
841
|
await (await store()).deleteOne({ _id: key });
|
|
842
842
|
},
|
|
843
|
-
increment: async (key, amount) => {
|
|
843
|
+
increment: async (key, amount, ttlSeconds) => {
|
|
844
844
|
const keysNow = await store();
|
|
845
|
+
const given = ttlSeconds === void 0 ? null : expiryIn(ttlSeconds);
|
|
845
846
|
const updated = await upserting(() => keysNow.findOneAndUpdate({ _id: key }, [
|
|
846
847
|
{ $set: { live: LIVE } },
|
|
847
848
|
{ $set: {
|
|
@@ -857,8 +858,8 @@ var createMongoKv = ({ db, collection = "action_kv" }) => {
|
|
|
857
858
|
] }, amount] } },
|
|
858
859
|
expiresAt: { $cond: [
|
|
859
860
|
"$live",
|
|
860
|
-
{ $ifNull: ["$expiresAt",
|
|
861
|
-
|
|
861
|
+
{ $ifNull: ["$expiresAt", given] },
|
|
862
|
+
given
|
|
862
863
|
] }
|
|
863
864
|
} },
|
|
864
865
|
{ $unset: "live" }
|
|
@@ -868,12 +869,6 @@ var createMongoKv = ({ db, collection = "action_kv" }) => {
|
|
|
868
869
|
}));
|
|
869
870
|
return Number(updated?.value ?? amount);
|
|
870
871
|
},
|
|
871
|
-
expire: async (key, ttlSeconds) => {
|
|
872
|
-
await (await store()).updateOne({
|
|
873
|
-
_id: key,
|
|
874
|
-
$expr: LIVE
|
|
875
|
-
}, [{ $set: { expiresAt: expiryIn(ttlSeconds) } }]);
|
|
876
|
-
},
|
|
877
872
|
/**
|
|
878
873
|
* Each branch is one update Mongo applies to the document atomically. Expecting a value, the filter names it.
|
|
879
874
|
* Expecting nothing is two cases: a lapsed document, taken over by a filter that matches only a lapsed one; and no
|
package/dist/mysql/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as
|
|
1
|
+
import { _ as outgrewWorker, d as flowOf, f as LOST_ERROR, g as needsAfterLoss, h as lostError, l as statusCounts, m as SET_ASIDE_WORDS, u as waitingKindOf } from "../chunks/queueRules-CJ9Huag3.mjs";
|
|
2
2
|
import { t as createStoreClock } from "../chunks/storeClock-Btm7EaVm.mjs";
|
|
3
3
|
import { TERMINAL_JOB_STATUSES } from "@plitzi/sdk-shared/actions";
|
|
4
4
|
import { execute, selectOne, selectRows } from "@plitzi/sdk-kernel/mysql";
|
|
@@ -891,21 +891,25 @@ var createMysqlKv = ({ pool, tablePrefix = "", createTables = true }) => {
|
|
|
891
891
|
delete: async (key) => {
|
|
892
892
|
await execute(await db(), `DELETE FROM ${kv} WHERE k = ?`, [key]);
|
|
893
893
|
},
|
|
894
|
-
increment: async (key, amount) => {
|
|
894
|
+
increment: async (key, amount, ttlSeconds) => {
|
|
895
895
|
const connection = await (await db()).getConnection();
|
|
896
896
|
try {
|
|
897
897
|
await connection.beginTransaction();
|
|
898
898
|
/**
|
|
899
899
|
* `v` FIRST: the assignments run left to right and each sees the ones before it, so the value has to be
|
|
900
900
|
* computed while `expires_at` still says whether the old one is alive. A lapsed counter starts again from
|
|
901
|
-
* zero,
|
|
901
|
+
* zero, with the lifetime it is given; a live one keeps its own, or takes the one given when it has none —
|
|
902
|
+
* in this statement, never one after it. `+ 0` reads the text as a number, as Redis reads its strings.
|
|
902
903
|
*/
|
|
903
|
-
|
|
904
|
+
const expiry = ttlSeconds === void 0 ? "NULL" : `${NOW_MS} + ?`;
|
|
905
|
+
const lifetime = ttlSeconds === void 0 ? [] : [ttlSeconds * 1e3];
|
|
906
|
+
await execute(connection, `INSERT INTO ${kv} (k, v, expires_at) VALUES (?, CAST(? AS CHAR), ${expiry})
|
|
904
907
|
ON DUPLICATE KEY UPDATE
|
|
905
908
|
v = CAST(IF(${LIVE}, (v + 0) + ?, ?) AS CHAR),
|
|
906
|
-
expires_at = IF(${LIVE}, expires_at,
|
|
909
|
+
expires_at = IF(${LIVE}, COALESCE(expires_at, VALUES(expires_at)), VALUES(expires_at))`, [
|
|
907
910
|
key,
|
|
908
911
|
amount,
|
|
912
|
+
...lifetime,
|
|
909
913
|
amount,
|
|
910
914
|
amount
|
|
911
915
|
]);
|
|
@@ -919,9 +923,6 @@ var createMysqlKv = ({ pool, tablePrefix = "", createTables = true }) => {
|
|
|
919
923
|
connection.release();
|
|
920
924
|
}
|
|
921
925
|
},
|
|
922
|
-
expire: async (key, ttlSeconds) => {
|
|
923
|
-
await execute(await db(), `UPDATE ${kv} SET expires_at = ${NOW_MS} + ? WHERE k = ? AND ${LIVE}`, [ttlSeconds * 1e3, key]);
|
|
924
|
-
},
|
|
925
926
|
/**
|
|
926
927
|
* Each branch is ONE statement MySQL applies under the row's lock, so two writers racing for the same key cannot
|
|
927
928
|
* both win. `affectedRows` counts the rows MATCHED because mysql2 connects with `FOUND_ROWS`: without it, writing
|
package/dist/realtime/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as KV_METHODS, o as createMemoryKv, r as createRealtimeGrants } from "../chunks/grants-
|
|
1
|
+
import { i as KV_METHODS, o as createMemoryKv, r as createRealtimeGrants } from "../chunks/grants-ZR79buug.mjs";
|
|
2
2
|
import { randomBytes, randomUUID } from "node:crypto";
|
|
3
3
|
import { isRecord } from "@plitzi/sdk-shared/helpers";
|
|
4
4
|
import { accessRefusal } from "@plitzi/sdk-shared/actions";
|
package/dist/sqlite/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as stateOf, t as documentOf } from "../chunks/queueDocument-
|
|
2
|
-
import { a as emptyState, i as changedBy, o as queueOver, r as applyRule, s as queueRules } from "../chunks/queueRules-
|
|
1
|
+
import { n as stateOf, t as documentOf } from "../chunks/queueDocument-BsYXkDDZ.mjs";
|
|
2
|
+
import { a as emptyState, i as changedBy, o as queueOver, r as applyRule, s as queueRules } from "../chunks/queueRules-CJ9Huag3.mjs";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { DatabaseSync } from "node:sqlite";
|
|
@@ -107,14 +107,13 @@ var createSqliteKv = (options) => {
|
|
|
107
107
|
set: db.prepare(`INSERT INTO ${table} (key, value, expires_at) VALUES (?, ?, ${expiresAt})
|
|
108
108
|
ON CONFLICT (key) DO UPDATE SET value = excluded.value, expires_at = excluded.expires_at`),
|
|
109
109
|
delete: db.prepare(`DELETE FROM ${table} WHERE key = ?`),
|
|
110
|
-
increment: db.prepare(`INSERT INTO ${table} (key, value, expires_at) VALUES (?, ?,
|
|
110
|
+
increment: db.prepare(`INSERT INTO ${table} (key, value, expires_at) VALUES (?, ?, ${expiresAt})
|
|
111
111
|
ON CONFLICT (key) DO UPDATE SET
|
|
112
112
|
value = CASE WHEN ${table}.expires_at IS NOT NULL AND ${table}.expires_at <= ${NOW_MS}
|
|
113
113
|
THEN excluded.value ELSE CAST(${table}.value + ? AS TEXT) END,
|
|
114
114
|
expires_at = CASE WHEN ${table}.expires_at IS NOT NULL AND ${table}.expires_at <= ${NOW_MS}
|
|
115
|
-
THEN
|
|
115
|
+
THEN excluded.expires_at ELSE COALESCE(${table}.expires_at, excluded.expires_at) END
|
|
116
116
|
RETURNING value`),
|
|
117
|
-
expire: db.prepare(`UPDATE ${table} SET expires_at = ${expiresAt} WHERE key = ? AND ${live}`),
|
|
118
117
|
claim: db.prepare(`INSERT INTO ${table} (key, value, expires_at) VALUES (?, ?, ${expiresAt})
|
|
119
118
|
ON CONFLICT (key) DO UPDATE SET value = excluded.value, expires_at = excluded.expires_at
|
|
120
119
|
WHERE ${table}.expires_at IS NOT NULL AND ${table}.expires_at <= ${NOW_MS}`),
|
|
@@ -140,16 +139,12 @@ var createSqliteKv = (options) => {
|
|
|
140
139
|
statements.delete.run(key);
|
|
141
140
|
return Promise.resolve();
|
|
142
141
|
},
|
|
143
|
-
increment: (key, amount) => {
|
|
142
|
+
increment: (key, amount, ttlSeconds) => {
|
|
144
143
|
const step = Number.isInteger(amount) ? BigInt(amount) : amount;
|
|
145
|
-
const value = text(statements.increment.get(key, String(amount), step));
|
|
144
|
+
const value = text(statements.increment.get(key, String(amount), expiry(ttlSeconds), expiry(ttlSeconds), step));
|
|
146
145
|
sweep();
|
|
147
146
|
return Promise.resolve(Number(value ?? amount));
|
|
148
147
|
},
|
|
149
|
-
expire: (key, ttlSeconds) => {
|
|
150
|
-
statements.expire.run(expiry(ttlSeconds), expiry(ttlSeconds), key);
|
|
151
|
-
return Promise.resolve();
|
|
152
|
-
},
|
|
153
148
|
swap: (key, expected, next, ttlSeconds) => {
|
|
154
149
|
const written = expected === void 0 ? statements.claim.run(key, next, expiry(ttlSeconds), expiry(ttlSeconds)) : statements.replace.run(next, expiry(ttlSeconds), expiry(ttlSeconds), key, expected);
|
|
155
150
|
sweep();
|
package/dist/types/config.d.ts
CHANGED
|
@@ -185,9 +185,9 @@ export type SSRActionConfig = {
|
|
|
185
185
|
/**
|
|
186
186
|
* Where the `kv` tasks keep things — shaped as `ActionKvAdapter` in `@plitzi/sdk-actions`.
|
|
187
187
|
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
188
|
+
* Five operations over strings: Redis, Memcached, a table, whatever this deployment already runs. How a counter
|
|
189
|
+
* BEHAVES — the key prefixing, the JSON round trip — belongs to the server; the one rule a store keeps is that an
|
|
190
|
+
* increment gives the counter it creates its lifetime in the same atomic step.
|
|
191
191
|
*
|
|
192
192
|
* Omitted leaves an in-process Map, which counts only its own replica. That is fine for one; for a cluster it is
|
|
193
193
|
* a rate limit that multiplies by the number of them, so a multi-replica deployment supplies a shared one.
|
|
@@ -196,8 +196,8 @@ export type SSRActionConfig = {
|
|
|
196
196
|
get: (key: string) => Promise<string | undefined>;
|
|
197
197
|
set: (key: string, value: string, ttlSeconds?: number) => Promise<void>;
|
|
198
198
|
delete: (key: string) => Promise<void>;
|
|
199
|
-
|
|
200
|
-
|
|
199
|
+
/** Adds, atomically; a counter it creates — or one holding no lifetime — is given `ttlSeconds` in the same step. */
|
|
200
|
+
increment: (key: string, amount: number, ttlSeconds?: number) => Promise<number>;
|
|
201
201
|
/** Writes `next` only if the key holds `expected` (nothing, when undefined); answers whether it wrote. Atomic. */
|
|
202
202
|
swap: (key: string, expected: string | undefined, next: string, ttlSeconds?: number) => Promise<boolean>;
|
|
203
203
|
};
|
package/dist/worker/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { handleRealtimePublish, handleRealtimeSocket, handleRealtimeSubscribe, realtimeModuleFor } from "../realtime/index.mjs";
|
|
2
2
|
import { a as createActionResolver, i as readRenderAsk, n as RENDER_PATH, t as createRemoteRenderResolver } from "../chunks/remote-DZSzOO01.mjs";
|
|
3
|
-
import { F as
|
|
3
|
+
import { F as keepCall, I as readKeptCall, S as ACTIONS_FLEET_STORES, h as precheckRun, t as createActionsModule, z as writeConnectorRecord } from "../chunks/module-BGt8qxNC.mjs";
|
|
4
4
|
import { a as triggerParams, i as findTriggerNode, t as ActionRunError } from "../chunks/errors-bCBfIe7c.mjs";
|
|
5
|
-
import { r as createConnectorResolver, t as describeCatalog } from "../chunks/taskCatalog-
|
|
6
|
-
import { t as isFunctionsDefinition } from "../chunks/load-
|
|
5
|
+
import { r as createConnectorResolver, t as describeCatalog } from "../chunks/taskCatalog-GrTxD29I.mjs";
|
|
6
|
+
import { t as isFunctionsDefinition } from "../chunks/load-CBBAXiBR.mjs";
|
|
7
7
|
import { privateOriginsOf } from "@plitzi/sdk-kernel/outbound";
|
|
8
8
|
import { isConnectorManifestDraft, validateConnectorManifest } from "@plitzi/sdk-shared/connectors";
|
|
9
9
|
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
10
|
+
import { configureServerLog, defaultLogLevel, serverLog } from "@plitzi/sdk-kernel/log";
|
|
10
11
|
import { isRecord } from "@plitzi/sdk-shared/helpers";
|
|
11
12
|
import { FUNCTION_ROUTES_PREFIX, isActionDocument, triggerAccess, triggerHasStaleVerify, triggerVerify, validateActionDocument } from "@plitzi/sdk-shared/actions";
|
|
12
|
-
import { configureServerLog, defaultLogLevel, serverLog } from "@plitzi/sdk-kernel/log";
|
|
13
13
|
import { statsRecorderFor, statsStage } from "@plitzi/sdk-kernel/stats";
|
|
14
14
|
import { protocolRefusal } from "@plitzi/sdk-shared/functions";
|
|
15
15
|
import { bearerMatches, clientIp, createHttpServer, createMiddlewaresStage, crossSiteWritesStage, healthStage, makeHandler, onAbort, openEventStream, readRawBody, readRawBytes, requestAuthority, requestOrigin, runsFleetJobs, writeWebResponse } from "@plitzi/sdk-kernel/http";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plitzi/sdk-actions",
|
|
3
|
-
"version": "0.39.
|
|
3
|
+
"version": "0.39.15",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"description": "The actions engine: server actions, a space's functions and runtimes as the platform holds them, the connectors, realtime, jobs, and the stock queues and stores. What a worker runs; what a page server is handed.",
|
|
6
6
|
"files": [
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"build:prod": "vite build"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@plitzi/sdk-kernel": "0.39.
|
|
41
|
-
"@plitzi/sdk-shared": "0.39.
|
|
40
|
+
"@plitzi/sdk-kernel": "0.39.15",
|
|
41
|
+
"@plitzi/sdk-shared": "0.39.15",
|
|
42
42
|
"nodemailer": "^10.6.0",
|
|
43
43
|
"ws": "^8.23.0"
|
|
44
44
|
},
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
}
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@plitzi/sdk-runtime": "0.39.
|
|
62
|
+
"@plitzi/sdk-runtime": "0.39.15",
|
|
63
63
|
"@types/node": "^26.6.6",
|
|
64
64
|
"@types/nodemailer": "^8.0.2",
|
|
65
65
|
"@types/ws": "^8.18.2",
|