@plitzi/sdk-actions 0.39.7 → 0.39.8
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 +10 -0
- package/dist/chunks/{load-DxIZm6AM.mjs → load-CKHHu7UP.mjs} +1 -1
- package/dist/chunks/{module-CqtrQfYf.mjs → module-CAk06qne.mjs} +44 -21
- package/dist/chunks/{queueDocument-4M64XO0Q.mjs → queueDocument-B3y8qr0i.mjs} +1 -1
- package/dist/chunks/{queueRules-Dk8mNzEJ.mjs → queueRules-B3AGQGPs.mjs} +21 -1
- package/dist/chunks/{taskCatalog-1Jc6_ZAn.mjs → taskCatalog-Cq7B1kUM.mjs} +1 -1
- package/dist/engine/jobs/endings.d.ts +17 -9
- package/dist/engine/jobs/scheduler.d.ts +2 -0
- package/dist/functions/index.mjs +2 -2
- package/dist/functions/jobControl.d.ts +3 -3
- package/dist/index.mjs +14 -7
- package/dist/mongo/dropWaiting.d.ts +8 -0
- package/dist/mongo/index.mjs +37 -1
- package/dist/mongo/jobQueue.d.ts +6 -0
- package/dist/mysql/index.mjs +31 -1
- package/dist/sqlite/index.mjs +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/jobs.d.ts +25 -0
- package/dist/worker/index.mjs +3 -3
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @plitzi/sdk-actions
|
|
2
2
|
|
|
3
|
+
## 0.39.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fd14ce2: 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 [fd14ce2]
|
|
10
|
+
- @plitzi/sdk-kernel@0.39.8
|
|
11
|
+
- @plitzi/sdk-shared@0.39.8
|
|
12
|
+
|
|
3
13
|
## 0.39.7
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as buildFunctions } from "./module-
|
|
1
|
+
import { i as buildFunctions } from "./module-CAk06qne.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,4 +1,4 @@
|
|
|
1
|
-
import { a as emptyState, c as queueRules, r as applyRule, s as queueOver } from "./queueRules-
|
|
1
|
+
import { a as emptyState, c as queueRules, p as SET_ASIDE_WORDS, r as applyRule, s as queueOver } from "./queueRules-B3AGQGPs.mjs";
|
|
2
2
|
import { a as triggerParams, i as findTriggerNode, n as RunLimitReached, r as limitOf, t as ActionRunError } from "./errors-bCBfIe7c.mjs";
|
|
3
3
|
import { i as KV_METHODS, n as MAX_GRANT_SECONDS, o as createMemoryKv, t as DEFAULT_GRANT_SECONDS } from "./grants-BsD-WlLE.mjs";
|
|
4
4
|
import { cappedResponse, fetchOutbound, isBlockedHost } from "@plitzi/sdk-kernel/outbound";
|
|
@@ -432,7 +432,8 @@ var JOB_QUEUE_METHODS = {
|
|
|
432
432
|
cancel: true,
|
|
433
433
|
pause: true,
|
|
434
434
|
resume: true,
|
|
435
|
-
cancelPending: true
|
|
435
|
+
cancelPending: true,
|
|
436
|
+
cancelWaiting: true
|
|
436
437
|
};
|
|
437
438
|
/**
|
|
438
439
|
* The default queue: one process's Maps.
|
|
@@ -491,19 +492,44 @@ var SET_ASIDE_LIMITS = /* @__PURE__ */ new Set([
|
|
|
491
492
|
"response",
|
|
492
493
|
"quota"
|
|
493
494
|
]);
|
|
495
|
+
var HOUR_MS = 36e5;
|
|
494
496
|
/**
|
|
495
|
-
*
|
|
496
|
-
*
|
|
497
|
-
*
|
|
497
|
+
* What the code meets again at the next fire, as it would at the next attempt: a day before the schedule tries one by
|
|
498
|
+
* itself. What a run holds can depend on the day's data, and nobody may be watching — held for ever by one large day,
|
|
499
|
+
* a feed would never come back; a day apart it is one run that says where it stands, not one a minute.
|
|
498
500
|
*/
|
|
499
|
-
var
|
|
501
|
+
var AGAIN_IN_A_DAY = {
|
|
502
|
+
retryMs: 24 * HOUR_MS,
|
|
503
|
+
retryIn: "a day"
|
|
504
|
+
};
|
|
500
505
|
/**
|
|
501
|
-
*
|
|
502
|
-
*
|
|
506
|
+
* Its allowance for the period spent: nobody resumes a job for that — it comes back when the period turns, or the plan
|
|
507
|
+
* changes — so the schedule asks again by itself, an hour apart: back within the hour, and never a job a minute.
|
|
508
|
+
*/
|
|
509
|
+
var AGAIN_IN_AN_HOUR = {
|
|
510
|
+
retryMs: HOUR_MS,
|
|
511
|
+
retryIn: "an hour"
|
|
512
|
+
};
|
|
513
|
+
/**
|
|
514
|
+
* Why a schedule waits on the fire before it, when it does: that job is set aside (`paused`) at something the next
|
|
515
|
+
* fire would meet too — a limit of {@link SET_ASIDE_LIMITS} its last attempt ended at, or a worker died running it and
|
|
516
|
+
* none here may hold what it needs (the next fire starts at that need). Fired into, each is one more job set aside per
|
|
517
|
+
* fire, for as long as nobody looks: a queue that only grows.
|
|
518
|
+
*
|
|
519
|
+
* A job set aside after failing every attempt is not one: the next fire may pass, and takes its place
|
|
520
|
+
* (`createScheduler`).
|
|
503
521
|
*/
|
|
504
|
-
var
|
|
505
|
-
|
|
506
|
-
|
|
522
|
+
var scheduleHold = (job) => {
|
|
523
|
+
if (job.status !== "paused") return;
|
|
524
|
+
const limit = job.history.at(-1)?.limit;
|
|
525
|
+
if (limit !== void 0 && SET_ASIDE_LIMITS.has(limit)) return {
|
|
526
|
+
limit,
|
|
527
|
+
...limit === "quota" ? AGAIN_IN_AN_HOUR : AGAIN_IN_A_DAY
|
|
528
|
+
};
|
|
529
|
+
return job.error?.startsWith(SET_ASIDE_WORDS[0]) ? {
|
|
530
|
+
limit: "memory",
|
|
531
|
+
...AGAIN_IN_A_DAY
|
|
532
|
+
} : void 0;
|
|
507
533
|
};
|
|
508
534
|
/** Why a job stopped at one of {@link SET_ASIDE_LIMITS} waits for somebody. */
|
|
509
535
|
var limitSetAsideError = (said) => `Set aside at once: it reached a limit its plan sets, which it would reach again on every attempt. Fix it, or give its plan more, then resume it. It said: ${said}`;
|
|
@@ -633,12 +659,6 @@ var MINUTE_MS = 6e4;
|
|
|
633
659
|
* {@link cronNextFire} searches: nothing inside it matched, so nothing inside it will. */
|
|
634
660
|
var PARK_MS = 2108160 * MINUTE_MS;
|
|
635
661
|
/**
|
|
636
|
-
* How long a schedule waits on a fire set aside at a limit before it tries one again by itself. What a run holds can
|
|
637
|
-
* depend on the day's data, and nobody may be watching: held for ever by one large day, a feed would never come back.
|
|
638
|
-
* A day apart it is one run that says where it stands — not one a minute.
|
|
639
|
-
*/
|
|
640
|
-
var HELD_RETRY_MS = 1440 * MINUTE_MS;
|
|
641
|
-
/**
|
|
642
662
|
* Turns due schedules into jobs. Nothing else.
|
|
643
663
|
*
|
|
644
664
|
* **There is no leader.** Every replica sweeps, and that is safe because a fire's job id is derived from the fire's
|
|
@@ -689,12 +709,13 @@ var createScheduler = ({ queue, lookups, environment = "main", pollMs = 15e3, ba
|
|
|
689
709
|
}
|
|
690
710
|
const id = scheduleJobId(spaceId, actionId, fireAt);
|
|
691
711
|
const before = schedule.lastFireAt === void 0 ? void 0 : await queue.getJob([spaceId], scheduleJobId(spaceId, actionId, schedule.lastFireAt));
|
|
692
|
-
const
|
|
712
|
+
const hold = before ? scheduleHold(before) : void 0;
|
|
693
713
|
const key = `${String(spaceId)}:${actionId}`;
|
|
694
|
-
if (before &&
|
|
714
|
+
if (before && hold && at.getTime() - before.dueAt < hold.retryMs) {
|
|
715
|
+
const { limit } = hold;
|
|
695
716
|
if (waiting.get(key) !== before.id) {
|
|
696
717
|
waiting.set(key, before.id);
|
|
697
|
-
serverLog.warn("Actions", `schedule ${actionId} of space ${String(spaceId)} waits: its run ${before.id} was set aside at its ${limit} limit, which the next would reach too. It fires again once that job is resumed or cancelled, and tries one by itself
|
|
718
|
+
serverLog.warn("Actions", `schedule ${actionId} of space ${String(spaceId)} waits: its run ${before.id} was set aside at its ${limit} limit, which the next would reach too. It fires again once that job is resumed or cancelled, and tries one by itself ${hold.retryIn} after it.`);
|
|
698
719
|
}
|
|
699
720
|
result.held.push({
|
|
700
721
|
spaceId,
|
|
@@ -729,6 +750,7 @@ var createScheduler = ({ queue, lookups, environment = "main", pollMs = 15e3, ba
|
|
|
729
750
|
maxAttempts: schedule.maxAttempts,
|
|
730
751
|
...before?.needsMemoryMb === void 0 ? {} : { needsMemoryMb: before.needsMemoryMb }
|
|
731
752
|
}) ? result.enqueued : result.duplicates).push(id);
|
|
753
|
+
if (before?.status === "paused" && await queue.cancel([spaceId], before.id)) result.superseded.push(before.id);
|
|
732
754
|
const lateness = Math.max(fireAt, at.getTime());
|
|
733
755
|
const missed = cronFiresBetween(cron, new Date(fireAt), new Date(lateness), timezone);
|
|
734
756
|
/**
|
|
@@ -756,7 +778,8 @@ var createScheduler = ({ queue, lookups, environment = "main", pollMs = 15e3, ba
|
|
|
756
778
|
enqueued: [],
|
|
757
779
|
duplicates: [],
|
|
758
780
|
missed: [],
|
|
759
|
-
held: []
|
|
781
|
+
held: [],
|
|
782
|
+
superseded: []
|
|
760
783
|
};
|
|
761
784
|
const at = await queue.now();
|
|
762
785
|
for (const schedule of await queue.dueSchedules(batch)) await produce(schedule, at, result);
|
|
@@ -91,6 +91,8 @@ var takesSpace = (spaces, spaceId) => !spaces || ("only" in spaces ? spaces.only
|
|
|
91
91
|
* whatever spaces it is kept for: the larger workers are few, and the job's own space's may all be the size that died.
|
|
92
92
|
*/
|
|
93
93
|
var fits = (job, spaces, memory) => job.needsMemoryMb === void 0 ? takesSpace(spaces, job.spaceId) : memory !== void 0 && memory.takesNeeding !== false && memory.mb >= job.needsMemoryMb;
|
|
94
|
+
/** Whether what `cancelWaiting` answered says it dropped a job. */
|
|
95
|
+
var droppedSome = (answer) => typeof answer === "object" && answer !== null && "cancelled" in answer && typeof answer.cancelled === "number" && answer.cancelled > 0;
|
|
94
96
|
/**
|
|
95
97
|
* Whether a call changed the state, by its method and what it answered — what a store keeping the state elsewhere writes
|
|
96
98
|
* back after. A worker claims every second: a claim that took nothing, a refused `write` or `cancel` change nothing, and
|
|
@@ -107,6 +109,7 @@ var changedBy = (method, answer) => {
|
|
|
107
109
|
case "pause":
|
|
108
110
|
case "resume": return answer === true;
|
|
109
111
|
case "cancelPending": return typeof answer === "number" && answer > 0;
|
|
112
|
+
case "cancelWaiting": return droppedSome(answer);
|
|
110
113
|
case "heartbeat":
|
|
111
114
|
case "settle":
|
|
112
115
|
case "putSchedules": return true;
|
|
@@ -362,6 +365,22 @@ var queueRules = ({ jobs, schedules }, { retainFinished, clock, onUnansweredChan
|
|
|
362
365
|
dropped += 1;
|
|
363
366
|
}
|
|
364
367
|
return dropped;
|
|
368
|
+
},
|
|
369
|
+
cancelWaiting: ({ spaceIds, status, kind, name }) => {
|
|
370
|
+
const at = now();
|
|
371
|
+
const dropped = {
|
|
372
|
+
cancelled: 0,
|
|
373
|
+
functionJobs: []
|
|
374
|
+
};
|
|
375
|
+
for (const job of jobs.values()) if (spaceIds.includes(job.spaceId) && (job.status === "pending" || job.status === "paused") && (status === void 0 || job.status === status) && (kind === void 0 || job.target.kind === kind) && (name === void 0 || job.target.name === name)) {
|
|
376
|
+
job.status = "cancelled";
|
|
377
|
+
job.workerId = void 0;
|
|
378
|
+
job.pauseRequested = void 0;
|
|
379
|
+
job.updatedAt = at;
|
|
380
|
+
dropped.cancelled += 1;
|
|
381
|
+
if (job.target.kind === "function") dropped.functionJobs.push(job.id);
|
|
382
|
+
}
|
|
383
|
+
return dropped;
|
|
365
384
|
}
|
|
366
385
|
};
|
|
367
386
|
};
|
|
@@ -482,6 +501,7 @@ var queueOver = (access) => ({
|
|
|
482
501
|
cancel: (...args) => access("cancel", args),
|
|
483
502
|
pause: (...args) => access("pause", args),
|
|
484
503
|
resume: (...args) => access("resume", args),
|
|
485
|
-
cancelPending: (...args) => access("cancelPending", args)
|
|
504
|
+
cancelPending: (...args) => access("cancelPending", args),
|
|
505
|
+
cancelWaiting: (...args) => access("cancelWaiting", args)
|
|
486
506
|
});
|
|
487
507
|
export { flowOf as _, emptyState as a, queueRules as c, LOST_ERROR as d, LOST_MEMORY_WORDS as f, outgrewWorker as g, needsAfterLoss as h, changedBy as i, scheduleKey as l, lostError as m, WAITING_STATUSES as n, noJobsByStatus as o, SET_ASIDE_WORDS as p, applyRule as r, queueOver as s, NEEDING_STATUSES as t, waitingKindOf as u };
|
|
@@ -22,17 +22,25 @@ export declare const GIVE_UP: Set<string>;
|
|
|
22
22
|
* for a minute answers the next attempt.
|
|
23
23
|
*/
|
|
24
24
|
export declare const SET_ASIDE_LIMITS: Set<ActionRunLimit>;
|
|
25
|
+
/** Why a schedule waits on the fire before it, and when it tries one by itself. */
|
|
26
|
+
export type ScheduleHold = {
|
|
27
|
+
/** What the fire before was set aside at. */
|
|
28
|
+
limit: ActionRunLimit;
|
|
29
|
+
/** How long after that fire the schedule tries one by itself. */
|
|
30
|
+
retryMs: number;
|
|
31
|
+
/** `retryMs` in words, for the line that says it waits. */
|
|
32
|
+
retryIn: string;
|
|
33
|
+
};
|
|
25
34
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
*
|
|
33
|
-
* limit of {@link HOLDS_SCHEDULE}. A job set aside after failing every attempt is not one — the next fire may pass.
|
|
35
|
+
* Why a schedule waits on the fire before it, when it does: that job is set aside (`paused`) at something the next
|
|
36
|
+
* fire would meet too — a limit of {@link SET_ASIDE_LIMITS} its last attempt ended at, or a worker died running it and
|
|
37
|
+
* none here may hold what it needs (the next fire starts at that need). Fired into, each is one more job set aside per
|
|
38
|
+
* fire, for as long as nobody looks: a queue that only grows.
|
|
39
|
+
*
|
|
40
|
+
* A job set aside after failing every attempt is not one: the next fire may pass, and takes its place
|
|
41
|
+
* (`createScheduler`).
|
|
34
42
|
*/
|
|
35
|
-
export declare const
|
|
43
|
+
export declare const scheduleHold: (job: Pick<Job, "status" | "history" | "error">) => ScheduleHold | undefined;
|
|
36
44
|
/** Why a job stopped at one of {@link SET_ASIDE_LIMITS} waits for somebody. */
|
|
37
45
|
export declare const limitSetAsideError: (said: string) => string;
|
|
38
46
|
/**
|
|
@@ -44,6 +44,8 @@ export type SweepResult = {
|
|
|
44
44
|
jobId: string;
|
|
45
45
|
limit: ActionRunLimit;
|
|
46
46
|
}[];
|
|
47
|
+
/** Jobs still set aside when their schedule fired again, cancelled: the new fire stands for them. */
|
|
48
|
+
superseded: string[];
|
|
47
49
|
};
|
|
48
50
|
export type Scheduler = {
|
|
49
51
|
/** One pass. Exposed because a deployment driving this from its own cron — a k8s CronJob, a queue tick — needs
|
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-CAk06qne.mjs";
|
|
2
|
+
import { i as readFunctionsDir, n as loadFunctions, r as loadFunctionsSource } from "../chunks/load-CKHHu7UP.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";
|
|
@@ -13,10 +13,10 @@ export type JobControlOptions = {
|
|
|
13
13
|
kv: ActionKvAdapter;
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
|
-
export type JobControl = Pick<JobQueue, 'pause' | 'resume' | 'cancel' | 'requeue'>;
|
|
16
|
+
export type JobControl = Pick<JobQueue, 'pause' | 'resume' | 'cancel' | 'requeue' | 'cancelWaiting'>;
|
|
17
17
|
/**
|
|
18
18
|
* An operator's hold on the jobs, from a process that serves no pages — a deployment's API behind its Queue panel: the
|
|
19
|
-
* queue's own `pause`, `resume`, `cancel` and `
|
|
20
|
-
* functions, as the page server says it when its code does the same.
|
|
19
|
+
* queue's own `pause`, `resume`, `cancel`, `requeue` and `cancelWaiting`, each said on `$job:<id>` when it changed a job
|
|
20
|
+
* of the spaces' functions, as the page server says it when its code does the same.
|
|
21
21
|
*/
|
|
22
22
|
export declare const createJobControl: ({ queue, realtime }: JobControlOptions) => JobControl;
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { A as schedulesFor, C as fleetJobQueue, D as DEFAULT_MAX_ATTEMPTS, E as createScheduler, I as fetchConnectorRecords, L as rebaseMedia, M as KEPT_CALLS_PER_SPACE, N as KEPT_CALL_MS, O as scheduleFor, R as writeConnectorRecord, 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 } from "./chunks/module-
|
|
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, c as queueRules, i as changedBy, r as applyRule, s as queueOver } from "./chunks/queueRules-
|
|
1
|
+
import { A as schedulesFor, C as fleetJobQueue, D as DEFAULT_MAX_ATTEMPTS, E as createScheduler, I as fetchConnectorRecords, L as rebaseMedia, M as KEPT_CALLS_PER_SPACE, N as KEPT_CALL_MS, O as scheduleFor, R as writeConnectorRecord, 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 } from "./chunks/module-CAk06qne.mjs";
|
|
2
|
+
import { n as describeTask, r as createConnectorResolver, t as describeCatalog } from "./chunks/taskCatalog-Cq7B1kUM.mjs";
|
|
3
|
+
import { n as stateOf, t as documentOf } from "./chunks/queueDocument-B3y8qr0i.mjs";
|
|
4
|
+
import { a as emptyState, c as queueRules, i as changedBy, r as applyRule, s as queueOver } from "./chunks/queueRules-B3AGQGPs.mjs";
|
|
5
5
|
import { a as triggerParams, t as ActionRunError } from "./chunks/errors-bCBfIe7c.mjs";
|
|
6
6
|
import { a as createMapKv, o as createMemoryKv } from "./chunks/grants-BsD-WlLE.mjs";
|
|
7
7
|
import { createActionRealtime, n as publishJobView, r as createRealtimeHub, t as createRealtimeRetained } from "./realtime/index.mjs";
|
|
@@ -507,10 +507,12 @@ var createRedisKv = (client, { prefix = "" } = {}) => {
|
|
|
507
507
|
};
|
|
508
508
|
};
|
|
509
509
|
// src/functions/jobControl.ts
|
|
510
|
+
/** How many of the jobs dropped at once (`cancelWaiting`) have their watchers told at a time. */
|
|
511
|
+
var ANNOUNCED_AT_ONCE = 20;
|
|
510
512
|
/**
|
|
511
513
|
* An operator's hold on the jobs, from a process that serves no pages — a deployment's API behind its Queue panel: the
|
|
512
|
-
* queue's own `pause`, `resume`, `cancel` and `
|
|
513
|
-
* functions, as the page server says it when its code does the same.
|
|
514
|
+
* queue's own `pause`, `resume`, `cancel`, `requeue` and `cancelWaiting`, each said on `$job:<id>` when it changed a job
|
|
515
|
+
* of the spaces' functions, as the page server says it when its code does the same.
|
|
514
516
|
*/
|
|
515
517
|
var createJobControl = ({ queue, realtime }) => {
|
|
516
518
|
const said = realtime ? {
|
|
@@ -539,7 +541,12 @@ var createJobControl = ({ queue, realtime }) => {
|
|
|
539
541
|
pause: told((spaceIds, jobId) => queue.pause(spaceIds, jobId)),
|
|
540
542
|
resume: told((spaceIds, jobId) => queue.resume(spaceIds, jobId)),
|
|
541
543
|
cancel: told((spaceIds, jobId) => queue.cancel(spaceIds, jobId)),
|
|
542
|
-
requeue: told((spaceIds, jobId, options) => queue.requeue(spaceIds, jobId, options))
|
|
544
|
+
requeue: told((spaceIds, jobId, options) => queue.requeue(spaceIds, jobId, options)),
|
|
545
|
+
cancelWaiting: async (query) => {
|
|
546
|
+
const dropped = await queue.cancelWaiting(query);
|
|
547
|
+
for (let from = 0; from < dropped.functionJobs.length; from += ANNOUNCED_AT_ONCE) await Promise.all(dropped.functionJobs.slice(from, from + ANNOUNCED_AT_ONCE).map((jobId) => announce(query.spaceIds, jobId)));
|
|
548
|
+
return dropped;
|
|
549
|
+
}
|
|
543
550
|
};
|
|
544
551
|
};
|
|
545
552
|
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, taskName, writeConnectorRecord };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { JobDocument } from './jobQueue';
|
|
2
|
+
import { JobsDropped, JobsToDrop } from '../types';
|
|
3
|
+
import { Collection } from 'mongodb';
|
|
4
|
+
/**
|
|
5
|
+
* `JobQueue.cancelWaiting` over the jobs' collection: everything of these spaces that has not started is `cancelled` at
|
|
6
|
+
* `at`, in one statement, and kept until `expiresAt` like any finished job.
|
|
7
|
+
*/
|
|
8
|
+
export declare const dropWaiting: (jobs: Collection<JobDocument>, { spaceIds, status, kind, name }: JobsToDrop, at: number, expiresAt: Date) => Promise<JobsDropped>;
|
package/dist/mongo/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as flowOf, d as LOST_ERROR, f as LOST_MEMORY_WORDS, n as WAITING_STATUSES, o as noJobsByStatus, p as SET_ASIDE_WORDS, t as NEEDING_STATUSES, u as waitingKindOf } from "../chunks/queueRules-
|
|
1
|
+
import { _ as flowOf, d as LOST_ERROR, f as LOST_MEMORY_WORDS, n as WAITING_STATUSES, o as noJobsByStatus, p as SET_ASIDE_WORDS, t as NEEDING_STATUSES, u as waitingKindOf } from "../chunks/queueRules-B3AGQGPs.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
|
|
@@ -25,6 +25,37 @@ var claimable = (at, spaces, memoryMb, takes) => ({
|
|
|
25
25
|
...spaces ? { spaceId: "only" in spaces ? { $in: spaces.only } : { $nin: spaces.except } } : {}
|
|
26
26
|
}, ...memoryMb === void 0 ? [] : [{ needsMemoryMb: { $lte: memoryMb } }]]
|
|
27
27
|
});
|
|
28
|
+
// src/mongo/dropWaiting.ts
|
|
29
|
+
/**
|
|
30
|
+
* `JobQueue.cancelWaiting` over the jobs' collection: everything of these spaces that has not started is `cancelled` at
|
|
31
|
+
* `at`, in one statement, and kept until `expiresAt` like any finished job.
|
|
32
|
+
*/
|
|
33
|
+
var dropWaiting = async (jobs, { spaceIds, status, kind, name }, at, expiresAt) => {
|
|
34
|
+
const filter = {
|
|
35
|
+
spaceId: { $in: spaceIds },
|
|
36
|
+
status: { $in: status ? [status] : ["pending", "paused"] },
|
|
37
|
+
...name ? { "target.name": name } : {},
|
|
38
|
+
...kind ? { "target.kind": kind } : {}
|
|
39
|
+
};
|
|
40
|
+
const watched = kind === "action" ? [] : await jobs.find({
|
|
41
|
+
...filter,
|
|
42
|
+
"target.kind": "function"
|
|
43
|
+
}, { projection: { _id: 1 } }).toArray();
|
|
44
|
+
return {
|
|
45
|
+
cancelled: (await jobs.updateMany(filter, {
|
|
46
|
+
$set: {
|
|
47
|
+
status: "cancelled",
|
|
48
|
+
updatedAt: at,
|
|
49
|
+
expiresAt
|
|
50
|
+
},
|
|
51
|
+
$unset: {
|
|
52
|
+
workerId: "",
|
|
53
|
+
pauseRequested: ""
|
|
54
|
+
}
|
|
55
|
+
})).modifiedCount,
|
|
56
|
+
functionJobs: watched.map((job) => job._id)
|
|
57
|
+
};
|
|
58
|
+
};
|
|
28
59
|
// src/mongo/jobQueue.ts
|
|
29
60
|
/** Mongo's code for a unique index that refused a second document with the same key. */
|
|
30
61
|
var DUPLICATE_KEY$1 = 11e3;
|
|
@@ -647,6 +678,11 @@ var createMongoJobQueue = ({ db, collections: names = {}, retentionDays = 90 })
|
|
|
647
678
|
},
|
|
648
679
|
$unset: { workerId: "" }
|
|
649
680
|
})).modifiedCount;
|
|
681
|
+
},
|
|
682
|
+
cancelWaiting: async (query) => {
|
|
683
|
+
const { jobs } = await collections();
|
|
684
|
+
const at = await clock.now();
|
|
685
|
+
return dropWaiting(jobs, query, at, expiryOf(at));
|
|
650
686
|
}
|
|
651
687
|
};
|
|
652
688
|
};
|
package/dist/mongo/jobQueue.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { JobQueue } from '../types';
|
|
2
|
+
import { Job } from '@plitzi/sdk-shared';
|
|
2
3
|
import { Db } from 'mongodb';
|
|
3
4
|
/** The database, or how to reach it — a getter for a deployment whose client is replaced when it reconnects. */
|
|
4
5
|
export type MongoDbSource = Db | (() => Db);
|
|
@@ -17,6 +18,11 @@ export type MongoJobQueue = JobQueue & {
|
|
|
17
18
|
/** Takes the store's clock again on the next call — after a failover to another primary. */
|
|
18
19
|
resyncClock: () => void;
|
|
19
20
|
};
|
|
21
|
+
export type JobDocument = Omit<Job, 'id'> & {
|
|
22
|
+
_id: string;
|
|
23
|
+
/** Set only once a job is finished, so a job still waiting or running is never expired out from under anybody. */
|
|
24
|
+
expiresAt?: Date | null;
|
|
25
|
+
};
|
|
20
26
|
/**
|
|
21
27
|
* An {@link JobQueue} over two collections of a Mongo database the deployment owns.
|
|
22
28
|
*
|
package/dist/mysql/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as flowOf, d as LOST_ERROR, g as outgrewWorker, h as needsAfterLoss, m as lostError, o as noJobsByStatus, p as SET_ASIDE_WORDS, u as waitingKindOf } from "../chunks/queueRules-
|
|
1
|
+
import { _ as flowOf, d as LOST_ERROR, g as outgrewWorker, h as needsAfterLoss, m as lostError, o as noJobsByStatus, p as SET_ASIDE_WORDS, u as waitingKindOf } from "../chunks/queueRules-B3AGQGPs.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";
|
|
@@ -699,6 +699,36 @@ var createMysqlJobQueue = ({ pool, tablePrefix = "", createTables = true, retent
|
|
|
699
699
|
newest.id
|
|
700
700
|
] : []
|
|
701
701
|
])).affectedRows;
|
|
702
|
+
},
|
|
703
|
+
cancelWaiting: async ({ spaceIds, status, kind, name }) => {
|
|
704
|
+
if (!inSpaces(spaceIds)) return {
|
|
705
|
+
cancelled: 0,
|
|
706
|
+
functionJobs: []
|
|
707
|
+
};
|
|
708
|
+
const conn = await db();
|
|
709
|
+
const where = [
|
|
710
|
+
"space_id IN (?)",
|
|
711
|
+
status ? "status = ?" : "status IN ('pending', 'paused')",
|
|
712
|
+
...name ? ["target_name = ?"] : [],
|
|
713
|
+
...kind ? ["target_kind = ?"] : []
|
|
714
|
+
].join(" AND ");
|
|
715
|
+
const params = [
|
|
716
|
+
spaceIds,
|
|
717
|
+
...status ? [status] : [],
|
|
718
|
+
...name ? [name] : [],
|
|
719
|
+
...kind ? [kind] : []
|
|
720
|
+
];
|
|
721
|
+
const watched = kind === "action" ? [] : await selectRows(conn, `SELECT id FROM ${t.jobs} WHERE ${where} AND target_kind = 'function'`, params);
|
|
722
|
+
const at = await clock.now();
|
|
723
|
+
return {
|
|
724
|
+
cancelled: (await execute(conn, `UPDATE ${t.jobs} SET status = 'cancelled', updated_at = ?, expires_at = ?, worker_id = NULL, pause_requested = 0
|
|
725
|
+
WHERE ${where}`, [
|
|
726
|
+
at,
|
|
727
|
+
expiryOf(at),
|
|
728
|
+
...params
|
|
729
|
+
])).affectedRows,
|
|
730
|
+
functionJobs: watched.map((job) => job.id)
|
|
731
|
+
};
|
|
702
732
|
}
|
|
703
733
|
};
|
|
704
734
|
};
|
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, c as queueRules, i as changedBy, r as applyRule, s as queueOver } from "../chunks/queueRules-
|
|
1
|
+
import { n as stateOf, t as documentOf } from "../chunks/queueDocument-B3y8qr0i.mjs";
|
|
2
|
+
import { a as emptyState, c as queueRules, i as changedBy, r as applyRule, s as queueOver } from "../chunks/queueRules-B3AGQGPs.mjs";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { DatabaseSync } from "node:sqlite";
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export type { ActionLookupsConfig, ConnectorLookupsConfig, EngineConfig, EngineOptions, EngineServerConfig, SSRActionConfig, ActionJobsConfig } from './config';
|
|
2
|
-
export type { ActionSchedule, ActionScheduleInput, JobClaimMemory, JobQuery, JobQueue, JobFlowMinute, JobQueueSummary, JobSettlement, JobsNeedingMemory, JobSpaces, JobStop, JobTake, JobWake, JobWrite, WaitingJobs } from './jobs';
|
|
2
|
+
export type { ActionSchedule, ActionScheduleInput, JobClaimMemory, JobQuery, JobQueue, JobFlowMinute, JobQueueSummary, JobSettlement, JobsDropped, JobsNeedingMemory, JobsToDrop, JobSpaces, JobStop, JobTake, JobWake, JobWrite, WaitingJobs } from './jobs';
|
package/dist/types/jobs.d.ts
CHANGED
|
@@ -138,6 +138,25 @@ export type JobQuery = {
|
|
|
138
138
|
limit: number;
|
|
139
139
|
offset: number;
|
|
140
140
|
};
|
|
141
|
+
/**
|
|
142
|
+
* Which jobs an operator drops at once (`JobQueue.cancelWaiting`): everything of these spaces that has not started —
|
|
143
|
+
* waiting to run or set aside — narrowed like a list of them is.
|
|
144
|
+
*/
|
|
145
|
+
export type JobsToDrop = {
|
|
146
|
+
spaceIds: number[];
|
|
147
|
+
/** Only what waits to run (`pending`), or only what was set aside (`paused`). Absent, both. */
|
|
148
|
+
status?: Extract<JobStatus, 'pending' | 'paused'>;
|
|
149
|
+
/** Only runs of actions, or only jobs of the spaces' functions. */
|
|
150
|
+
kind?: JobTarget['kind'];
|
|
151
|
+
/** Only what runs this action, or this job (`target.name`). */
|
|
152
|
+
name?: string;
|
|
153
|
+
};
|
|
154
|
+
/** What `JobQueue.cancelWaiting` dropped. */
|
|
155
|
+
export type JobsDropped = {
|
|
156
|
+
cancelled: number;
|
|
157
|
+
/** The jobs of the spaces' functions among them: the ones somebody may be watching, for whoever tells them. */
|
|
158
|
+
functionJobs: string[];
|
|
159
|
+
};
|
|
141
160
|
/**
|
|
142
161
|
* A recurring intent, as a row rather than as a timer.
|
|
143
162
|
*
|
|
@@ -319,4 +338,10 @@ export type JobQueue = {
|
|
|
319
338
|
key: string;
|
|
320
339
|
olderThan?: string;
|
|
321
340
|
}) => Promise<number>;
|
|
341
|
+
/**
|
|
342
|
+
* Drops every job of these spaces that has not started (`cancelled`) — a queue filled by a schedule whose runs were
|
|
343
|
+
* all set aside is emptied in one statement, not a job at a time. A running one is left to `cancel`: only the worker
|
|
344
|
+
* holding it can stop it.
|
|
345
|
+
*/
|
|
346
|
+
cancelWaiting: (query: JobsToDrop) => Promise<JobsDropped>;
|
|
322
347
|
};
|
package/dist/worker/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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-Cm3IDERi.mjs";
|
|
3
|
-
import { F as readKeptCall, P as keepCall, R as writeConnectorRecord, S as ACTIONS_FLEET_STORES, h as precheckRun, t as createActionsModule } from "../chunks/module-
|
|
3
|
+
import { F as readKeptCall, P as keepCall, R as writeConnectorRecord, S as ACTIONS_FLEET_STORES, h as precheckRun, t as createActionsModule } from "../chunks/module-CAk06qne.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-Cq7B1kUM.mjs";
|
|
6
|
+
import { t as isFunctionsDefinition } from "../chunks/load-CKHHu7UP.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";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plitzi/sdk-actions",
|
|
3
|
-
"version": "0.39.
|
|
3
|
+
"version": "0.39.8",
|
|
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.8",
|
|
41
|
+
"@plitzi/sdk-shared": "0.39.8",
|
|
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.8",
|
|
63
63
|
"@types/node": "^26.6.6",
|
|
64
64
|
"@types/nodemailer": "^8.0.2",
|
|
65
65
|
"@types/ws": "^8.18.2",
|