@plitzi/sdk-actions 0.39.6 → 0.39.7

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 CHANGED
@@ -1,5 +1,15 @@
1
1
  # @plitzi/sdk-actions
2
2
 
3
+ ## 0.39.7
4
+
5
+ ### Patch Changes
6
+
7
+ - 081d94e: 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 [081d94e]
10
+ - @plitzi/sdk-kernel@0.39.7
11
+ - @plitzi/sdk-shared@0.39.7
12
+
3
13
  ## 0.39.6
4
14
 
5
15
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import { i as buildFunctions } from "./module-HDpOahhW.mjs";
1
+ import { i as buildFunctions } from "./module-CqtrQfYf.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-BCCVgeUE.mjs";
1
+ import { a as emptyState, c as queueRules, r as applyRule, s as queueOver } from "./queueRules-Dk8mNzEJ.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";
@@ -452,6 +452,94 @@ var createMemoryJobQueue = ({ retainFinished = 500, clock = Date.now } = {}) =>
452
452
  });
453
453
  return queueOver((method, args) => Promise.resolve(applyRule(rules, method, args)));
454
454
  };
455
+ // src/engine/jobs/endings.ts
456
+ /** How a job ends badly: given up, set aside at a limit, or out of attempts — and what its line says. */
457
+ /**
458
+ * Why a run that ended badly did, in the words an operator can act on: the step that failed and what it said.
459
+ *
460
+ * Read from `steps` — the outline, whose errors are already redacted of every credential the run resolved — so
461
+ * nothing lands on the job that the run history would not show. A run that failed without any step failing (a
462
+ * timeout between steps, a budget spent) has no step to name, and says how it ended instead.
463
+ */
464
+ var failureOf = (result) => {
465
+ const failed = result.steps.find((step) => step.phase === "flow" && step.status === "failed");
466
+ return failed ? `step "${failed.id}" failed: ${failed.error ?? "no reason given"}` : `the flow ended ${result.status}`;
467
+ };
468
+ /**
469
+ * Refusals no number of attempts will change: the action was deleted, its schedule was switched off, or the
470
+ * document refuses this trigger. Retrying is noise, and the job stops where an operator can see why.
471
+ */
472
+ var GIVE_UP = /* @__PURE__ */ new Set([
473
+ "not_found",
474
+ "disabled",
475
+ "forbidden",
476
+ "recursion"
477
+ ]);
478
+ /**
479
+ * The limits the same code meets again on every attempt — what it spends of CPU, memory, calls, output, steps or
480
+ * requests, and its plan's allowance for the period spent (`quota`): a job stopped at one is set aside at once, for its
481
+ * owner to fix or its plan to allow more, rather than run twice more for nothing. Time is not among them: an API slow
482
+ * for a minute answers the next attempt.
483
+ */
484
+ var SET_ASIDE_LIMITS = /* @__PURE__ */ new Set([
485
+ "cpu",
486
+ "memory",
487
+ "calls",
488
+ "output",
489
+ "steps",
490
+ "requests",
491
+ "response",
492
+ "quota"
493
+ ]);
494
+ /**
495
+ * The limits a SCHEDULE waits on: those the code itself meets again at the next fire, as it would at the next attempt.
496
+ * Its allowance for the period (`quota`) is not one — that comes back by itself when the period turns, and a schedule
497
+ * waiting on it would wait on a job nobody has a reason to resume.
498
+ */
499
+ var HOLDS_SCHEDULE = new Set([...SET_ASIDE_LIMITS].filter((limit) => limit !== "quota"));
500
+ /**
501
+ * The limit a job set aside was stopped at, when its schedule waits on it: `paused`, its last attempt ended at a
502
+ * limit of {@link HOLDS_SCHEDULE}. A job set aside after failing every attempt is not one — the next fire may pass.
503
+ */
504
+ var heldAtLimit = (job) => {
505
+ const limit = job.status === "paused" ? job.history.at(-1)?.limit : void 0;
506
+ return limit !== void 0 && HOLDS_SCHEDULE.has(limit) ? limit : void 0;
507
+ };
508
+ /** Why a job stopped at one of {@link SET_ASIDE_LIMITS} waits for somebody. */
509
+ 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}`;
510
+ /**
511
+ * Why a job that failed every attempt waits: it is set aside (`paused`) for somebody to read its runs and decide —
512
+ * resume it once fixed, with every attempt again, or cancel it.
513
+ */
514
+ 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}`;
515
+ /**
516
+ * A run stopped at a limit is not retried as a failure, whether it was reached as the run went or refused before it
517
+ * started: its account's CPU for the minute is not now — back next minute, its attempt refunded — and a limit its plan
518
+ * sets is reached again on every attempt, so it is set aside at once. Answers whether it was one.
519
+ */
520
+ var limitEndings = ({ workerId, settle, release, nextMinuteMs }) => async (job, runId, limit, said) => {
521
+ if (limit === "cpuBudget") {
522
+ await release(job, await nextMinuteMs(), said);
523
+ return true;
524
+ }
525
+ if (!limit || !SET_ASIDE_LIMITS.has(limit)) return false;
526
+ serverLog.warn("Actions", `job ${job.id} of space ${String(job.spaceId)} set aside at its plan's limit: ${said}`);
527
+ await settle({
528
+ jobId: job.id,
529
+ workerId,
530
+ status: "paused",
531
+ runId,
532
+ error: limitSetAsideError(said),
533
+ attempt: {
534
+ status: "failed",
535
+ workerId,
536
+ runId,
537
+ error: said,
538
+ limit
539
+ }
540
+ });
541
+ return true;
542
+ };
455
543
  // src/engine/jobs/failureStreak.ts
