@plitzi/sdk-actions 0.39.6 → 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 +20 -0
- package/dist/chunks/{load-DTPs5l0C.mjs → load-CKHHu7UP.mjs} +1 -1
- package/dist/chunks/{module-HDpOahhW.mjs → module-CAk06qne.mjs} +154 -76
- package/dist/chunks/{queueDocument-xYz-KZ5V.mjs → queueDocument-B3y8qr0i.mjs} +1 -1
- package/dist/chunks/{queueRules-BCCVgeUE.mjs → queueRules-B3AGQGPs.mjs} +23 -3
- package/dist/chunks/{taskCatalog-DBVODJX7.mjs → taskCatalog-Cq7B1kUM.mjs} +1 -1
- package/dist/engine/jobs/endings.d.ts +20 -1
- package/dist/engine/jobs/scheduler.d.ts +15 -1
- 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 +39 -3
- package/dist/mongo/jobQueue.d.ts +6 -0
- package/dist/mysql/index.mjs +35 -4
- package/dist/sqlite/index.mjs +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/jobs.d.ts +31 -1
- package/dist/worker/index.mjs +3 -3
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
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
|
+
|
|
13
|
+
## 0.39.7
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 081d94e: 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 [081d94e]
|
|
20
|
+
- @plitzi/sdk-kernel@0.39.7
|
|
21
|
+
- @plitzi/sdk-shared@0.39.7
|
|
22
|
+
|
|
3
23
|
## 0.39.6
|
|
4
24
|
|
|
5
25
|
### 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.
|
|
@@ -452,6 +453,119 @@ var createMemoryJobQueue = ({ retainFinished = 500, clock = Date.now } = {}) =>
|
|
|
452
453
|
});
|
|
453
454
|
return queueOver((method, args) => Promise.resolve(applyRule(rules, method, args)));
|
|
454
455
|
};
|
|
456
|
+
// src/engine/jobs/endings.ts
|
|
457
|
+
/** How a job ends badly: given up, set aside at a limit, or out of attempts — and what its line says. */
|
|
458
|
+
/**
|
|
459
|
+
* Why a run that ended badly did, in the words an operator can act on: the step that failed and what it said.
|
|
460
|
+
*
|
|
461
|
+
* Read from `steps` — the outline, whose errors are already redacted of every credential the run resolved — so
|
|
462
|
+
* nothing lands on the job that the run history would not show. A run that failed without any step failing (a
|
|
463
|
+
* timeout between steps, a budget spent) has no step to name, and says how it ended instead.
|
|
464
|
+
*/
|
|
465
|
+
var failureOf = (result) => {
|
|
466
|
+
const failed = result.steps.find((step) => step.phase === "flow" && step.status === "failed");
|
|
467
|
+
return failed ? `step "${failed.id}" failed: ${failed.error ?? "no reason given"}` : `the flow ended ${result.status}`;
|
|
468
|
+
};
|
|
469
|
+
/**
|
|
470
|
+
* Refusals no number of attempts will change: the action was deleted, its schedule was switched off, or the
|
|
471
|
+
* document refuses this trigger. Retrying is noise, and the job stops where an operator can see why.
|
|
472
|
+
*/
|
|
473
|
+
var GIVE_UP = /* @__PURE__ */ new Set([
|
|
474
|
+
"not_found",
|
|
475
|
+
"disabled",
|
|
476
|
+
"forbidden",
|
|
477
|
+
"recursion"
|
|
478
|
+
]);
|
|
479
|
+
/**
|
|
480
|
+
* The limits the same code meets again on every attempt — what it spends of CPU, memory, calls, output, steps or
|
|
481
|
+
* requests, and its plan's allowance for the period spent (`quota`): a job stopped at one is set aside at once, for its
|
|
482
|
+
* owner to fix or its plan to allow more, rather than run twice more for nothing. Time is not among them: an API slow
|
|
483
|
+
* for a minute answers the next attempt.
|
|
484
|
+
*/
|
|
485
|
+
var SET_ASIDE_LIMITS = /* @__PURE__ */ new Set([
|
|
486
|
+
"cpu",
|
|
487
|
+
"memory",
|
|
488
|
+
"calls",
|
|
489
|
+
"output",
|
|
490
|
+
"steps",
|
|
491
|
+
"requests",
|
|
492
|
+
"response",
|
|
493
|
+
"quota"
|
|
494
|
+
]);
|
|
495
|
+
var HOUR_MS = 36e5;
|
|
496
|
+
/**
|
|
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.
|
|
500
|
+
*/
|
|
501
|
+
var AGAIN_IN_A_DAY = {
|
|
502
|
+
retryMs: 24 * HOUR_MS,
|
|
503
|
+
retryIn: "a day"
|
|
504
|
+
};
|
|
505
|
+
/**
|
|
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`).
|
|
521
|
+
*/
|
|
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;
|
|
533
|
+
};
|
|
534
|
+
/** Why a job stopped at one of {@link SET_ASIDE_LIMITS} waits for somebody. */
|
|
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}`;
|
|
536
|
+
/**
|
|
537
|
+
* Why a job that failed every attempt waits: it is set aside (`paused`) for somebody to read its runs and decide —
|
|
538
|
+
* resume it once fixed, with every attempt again, or cancel it.
|
|
539
|
+
*/
|
|
540
|
+
var failedOutError = (attempts, last) => `Set aside after ${String(attempts)} failed attempt${attempts === 1 ? "" : "s"}: look at its runs, then resume it once fixed — every attempt again — or cancel it. The last said: ${last}`;
|
|
541
|
+
/**
|
|
542
|
+
* A run stopped at a limit is not retried as a failure, whether it was reached as the run went or refused before it
|
|
543
|
+
* started: its account's CPU for the minute is not now — back next minute, its attempt refunded — and a limit its plan
|
|
544
|
+
* sets is reached again on every attempt, so it is set aside at once. Answers whether it was one.
|
|
545
|
+
*/
|
|
546
|
+
var limitEndings = ({ workerId, settle, release, nextMinuteMs }) => async (job, runId, limit, said) => {
|
|
547
|
+
if (limit === "cpuBudget") {
|
|
548
|
+
await release(job, await nextMinuteMs(), said);
|
|
549
|
+
return true;
|
|
550
|
+
}
|
|
551
|
+
if (!limit || !SET_ASIDE_LIMITS.has(limit)) return false;
|
|
552
|
+
serverLog.warn("Actions", `job ${job.id} of space ${String(job.spaceId)} set aside at its plan's limit: ${said}`);
|
|
553
|
+
await settle({
|
|
554
|
+
jobId: job.id,
|
|
555
|
+
workerId,
|
|
556
|
+
status: "paused",
|
|
557
|
+
runId,
|
|
558
|
+
error: limitSetAsideError(said),
|
|
559
|
+
attempt: {
|
|
560
|
+
status: "failed",
|
|
561
|
+
workerId,
|
|
562
|
+
runId,
|
|
563
|
+
error: said,
|
|
564
|
+
limit
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
return true;
|
|
568
|
+
};
|
|
455
569
|
// src/engine/jobs/failureStreak.ts
|
|
456
570
|
/** How long a pass may keep failing before it is reported as the error it has become. */
|
|
457
571
|
var FAILURE_STREAK_ESCALATION_MS = 6e4;
|
|
@@ -563,6 +677,11 @@ var PARK_MS = 2108160 * MINUTE_MS;
|
|
|
563
677
|
* **An outage does not replay as a storm.** The overdue fire becomes one job, and the schedule then jumps to the
|
|
564
678
|
* first occurrence after now, recording how many went by. A digest missed for a day sends once and says it missed
|
|
565
679
|
* 23 — rather than sending 23 times, which is how a scheduler that "catches up" turns an outage into an incident.
|
|
680
|
+
*
|
|
681
|
+
* **A limit is not fired into again.** A fire set aside because its code went past what its plan gives it — its
|
|
682
|
+
* memory, its CPU, its calls — would be at the next fire too: the schedule waits on that one job, moving on with the
|
|
683
|
+
* clock, until somebody resumes or cancels it; and tries one again by itself a day later. An every-minute sweep that
|
|
684
|
+
* needed more memory than its size has was one more job set aside every minute, each a failed run.
|
|
566
685
|
*/
|
|
567
686
|
var createScheduler = ({ queue, lookups, environment = "main", pollMs = 15e3, batch = 200, maxAttempts = 3, reconcileMs = 15 * MINUTE_MS, spaces, admit, onError }) => {
|
|
568
687
|
/** What was last said of each space refused, so a refusal is said once, not on every sweep. */
|
|
@@ -577,6 +696,8 @@ var createScheduler = ({ queue, lookups, environment = "main", pollMs = 15e3, ba
|
|
|
577
696
|
let timer;
|
|
578
697
|
let reconcileTimer;
|
|
579
698
|
let running = false;
|
|
699
|
+
/** The job each schedule was last said to wait on, so it is said once — not at every fire held back. */
|
|
700
|
+
const waiting = /* @__PURE__ */ new Map();
|
|
580
701
|
const produce = async (schedule, at, result) => {
|
|
581
702
|
const { spaceId, actionId, cron, timezone, nextRunAt: fireAt } = schedule;
|
|
582
703
|
if (await refusalOf(spaceId)) {
|
|
@@ -588,6 +709,33 @@ var createScheduler = ({ queue, lookups, environment = "main", pollMs = 15e3, ba
|
|
|
588
709
|
}
|
|
589
710
|
const id = scheduleJobId(spaceId, actionId, fireAt);
|
|
590
711
|
const before = schedule.lastFireAt === void 0 ? void 0 : await queue.getJob([spaceId], scheduleJobId(spaceId, actionId, schedule.lastFireAt));
|
|
712
|
+
const hold = before ? scheduleHold(before) : void 0;
|
|
713
|
+
const key = `${String(spaceId)}:${actionId}`;
|
|
714
|
+
if (before && hold && at.getTime() - before.dueAt < hold.retryMs) {
|
|
715
|
+
const { limit } = hold;
|
|
716
|
+
if (waiting.get(key) !== before.id) {
|
|
717
|
+
waiting.set(key, before.id);
|
|
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.`);
|
|
719
|
+
}
|
|
720
|
+
result.held.push({
|
|
721
|
+
spaceId,
|
|
722
|
+
actionId,
|
|
723
|
+
jobId: before.id,
|
|
724
|
+
limit
|
|
725
|
+
});
|
|
726
|
+
const late = Math.max(fireAt, at.getTime());
|
|
727
|
+
const following = cronNextFire(cron, /* @__PURE__ */ new Date(Math.floor(late / MINUTE_MS) * MINUTE_MS + MINUTE_MS), timezone);
|
|
728
|
+
await queue.advanceSchedule({
|
|
729
|
+
spaceId,
|
|
730
|
+
actionId,
|
|
731
|
+
from: fireAt,
|
|
732
|
+
to: following ? following.getTime() : late + PARK_MS,
|
|
733
|
+
missed: 0,
|
|
734
|
+
held: true
|
|
735
|
+
});
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
waiting.delete(key);
|
|
591
739
|
(await queue.enqueue({
|
|
592
740
|
id,
|
|
593
741
|
spaceId,
|
|
@@ -602,6 +750,7 @@ var createScheduler = ({ queue, lookups, environment = "main", pollMs = 15e3, ba
|
|
|
602
750
|
maxAttempts: schedule.maxAttempts,
|
|
603
751
|
...before?.needsMemoryMb === void 0 ? {} : { needsMemoryMb: before.needsMemoryMb }
|
|
604
752
|
}) ? result.enqueued : result.duplicates).push(id);
|
|
753
|
+
if (before?.status === "paused" && await queue.cancel([spaceId], before.id)) result.superseded.push(before.id);
|
|
605
754
|
const lateness = Math.max(fireAt, at.getTime());
|
|
606
755
|
const missed = cronFiresBetween(cron, new Date(fireAt), new Date(lateness), timezone);
|
|
607
756
|
/**
|
|
@@ -628,7 +777,9 @@ var createScheduler = ({ queue, lookups, environment = "main", pollMs = 15e3, ba
|
|
|
628
777
|
const result = {
|
|
629
778
|
enqueued: [],
|
|
630
779
|
duplicates: [],
|
|
631
|
-
missed: []
|
|
780
|
+
missed: [],
|
|
781
|
+
held: [],
|
|
782
|
+
superseded: []
|
|
632
783
|
};
|
|
633
784
|
const at = await queue.now();
|
|
634
785
|
for (const schedule of await queue.dueSchedules(batch)) await produce(schedule, at, result);
|
|
@@ -730,79 +881,6 @@ var onlyFull = (spaces, full) => {
|
|
|
730
881
|
const only = !spaces ? full : "only" in spaces ? spaces.only.filter((spaceId) => full.includes(spaceId)) : full.filter((spaceId) => !spaces.except.includes(spaceId));
|
|
731
882
|
return only.length > 0 ? { only } : void 0;
|
|
732
883
|
};
|
|
733
|
-
// src/engine/jobs/endings.ts
|
|
734
|
-
/** How a job ends badly: given up, set aside at a limit, or out of attempts — and what its line says. */
|
|
735
|
-
/**
|
|
736
|
-
* Why a run that ended badly did, in the words an operator can act on: the step that failed and what it said.
|
|
737
|
-
*
|
|
738
|
-
* Read from `steps` — the outline, whose errors are already redacted of every credential the run resolved — so
|
|
739
|
-
* nothing lands on the job that the run history would not show. A run that failed without any step failing (a
|
|
740
|
-
* timeout between steps, a budget spent) has no step to name, and says how it ended instead.
|
|
741
|
-
*/
|
|
742
|
-
var failureOf = (result) => {
|
|
743
|
-
const failed = result.steps.find((step) => step.phase === "flow" && step.status === "failed");
|
|
744
|
-
return failed ? `step "${failed.id}" failed: ${failed.error ?? "no reason given"}` : `the flow ended ${result.status}`;
|
|
745
|
-
};
|
|
746
|
-
/**
|
|
747
|
-
* Refusals no number of attempts will change: the action was deleted, its schedule was switched off, or the
|
|
748
|
-
* document refuses this trigger. Retrying is noise, and the job stops where an operator can see why.
|
|
749
|
-
*/
|
|
750
|
-
var GIVE_UP = /* @__PURE__ */ new Set([
|
|
751
|
-
"not_found",
|
|
752
|
-
"disabled",
|
|
753
|
-
"forbidden",
|
|
754
|
-
"recursion"
|
|
755
|
-
]);
|
|
756
|
-
/**
|
|
757
|
-
* The limits the same code meets again on every attempt — what it spends of CPU, memory, calls, output, steps or
|
|
758
|
-
* requests, and its plan's allowance for the period spent (`quota`): a job stopped at one is set aside at once, for its
|
|
759
|
-
* owner to fix or its plan to allow more, rather than run twice more for nothing. Time is not among them: an API slow
|
|
760
|
-
* for a minute answers the next attempt.
|
|
761
|
-
*/
|
|
762
|
-
var SET_ASIDE_LIMITS = /* @__PURE__ */ new Set([
|
|
763
|
-
"cpu",
|
|
764
|
-
"memory",
|
|
765
|
-
"calls",
|
|
766
|
-
"output",
|
|
767
|
-
"steps",
|
|
768
|
-
"requests",
|
|
769
|
-
"response",
|
|
770
|
-
"quota"
|
|
771
|
-
]);
|
|
772
|
-
/** Why a job stopped at one of {@link SET_ASIDE_LIMITS} waits for somebody. */
|
|
773
|
-
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}`;
|
|
774
|
-
/**
|
|
775
|
-
* Why a job that failed every attempt waits: it is set aside (`paused`) for somebody to read its runs and decide —
|
|
776
|
-
* resume it once fixed, with every attempt again, or cancel it.
|
|
777
|
-
*/
|
|
778
|
-
var failedOutError = (attempts, last) => `Set aside after ${String(attempts)} failed attempt${attempts === 1 ? "" : "s"}: look at its runs, then resume it once fixed — every attempt again — or cancel it. The last said: ${last}`;
|
|
779
|
-
/**
|
|
780
|
-
* A run stopped at a limit is not retried as a failure, whether it was reached as the run went or refused before it
|
|
781
|
-
* started: its account's CPU for the minute is not now — back next minute, its attempt refunded — and a limit its plan
|
|
782
|
-
* sets is reached again on every attempt, so it is set aside at once. Answers whether it was one.
|
|
783
|
-
*/
|
|
784
|
-
var limitEndings = ({ workerId, settle, release, nextMinuteMs }) => async (job, runId, limit, said) => {
|
|
785
|
-
if (limit === "cpuBudget") {
|
|
786
|
-
await release(job, await nextMinuteMs(), said);
|
|
787
|
-
return true;
|
|
788
|
-
}
|
|
789
|
-
if (!limit || !SET_ASIDE_LIMITS.has(limit)) return false;
|
|
790
|
-
serverLog.warn("Actions", `job ${job.id} of space ${String(job.spaceId)} set aside at its plan's limit: ${said}`);
|
|
791
|
-
await settle({
|
|
792
|
-
jobId: job.id,
|
|
793
|
-
workerId,
|
|
794
|
-
status: "paused",
|
|
795
|
-
runId,
|
|
796
|
-
error: limitSetAsideError(said),
|
|
797
|
-
attempt: {
|
|
798
|
-
status: "failed",
|
|
799
|
-
workerId,
|
|
800
|
-
runId,
|
|
801
|
-
error: said
|
|
802
|
-
}
|
|
803
|
-
});
|
|
804
|
-
return true;
|
|
805
|
-
};
|
|
806
884
|
// src/engine/jobs/memoryWatch.ts
|
|
807
885
|
/** The share of a limit past which a worker is near it: a kernel or V8 ends it at the limit, not before. */
|
|
808
886
|
var NEAR_MEMORY_SHARE = .85;
|
|
@@ -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;
|
|
@@ -256,11 +259,11 @@ var queueRules = ({ jobs, schedules }, { retainFinished, clock, onUnansweredChan
|
|
|
256
259
|
const at = now();
|
|
257
260
|
return [...schedules.values()].filter((schedule) => schedule.enabled && schedule.nextRunAt <= at).sort((a, b) => a.nextRunAt - b.nextRunAt).slice(0, limit).map((schedule) => ({ ...schedule }));
|
|
258
261
|
},
|
|
259
|
-
advanceSchedule: ({ spaceId, actionId, from, to, missed }) => {
|
|
262
|
+
advanceSchedule: ({ spaceId, actionId, from, to, missed, held }) => {
|
|
260
263
|
const schedule = schedules.get(key(spaceId, actionId));
|
|
261
264
|
if (!schedule || schedule.nextRunAt !== from) return false;
|
|
262
265
|
schedule.nextRunAt = to;
|
|
263
|
-
schedule.lastFireAt = from;
|
|
266
|
+
if (!held) schedule.lastFireAt = from;
|
|
264
267
|
schedule.missed += missed;
|
|
265
268
|
schedule.updatedAt = now();
|
|
266
269
|
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 };
|
|
@@ -21,7 +21,26 @@ export declare const GIVE_UP: Set<string>;
|
|
|
21
21
|
* owner to fix or its plan to allow more, rather than run twice more for nothing. Time is not among them: an API slow
|
|
22
22
|
* for a minute answers the next attempt.
|
|
23
23
|
*/
|
|
24
|
-
export declare const SET_ASIDE_LIMITS: Set<
|
|
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
|
+
};
|
|
34
|
+
/**
|
|
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`).
|
|
42
|
+
*/
|
|
43
|
+
export declare const scheduleHold: (job: Pick<Job, "status" | "history" | "error">) => ScheduleHold | undefined;
|
|
25
44
|
/** Why a job stopped at one of {@link SET_ASIDE_LIMITS} waits for somebody. */
|
|
26
45
|
export declare const limitSetAsideError: (said: string) => string;
|
|
27
46
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JobQueue } from '../../types';
|
|
2
2
|
import { ActionLookups } from '../types';
|
|
3
|
-
import { Environment } from '@plitzi/sdk-shared';
|
|
3
|
+
import { ActionRunLimit, Environment } from '@plitzi/sdk-shared';
|
|
4
4
|
export type SchedulerOptions = {
|
|
5
5
|
queue: JobQueue;
|
|
6
6
|
lookups: ActionLookups;
|
|
@@ -37,6 +37,15 @@ export type SweepResult = {
|
|
|
37
37
|
actionId: string;
|
|
38
38
|
count: number;
|
|
39
39
|
}[];
|
|
40
|
+
/** Fires not made into jobs: their schedule waits on the job named, set aside at a limit it would meet again. */
|
|
41
|
+
held: {
|
|
42
|
+
spaceId: number;
|
|
43
|
+
actionId: string;
|
|
44
|
+
jobId: string;
|
|
45
|
+
limit: ActionRunLimit;
|
|
46
|
+
}[];
|
|
47
|
+
/** Jobs still set aside when their schedule fired again, cancelled: the new fire stands for them. */
|
|
48
|
+
superseded: string[];
|
|
40
49
|
};
|
|
41
50
|
export type Scheduler = {
|
|
42
51
|
/** One pass. Exposed because a deployment driving this from its own cron — a k8s CronJob, a queue tick — needs
|
|
@@ -66,5 +75,10 @@ export type Scheduler = {
|
|
|
66
75
|
* **An outage does not replay as a storm.** The overdue fire becomes one job, and the schedule then jumps to the
|
|
67
76
|
* first occurrence after now, recording how many went by. A digest missed for a day sends once and says it missed
|
|
68
77
|
* 23 — rather than sending 23 times, which is how a scheduler that "catches up" turns an outage into an incident.
|
|
78
|
+
*
|
|
79
|
+
* **A limit is not fired into again.** A fire set aside because its code went past what its plan gives it — its
|
|
80
|
+
* memory, its CPU, its calls — would be at the next fire too: the schedule waits on that one job, moving on with the
|
|
81
|
+
* clock, until somebody resumes or cancels it; and tries one again by itself a day later. An every-minute sweep that
|
|
82
|
+
* needed more memory than its size has was one more job set aside every minute, each a failed run.
|
|
69
83
|
*/
|
|
70
84
|
export declare const createScheduler: ({ queue, lookups, environment, pollMs, batch, maxAttempts, reconcileMs, spaces, admit, onError }: SchedulerOptions) => Scheduler;
|
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;
|
|
@@ -346,7 +377,7 @@ var createMongoJobQueue = ({ db, collections: names = {}, retentionDays = 90 })
|
|
|
346
377
|
nextRunAt: { $lte: at }
|
|
347
378
|
}).sort({ nextRunAt: 1 }).limit(limit).toArray()).map(toSchedule);
|
|
348
379
|
},
|
|
349
|
-
advanceSchedule: async ({ spaceId, actionId, from, to, missed }) => {
|
|
380
|
+
advanceSchedule: async ({ spaceId, actionId, from, to, missed, held }) => {
|
|
350
381
|
const { schedules } = await collections();
|
|
351
382
|
const at = await clock.now();
|
|
352
383
|
return (await schedules.updateOne({
|
|
@@ -355,7 +386,7 @@ var createMongoJobQueue = ({ db, collections: names = {}, retentionDays = 90 })
|
|
|
355
386
|
}, {
|
|
356
387
|
$set: {
|
|
357
388
|
nextRunAt: to,
|
|
358
|
-
lastFireAt: from,
|
|
389
|
+
...held ? {} : { lastFireAt: from },
|
|
359
390
|
updatedAt: at
|
|
360
391
|
},
|
|
361
392
|
$inc: { missed }
|
|
@@ -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";
|
|
@@ -509,13 +509,14 @@ var createMysqlJobQueue = ({ pool, tablePrefix = "", createTables = true, retent
|
|
|
509
509
|
const at = await clock.now();
|
|
510
510
|
return (await selectRows(conn, `SELECT * FROM ${t.schedules} WHERE enabled = 1 AND next_run_at <= ? ORDER BY next_run_at LIMIT ?`, [at, limit])).map(toSchedule);
|
|
511
511
|
},
|
|
512
|
-
advanceSchedule: async ({ spaceId, actionId, from, to, missed }) => {
|
|
512
|
+
advanceSchedule: async ({ spaceId, actionId, from, to, missed, held }) => {
|
|
513
513
|
const conn = await db();
|
|
514
514
|
const at = await clock.now();
|
|
515
|
-
return (await execute(conn, `UPDATE ${t.schedules} SET next_run_at = ?, last_fire_at =
|
|
515
|
+
return (await execute(conn, `UPDATE ${t.schedules} SET next_run_at = ?, last_fire_at = ${held ? "last_fire_at" : "?"}, updated_at = ?,
|
|
516
|
+
missed = missed + ?
|
|
516
517
|
WHERE space_id = ? AND action_id = ? AND next_run_at = ?`, [
|
|
517
518
|
to,
|
|
518
|
-
from,
|
|
519
|
+
...held ? [] : [from],
|
|
519
520
|
at,
|
|
520
521
|
missed,
|
|
521
522
|
spaceId,
|
|
@@ -698,6 +699,36 @@ var createMysqlJobQueue = ({ pool, tablePrefix = "", createTables = true, retent
|
|
|
698
699
|
newest.id
|
|
699
700
|
] : []
|
|
700
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
|
+
};
|
|
701
732
|
}
|
|
702
733
|
};
|
|
703
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
|
*
|
|
@@ -155,7 +174,7 @@ export type ActionSchedule = {
|
|
|
155
174
|
enabled: boolean;
|
|
156
175
|
/** Epoch ms of the next fire this schedule owes. The queue's clock decides when that has arrived. */
|
|
157
176
|
nextRunAt: number;
|
|
158
|
-
/** The last fire actually enqueued. */
|
|
177
|
+
/** The last fire actually enqueued: one the scheduler held back (`advanceSchedule`'s `held`) does not move it. */
|
|
159
178
|
lastFireAt?: number;
|
|
160
179
|
/** Fires that went by while nothing was running to take them. Cumulative, and shown to an operator. */
|
|
161
180
|
missed: number;
|
|
@@ -239,6 +258,11 @@ export type JobQueue = {
|
|
|
239
258
|
from: number;
|
|
240
259
|
to: number;
|
|
241
260
|
missed: number;
|
|
261
|
+
/**
|
|
262
|
+
* The fire at `from` was not enqueued — the schedule waits on the one before it, set aside at a limit it would
|
|
263
|
+
* meet again: it moves on with the clock, and `lastFireAt` stays the fire that was.
|
|
264
|
+
*/
|
|
265
|
+
held?: boolean;
|
|
242
266
|
}) => Promise<boolean>;
|
|
243
267
|
/** Replaces what this space has scheduled. An action no longer listed stops having a schedule at all. */
|
|
244
268
|
putSchedules: (params: {
|
|
@@ -314,4 +338,10 @@ export type JobQueue = {
|
|
|
314
338
|
key: string;
|
|
315
339
|
olderThan?: string;
|
|
316
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>;
|
|
317
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",
|