456
544
  /** How long a pass may keep failing before it is reported as the error it has become. */
457
545
  var FAILURE_STREAK_ESCALATION_MS = 6e4;
@@ -545,6 +633,12 @@ var MINUTE_MS = 6e4;
545
633
  * {@link cronNextFire} searches: nothing inside it matched, so nothing inside it will. */
546
634
  var PARK_MS = 2108160 * MINUTE_MS;
547
635
  /**
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
+ /**
548
642
  * Turns due schedules into jobs. Nothing else.
549
643
  *
550
644
  * **There is no leader.** Every replica sweeps, and that is safe because a fire's job id is derived from the fire's
@@ -563,6 +657,11 @@ var PARK_MS = 2108160 * MINUTE_MS;
563
657
  * **An outage does not replay as a storm.** The overdue fire becomes one job, and the schedule then jumps to the
564
658
  * first occurrence after now, recording how many went by. A digest missed for a day sends once and says it missed
565
659
  * 23 — rather than sending 23 times, which is how a scheduler that "catches up" turns an outage into an incident.
660
+ *
661
+ * **A limit is not fired into again.** A fire set aside because its code went past what its plan gives it — its
662
+ * memory, its CPU, its calls — would be at the next fire too: the schedule waits on that one job, moving on with the
663
+ * clock, until somebody resumes or cancels it; and tries one again by itself a day later. An every-minute sweep that
664
+ * needed more memory than its size has was one more job set aside every minute, each a failed run.
566
665
  */
567
666
  var createScheduler = ({ queue, lookups, environment = "main", pollMs = 15e3, batch = 200, maxAttempts = 3, reconcileMs = 15 * MINUTE_MS, spaces, admit, onError }) => {
568
667
  /** What was last said of each space refused, so a refusal is said once, not on every sweep. */
@@ -577,6 +676,8 @@ var createScheduler = ({ queue, lookups, environment = "main", pollMs = 15e3, ba
577
676
  let timer;
578
677
  let reconcileTimer;
579
678
  let running = false;
679
+ /** The job each schedule was last said to wait on, so it is said once — not at every fire held back. */
680
+ const waiting = /* @__PURE__ */ new Map();
580
681
  const produce = async (schedule, at, result) => {
581
682
  const { spaceId, actionId, cron, timezone, nextRunAt: fireAt } = schedule;
582
683
  if (await refusalOf(spaceId)) {
@@ -588,6 +689,32 @@ var createScheduler = ({ queue, lookups, environment = "main", pollMs = 15e3, ba
588
689
  }
589
690
  const id = scheduleJobId(spaceId, actionId, fireAt);
590
691
  const before = schedule.lastFireAt === void 0 ? void 0 : await queue.getJob([spaceId], scheduleJobId(spaceId, actionId, schedule.lastFireAt));
692
+ const limit = before ? heldAtLimit(before) : void 0;
693
+ const key = `${String(spaceId)}:${actionId}`;
694
+ if (before && limit && at.getTime() - before.dueAt < HELD_RETRY_MS) {
695
+ if (waiting.get(key) !== before.id) {
696
+ 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 a day after it.`);
698
+ }
699
+ result.held.push({
700
+ spaceId,
701
+ actionId,
702
+ jobId: before.id,
703
+ limit
704
+ });
705
+ const late = Math.max(fireAt, at.getTime());
706
+ const following = cronNextFire(cron, /* @__PURE__ */ new Date(Math.floor(late / MINUTE_MS) * MINUTE_MS + MINUTE_MS), timezone);
707
+ await queue.advanceSchedule({
708
+ spaceId,
709
+ actionId,
710
+ from: fireAt,
711
+ to: following ? following.getTime() : late + PARK_MS,
712
+ missed: 0,
713
+ held: true
714
+ });
715
+ return;
716
+ }
717
+ waiting.delete(key);
591
718
  (await queue.enqueue({
592
719
  id,
593
720
  spaceId,
@@ -628,7 +755,8 @@ var createScheduler = ({ queue, lookups, environment = "main", pollMs = 15e3, ba
628
755
  const result = {
629
756
  enqueued: [],
630
757
  duplicates: [],
631
- missed: []
758
+ missed: [],
759
+ held: []
632
760
  };
633
761
  const at = await queue.now();
634
762
  for (const schedule of await queue.dueSchedules(batch)) await produce(schedule, at, result);
@@ -730,79 +858,6 @@ var onlyFull = (spaces, full) => {
730
858
  const only = !spaces ? full : "only" in spaces ? spaces.only.filter((spaceId) => full.includes(spaceId)) : full.filter((spaceId) => !spaces.except.includes(spaceId));
731
859
  return only.length > 0 ? { only } : void 0;
732
860
  };
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
861
  // src/engine/jobs/memoryWatch.ts
807
862
  /** The share of a limit past which a worker is near it: a kernel or V8 ends it at the limit, not before. */
808
863
  var NEAR_MEMORY_SHARE = .85;
@@ -1,4 +1,4 @@
1
- import { l as scheduleKey } from "./queueRules-BCCVgeUE.mjs";
1
+ import { l as scheduleKey } from "./queueRules-Dk8mNzEJ.mjs";
2
2
  import { isRecord } from "@plitzi/sdk-shared/helpers";
3
3
  // src/engine/jobs/queueDocument.ts
4
4
  var documentOf = ({ jobs, schedules }) => ({
@@ -256,11 +256,11 @@ var queueRules = ({ jobs, schedules }, { retainFinished, clock, onUnansweredChan
256
256
  const at = now();
257
257
  return [...schedules.values()].filter((schedule) => schedule.enabled && schedule.nextRunAt <= at).sort((a, b) => a.nextRunAt - b.nextRunAt).slice(0, limit).map((schedule) => ({ ...schedule }));
258
258
  },
259
- advanceSchedule: ({ spaceId, actionId, from, to, missed }) => {
259
+ advanceSchedule: ({ spaceId, actionId, from, to, missed, held }) => {
260
260
  const schedule = schedules.get(key(spaceId, actionId));
261
261
  if (!schedule || schedule.nextRunAt !== from) return false;
262
262
  schedule.nextRunAt = to;
263
- schedule.lastFireAt = from;
263
+ if (!held) schedule.lastFireAt = from;
264
264
  schedule.missed += missed;
265
265
  schedule.updatedAt = now();
266
266
  return true;
@@ -1,4 +1,4 @@
1
- import { I as fetchConnectorRecords } from "./module-HDpOahhW.mjs";
1
+ import { I as fetchConnectorRecords } from "./module-CqtrQfYf.mjs";
2
2
  import { getSourceName } from "@plitzi/sdk-shared/dataSource/helpers";
3
3
  // src/connectors/projection.ts
4
4
  /**
@@ -21,7 +21,18 @@ 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<string>;
24
+ export declare const SET_ASIDE_LIMITS: Set<ActionRunLimit>;
25
+ /**
26
+ * The limits a SCHEDULE waits on: those the code itself meets again at the next fire, as it would at the next attempt.
27
+ * Its allowance for the period (`quota`) is not one — that comes back by itself when the period turns, and a schedule
28
+ * waiting on it would wait on a job nobody has a reason to resume.
29
+ */
30
+ export declare const HOLDS_SCHEDULE: Set<ActionRunLimit>;
31
+ /**
32
+ * The limit a job set aside was stopped at, when its schedule waits on it: `paused`, its last attempt ended at a
33
+ * limit of {@link HOLDS_SCHEDULE}. A job set aside after failing every attempt is not one — the next fire may pass.
34
+ */
35
+ export declare const heldAtLimit: (job: Pick<Job, "status" | "history">) => ActionRunLimit | undefined;
25
36
  /** Why a job stopped at one of {@link SET_ASIDE_LIMITS} waits for somebody. */
26
37
  export declare const limitSetAsideError: (said: string) => string;
27
38
  /**
@@ -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,13 @@ 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
+ }[];
40
47
  };
41
48
  export type Scheduler = {
42
49
  /** One pass. Exposed because a deployment driving this from its own cron — a k8s CronJob, a queue tick — needs
@@ -66,5 +73,10 @@ export type Scheduler = {
66
73
  * **An outage does not replay as a storm.** The overdue fire becomes one job, and the schedule then jumps to the
67
74
  * first occurrence after now, recording how many went by. A digest missed for a day sends once and says it missed
68
75
  * 23 — rather than sending 23 times, which is how a scheduler that "catches up" turns an outage into an incident.
76
+ *
77
+ * **A limit is not fired into again.** A fire set aside because its code went past what its plan gives it — its
78
+ * memory, its CPU, its calls — would be at the next fire too: the schedule waits on that one job, moving on with the
79
+ * clock, until somebody resumes or cancels it; and tries one again by itself a day later. An every-minute sweep that
80
+ * needed more memory than its size has was one more job set aside every minute, each a failed run.
69
81
  */
70
82
  export declare const createScheduler: ({ queue, lookups, environment, pollMs, batch, maxAttempts, reconcileMs, spaces, admit, onError }: SchedulerOptions) => Scheduler;
@@ -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-HDpOahhW.mjs";
2
- import { i as readFunctionsDir, n as loadFunctions, r as loadFunctionsSource } from "../chunks/load-DTPs5l0C.mjs";
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-CqtrQfYf.mjs";
2
+ import { i as readFunctionsDir, n as loadFunctions, r as loadFunctionsSource } from "../chunks/load-DxIZm6AM.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.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-HDpOahhW.mjs";
2
- import { n as describeTask, r as createConnectorResolver, t as describeCatalog } from "./chunks/taskCatalog-DBVODJX7.mjs";
3
- import { n as stateOf, t as documentOf } from "./chunks/queueDocument-xYz-KZ5V.mjs";
4
- import { a as emptyState, c as queueRules, i as changedBy, r as applyRule, s as queueOver } from "./chunks/queueRules-BCCVgeUE.mjs";
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-CqtrQfYf.mjs";
2
+ import { n as describeTask, r as createConnectorResolver, t as describeCatalog } from "./chunks/taskCatalog-1Jc6_ZAn.mjs";
3
+ import { n as stateOf, t as documentOf } from "./chunks/queueDocument-4M64XO0Q.mjs";
4
+ import { a as emptyState, c as queueRules, i as changedBy, r as applyRule, s as queueOver } from "./chunks/queueRules-Dk8mNzEJ.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";
@@ -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-BCCVgeUE.mjs";
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-Dk8mNzEJ.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
@@ -346,7 +346,7 @@ var createMongoJobQueue = ({ db, collections: names = {}, retentionDays = 90 })
346
346
  nextRunAt: { $lte: at }
347
347
  }).sort({ nextRunAt: 1 }).limit(limit).toArray()).map(toSchedule);
348
348
  },
349
- advanceSchedule: async ({ spaceId, actionId, from, to, missed }) => {
349
+ advanceSchedule: async ({ spaceId, actionId, from, to, missed, held }) => {
350
350
  const { schedules } = await collections();
351
351
  const at = await clock.now();
352
352
  return (await schedules.updateOne({
@@ -355,7 +355,7 @@ var createMongoJobQueue = ({ db, collections: names = {}, retentionDays = 90 })
355
355
  }, {
356
356
  $set: {
357
357
  nextRunAt: to,
358
- lastFireAt: from,
358
+ ...held ? {} : { lastFireAt: from },
359
359
  updatedAt: at
360
360
  },
361
361
  $inc: { missed }
@@ -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-BCCVgeUE.mjs";
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-Dk8mNzEJ.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 = ?, updated_at = ?, missed = missed + ?
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,
@@ -1,5 +1,5 @@
1
- import { n as stateOf, t as documentOf } from "../chunks/queueDocument-xYz-KZ5V.mjs";
2
- import { a as emptyState, c as queueRules, i as changedBy, r as applyRule, s as queueOver } from "../chunks/queueRules-BCCVgeUE.mjs";
1
+ import { n as stateOf, t as documentOf } from "../chunks/queueDocument-4M64XO0Q.mjs";
2
+ import { a as emptyState, c as queueRules, i as changedBy, r as applyRule, s as queueOver } from "../chunks/queueRules-Dk8mNzEJ.mjs";
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
5
5
  import { DatabaseSync } from "node:sqlite";
@@ -155,7 +155,7 @@ export type ActionSchedule = {
155
155
  enabled: boolean;
156
156
  /** Epoch ms of the next fire this schedule owes. The queue's clock decides when that has arrived. */
157
157
  nextRunAt: number;
158
- /** The last fire actually enqueued. */
158
+ /** The last fire actually enqueued: one the scheduler held back (`advanceSchedule`'s `held`) does not move it. */
159
159
  lastFireAt?: number;
160
160
  /** Fires that went by while nothing was running to take them. Cumulative, and shown to an operator. */
161
161
  missed: number;
@@ -239,6 +239,11 @@ export type JobQueue = {
239
239
  from: number;
240
240
  to: number;
241
241
  missed: number;
242
+ /**
243
+ * The fire at `from` was not enqueued — the schedule waits on the one before it, set aside at a limit it would
244
+ * meet again: it moves on with the clock, and `lastFireAt` stays the fire that was.
245
+ */
246
+ held?: boolean;
242
247
  }) => Promise<boolean>;
243
248
  /** Replaces what this space has scheduled. An action no longer listed stops having a schedule at all. */
244
249
  putSchedules: (params: {
@@ -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-HDpOahhW.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-CqtrQfYf.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-DBVODJX7.mjs";
6
- import { t as isFunctionsDefinition } from "../chunks/load-DTPs5l0C.mjs";
5
+ import { r as createConnectorResolver, t as describeCatalog } from "../chunks/taskCatalog-1Jc6_ZAn.mjs";
6
+ import { t as isFunctionsDefinition } from "../chunks/load-DxIZm6AM.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.6",
3
+ "version": "0.39.7",
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.6",
41
- "@plitzi/sdk-shared": "0.39.6",
40
+ "@plitzi/sdk-kernel": "0.39.7",
41
+ "@plitzi/sdk-shared": "0.39.7",
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.6",
62
+ "@plitzi/sdk-runtime": "0.39.7",
63
63
  "@types/node": "^26.6.6",
64
64
  "@types/nodemailer": "^8.0.2",
65
65
  "@types/ws": "^8.18.2",