@plitzi/sdk-actions 0.39.14 → 0.39.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @plitzi/sdk-actions
2
2
 
3
+ ## 0.39.15
4
+
5
+ ### Patch Changes
6
+
7
+ - 359fd04: Released with every `@plitzi` package at this version. What changed in each, and what to do when you upgrade, is in
8
+ `@plitzi/cli`'s `CHANGELOG.md`: one copy of the notes, not one per package.
9
+ - Updated dependencies [359fd04]
10
+ - @plitzi/sdk-kernel@0.39.15
11
+ - @plitzi/sdk-shared@0.39.15
12
+
3
13
  ## 0.39.14
4
14
 
5
15
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import { i as buildFunctions } from "./module-RTJHp4G8.mjs";
1
+ import { i as buildFunctions } from "./module-BGt8qxNC.mjs";
2
2
  import { isRecord } from "@plitzi/sdk-shared/helpers";
3
3
  import { readFunctionsSource } from "@plitzi/sdk-shared/actions";
4
4
  import { readFile, readdir } from "node:fs/promises";
@@ -1,14 +1,14 @@
1
- import { a as emptyState, o as queueOver, p as SET_ASIDE_WORDS, r as applyRule, s as queueRules } from "./queueRules-UGZNkho0.mjs";
1
+ import { a as emptyState, m as SET_ASIDE_WORDS, o as queueOver, r as applyRule, s as queueRules } from "./queueRules-CJ9Huag3.mjs";
2
2
  import { a as triggerParams, i as findTriggerNode, n as RunLimitReached, r as limitOf, t as ActionRunError } from "./errors-bCBfIe7c.mjs";
3
3
  import { i as KV_METHODS, n as MAX_GRANT_SECONDS, o as createMemoryKv, t as DEFAULT_GRANT_SECONDS } from "./grants-ZR79buug.mjs";
4
4
  import { cappedResponse, fetchOutbound, isBlockedHost } from "@plitzi/sdk-kernel/outbound";
5
5
  import { BODYLESS_METHODS, DEFAULT_READ_ENDPOINT, EMPTY_RESPONSE_METHODS } from "@plitzi/sdk-shared/connectors";
6
6
  import { processTwig, processTwigParam, resolveStepParam } from "@plitzi/sdk-shared/helpers/twigWrapper";
7
7
  import { createCipheriv, createDecipheriv, createHash, createHmac, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
8
+ import { serverLog } from "@plitzi/sdk-kernel/log";
8
9
  import { isRecord } from "@plitzi/sdk-shared/helpers";
9
10
  import { DEFAULT_FUNCTION_ASKED_LIMITS, FAILURE_HANDLER_TASK, FLOW_DELAY_MAX_MS, FUNCTION_ASKED_KEYS, FUNCTION_ROUTES_PREFIX, PLUGIN_ROUTES_SEGMENT, accessRefusal, actionAccessOf, cronFiresBetween, cronNextFire, exportsByDefault, isFunctionsDefinitionFile, isFunctionsSourcePath, isKnownTimeZone, isSingleEmailAddress, isTerminalJobStatus, readSmtpCredential, triggerAccess, triggerInput } from "@plitzi/sdk-shared/actions";
10
11
  import path from "node:path";
11
- import { serverLog } from "@plitzi/sdk-kernel/log";
12
12
  import { overloaded, processLoad, sampleProcessMemory } from "@plitzi/sdk-kernel/stats";
13
13
  import { getHeapStatistics } from "node:v8";
14
14
  import { ActionRefusal, FUNCTION_SIZES, FUNCTION_SIZE_NAMES, FunctionFailure, changeKv, changeListEntry, defineFunctions, functionSizesWithin, isActionRefusal, isFunctionLimit, isFunctionSize, isStreamedRouteAnswer, refusalCodeOf, responseOf, wireRequestOf, wireResponseFrom, wireResponseOf } from "@plitzi/sdk-shared/functions";
@@ -385,76 +385,6 @@ var readKeptCall = async (queue, spaceId, jobId, ticket) => {
385
385
  }
386
386
  }
387
387
  };
388
- // src/engine/jobs/codeMarks.ts
389
- /**
390
- * The queue, marking each action job it is given whose action runs the space's own code (`target.code`) — read off its
391
- * document as it is queued, wherever from: a schedule's fire, a run set for later, a call kept for when a runner is
392
- * back. What lets a worker whose runs wait for a runner with room go on taking the jobs that need none
393
- * (`claim({ takes: 'light' })`). A mark that misses costs only that: the job waits beside the others, as before.
394
- */
395
- var codeMarkingQueue = (queue, lookups, runsCode) => ({
396
- ...queue,
397
- enqueue: async (job) => {
398
- const { target } = job;
399
- if (target.kind !== "action" || target.code) return queue.enqueue(job);
400
- const entry = await lookups.getAction(job.spaceId, target.name, target.at).catch((error) => {
401
- serverLog.warn("Actions", `job ${job.id}: queued without reading whether its action runs the space's code`, error);
402
- });
403
- return queue.enqueue(entry && runsCode(entry.document) ? {
404
- ...job,
405
- target: {
406
- ...target,
407
- code: true
408
- }
409
- } : job);
410
- }
411
- });
412
- // src/engine/jobs/memoryQueue.ts
413
- /** Every method of the queue, for the copy a server's workers share (`FleetStores`, `core/server/fleet/link.ts`). */
414
- var JOB_QUEUE_METHODS = {
415
- now: true,
416
- enqueue: true,
417
- claim: true,
418
- heartbeat: true,
419
- settle: true,
420
- write: true,
421
- dueSchedules: true,
422
- advanceSchedule: true,
423
- putSchedules: true,
424
- listJobs: true,
425
- listJobGroups: true,
426
- listAcross: true,
427
- summarize: true,
428
- countDue: true,
429
- flow: true,
430
- getJob: true,
431
- listSchedules: true,
432
- requeue: true,
433
- cancel: true,
434
- pause: true,
435
- resume: true,
436
- cancelPending: true,
437
- cancelWaiting: true,
438
- resumeWaiting: true
439
- };
440
- /**
441
- * The default queue: one process's Maps.
442
- *
443
- * Correct for a deployment that runs ONE replica, which is most self-hosted ones, and honest about the rest — a
444
- * second replica running on this gets its own schedules and its own jobs, so a nightly digest goes out twice. The
445
- * cure is any store the replicas share, behind the same {@link JobQueue} seam.
446
- *
447
- * It keeps the contract exactly, rather than approximately: enqueue is idempotent by id, a claim reaps lapsed
448
- * leases, and every instant is read here rather than accepted from a caller. A test that passes against this one
449
- * is testing the rules a shared store has to keep too.
450
- */
451
- var createMemoryJobQueue = ({ retainFinished = 500, clock = Date.now } = {}) => {
452
- const rules = queueRules(emptyState(), {
453
- retainFinished,
454
- clock
455
- });
456
- return queueOver((method, args) => Promise.resolve(applyRule(rules, method, args)));
457
- };
458
388
  // src/engine/jobs/endings.ts
459
389
  /** How a job ends badly: given up, set aside at a limit, or out of attempts — and what its line says. */
460
390
  /**
@@ -568,6 +498,76 @@ var limitEndings = ({ workerId, settle, release, nextMinuteMs }) => async (job,
568
498
  });
569
499
  return true;
570
500
  };
501
+ // src/engine/jobs/codeMarks.ts
502
+ /**
503
+ * The queue, marking each action job it is given whose action runs the space's own code (`target.code`) — read off its
504
+ * document as it is queued, wherever from: a schedule's fire, a run set for later, a call kept for when a runner is
505
+ * back. What lets a worker whose runs wait for a runner with room go on taking the jobs that need none
506
+ * (`claim({ takes: 'light' })`). A mark that misses costs only that: the job waits beside the others, as before.
507
+ */
508
+ var codeMarkingQueue = (queue, lookups, runsCode) => ({
509
+ ...queue,
510
+ enqueue: async (job) => {
511
+ const { target } = job;
512
+ if (target.kind !== "action" || target.code) return queue.enqueue(job);
513
+ const entry = await lookups.getAction(job.spaceId, target.name, target.at).catch((error) => {
514
+ serverLog.warn("Actions", `job ${job.id}: queued without reading whether its action runs the space's code`, error);
515
+ });
516
+ return queue.enqueue(entry && runsCode(entry.document) ? {
517
+ ...job,
518
+ target: {
519
+ ...target,
520
+ code: true
521
+ }
522
+ } : job);
523
+ }
524
+ });
525
+ // src/engine/jobs/memoryQueue.ts
526
+ /** Every method of the queue, for the copy a server's workers share (`FleetStores`, `core/server/fleet/link.ts`). */
527
+ var JOB_QUEUE_METHODS = {
528
+ now: true,
529
+ enqueue: true,
530
+ claim: true,
531
+ heartbeat: true,
532
+ settle: true,
533
+ write: true,
534
+ dueSchedules: true,
535
+ advanceSchedule: true,
536
+ putSchedules: true,
537
+ listJobs: true,
538
+ listJobGroups: true,
539
+ listAcross: true,
540
+ summarize: true,
541
+ countDue: true,
542
+ flow: true,
543
+ getJob: true,
544
+ listSchedules: true,
545
+ requeue: true,
546
+ cancel: true,
547
+ pause: true,
548
+ resume: true,
549
+ cancelPending: true,
550
+ cancelWaiting: true,
551
+ resumeWaiting: true
552
+ };
553
+ /**
554
+ * The default queue: one process's Maps.
555
+ *
556
+ * Correct for a deployment that runs ONE replica, which is most self-hosted ones, and honest about the rest — a
557
+ * second replica running on this gets its own schedules and its own jobs, so a nightly digest goes out twice. The
558
+ * cure is any store the replicas share, behind the same {@link JobQueue} seam.
559
+ *
560
+ * It keeps the contract exactly, rather than approximately: enqueue is idempotent by id, a claim reaps lapsed
561
+ * leases, and every instant is read here rather than accepted from a caller. A test that passes against this one
562
+ * is testing the rules a shared store has to keep too.
563
+ */
564
+ var createMemoryJobQueue = ({ retainFinished = 500, clock = Date.now } = {}) => {
565
+ const rules = queueRules(emptyState(), {
566
+ retainFinished,
567
+ clock
568
+ });
569
+ return queueOver((method, args) => Promise.resolve(applyRule(rules, method, args)));
570
+ };
571
571
  // src/engine/jobs/failureStreak.ts
572
572
  /** How long a pass may keep failing before it is reported as the error it has become. */
573
573
  var FAILURE_STREAK_ESCALATION_MS = 6e4;
@@ -7130,4 +7130,4 @@ var createActionsModule = (given) => {
7130
7130
  }
7131
7131
  return module;
7132
7132
  };
7133
- export { schedulesFor as A, fleetJobQueue as C, DEFAULT_MAX_ATTEMPTS as D, createScheduler as E, readKeptCall as F, fetchConnectorRecords as I, rebaseMedia as L, KEPT_CALLS_PER_SPACE as M, KEPT_CALL_MS as N, scheduleFor as O, keepCall as P, writeConnectorRecord as R, ACTIONS_FLEET_STORES as S, createJobWorker as T, DEFAULT_LIMITS as _, createTaskRegistry as a, MAX_LIST_ENTRIES as b, oauthCallbackUrlOn as c, DEFAULT_FUNCTION_LIMITS as d, taskName as f, spaceKvPatterns as g, precheckRun as h, buildFunctions as i, createMemoryJobQueue as j, scheduleJobId as k, readManifest as l, createSigning as m, functionsInHand as n, DEFAULT_FUNCTION_JOB_LIMITS as o, MIN_SIGNING_SECRET_LENGTH as p, FunctionsBuildError as r, jobViewOf as s, createActionsModule as t, DEFAULT_FUNCTION_CEILINGS as u, createKvStore as v, fleetKv as w, createActionJobs as x, MAX_LIST_BYTES as y };
7133
+ export { schedulesFor as A, fleetJobQueue as C, DEFAULT_MAX_ATTEMPTS as D, createScheduler as E, keepCall as F, readKeptCall as I, fetchConnectorRecords as L, SET_ASIDE_LIMITS as M, KEPT_CALLS_PER_SPACE as N, scheduleFor as O, KEPT_CALL_MS as P, rebaseMedia as R, ACTIONS_FLEET_STORES as S, createJobWorker as T, DEFAULT_LIMITS as _, createTaskRegistry as a, MAX_LIST_ENTRIES as b, oauthCallbackUrlOn as c, DEFAULT_FUNCTION_LIMITS as d, taskName as f, spaceKvPatterns as g, precheckRun as h, buildFunctions as i, createMemoryJobQueue as j, scheduleJobId as k, readManifest as l, createSigning as m, functionsInHand as n, DEFAULT_FUNCTION_JOB_LIMITS as o, MIN_SIGNING_SECRET_LENGTH as p, FunctionsBuildError as r, jobViewOf as s, createActionsModule as t, DEFAULT_FUNCTION_CEILINGS as u, createKvStore as v, fleetKv as w, createActionJobs as x, MAX_LIST_BYTES as y, writeConnectorRecord as z };
@@ -1,4 +1,4 @@
1
- import { c as scheduleKey } from "./queueRules-UGZNkho0.mjs";
1
+ import { c as scheduleKey } from "./queueRules-CJ9Huag3.mjs";
2
2
  import { isRecord } from "@plitzi/sdk-shared/helpers";
3
3
  // src/engine/jobs/queueDocument.ts
4
4
  var documentOf = ({ jobs, schedules }) => ({
@@ -1,5 +1,33 @@
1
1
  import { isRecord } from "@plitzi/sdk-shared/helpers";
2
2
  import { isTerminalJobStatus } from "@plitzi/sdk-shared/actions";
3
+ // src/engine/jobs/memoryNeeds.ts
4
+ /**
5
+ * What a job needs once the worker running it died, in the words every store writes: the in-process ones through
6
+ * `queueRules`, Mongo and MySQL in their own queries — each composing the same sentences from these parts.
7
+ *
8
+ * A worker dies for many reasons — a node lost, a deploy past its grace — and the job is simply run again. But one that
9
+ * died near its memory (it said so: `heartbeat`'s `nearMemoryLimit`), or a second in a row to die running the same job,
10
+ * was taken down by the job: run again on the same size, it ends that one too, and the next. That job needs more than
11
+ * the worker could hold, when the claims say what their workers may (`JobClaimMemory`).
12
+ */
13
+ /** What the history says of an attempt nobody reported. */
14
+ var LOST_ERROR = "the worker holding this job stopped reporting";
15
+ /** {@link lostError}'s words around what the worker could hold. */
16
+ var LOST_MEMORY_WORDS = [`${LOST_ERROR} near its memory — it could hold `, " MiB, so the job runs next on a worker that may hold more"];
17
+ /** {@link setAsideError}'s words around what the job needs more than, and what the largest worker may hold. */
18
+ var SET_ASIDE_WORDS = [
19
+ "Set aside: a worker died running it — it needs more than ",
20
+ " MiB, and the largest worker here may hold ",
21
+ " MiB. Give a worker more memory, then resume it."
22
+ ];
23
+ /** Whether the job took its worker down: it neared its memory holding it, or the attempt before was lost too. */
24
+ var outgrewWorker = (job) => job.nearMemoryLimit === true || job.history.at(-1)?.status === "lost";
25
+ /** The least a job needs after the worker holding it died: more than that one could hold when the job took it down. */
26
+ var needsAfterLoss = (needsMb, holderMb, outgrew) => holderMb === void 0 || !outgrew ? needsMb : Math.max(needsMb ?? 0, holderMb + 1);
27
+ /** Why a job waits after its worker died: for a larger one, when it took that worker down and it said its size. */
28
+ var lostError = (holderMb, outgrew) => holderMb === void 0 || !outgrew ? LOST_ERROR : `${LOST_MEMORY_WORDS[0]}${String(holderMb)}${LOST_MEMORY_WORDS[1]}`;
29
+ /** Why a job is set aside: no worker of the deployment may hold what it needs. */
30
+ var setAsideError = (needsMb, ceilingMb) => `${SET_ASIDE_WORDS[0]}${String(needsMb - 1)}${SET_ASIDE_WORDS[1]}${String(ceilingMb)}${SET_ASIDE_WORDS[2]}`;
3
31
  // src/engine/jobs/flow.ts
4
32
  var MINUTE = 6e4;
5
33
  var p95 = (values) => {
@@ -85,34 +113,6 @@ var groupJobs = (newestFirst) => {
85
113
  }
86
114
  return [...groups.values()];
87
115
  };
88
- // src/engine/jobs/memoryNeeds.ts
89
- /**
90
- * What a job needs once the worker running it died, in the words every store writes: the in-process ones through
91
- * `queueRules`, Mongo and MySQL in their own queries — each composing the same sentences from these parts.
92
- *
93
- * A worker dies for many reasons — a node lost, a deploy past its grace — and the job is simply run again. But one that
94
- * died near its memory (it said so: `heartbeat`'s `nearMemoryLimit`), or a second in a row to die running the same job,
95
- * was taken down by the job: run again on the same size, it ends that one too, and the next. That job needs more than
96
- * the worker could hold, when the claims say what their workers may (`JobClaimMemory`).
97
- */
98
- /** What the history says of an attempt nobody reported. */
99
- var LOST_ERROR = "the worker holding this job stopped reporting";
100
- /** {@link lostError}'s words around what the worker could hold. */
101
- var LOST_MEMORY_WORDS = [`${LOST_ERROR} near its memory — it could hold `, " MiB, so the job runs next on a worker that may hold more"];
102
- /** {@link setAsideError}'s words around what the job needs more than, and what the largest worker may hold. */
103
- var SET_ASIDE_WORDS = [
104
- "Set aside: a worker died running it — it needs more than ",
105
- " MiB, and the largest worker here may hold ",
106
- " MiB. Give a worker more memory, then resume it."
107
- ];
108
- /** Whether the job took its worker down: it neared its memory holding it, or the attempt before was lost too. */
109
- var outgrewWorker = (job) => job.nearMemoryLimit === true || job.history.at(-1)?.status === "lost";
110
- /** The least a job needs after the worker holding it died: more than that one could hold when the job took it down. */
111
- var needsAfterLoss = (needsMb, holderMb, outgrew) => holderMb === void 0 || !outgrew ? needsMb : Math.max(needsMb ?? 0, holderMb + 1);
112
- /** Why a job waits after its worker died: for a larger one, when it took that worker down and it said its size. */
113
- var lostError = (holderMb, outgrew) => holderMb === void 0 || !outgrew ? LOST_ERROR : `${LOST_MEMORY_WORDS[0]}${String(holderMb)}${LOST_MEMORY_WORDS[1]}`;
114
- /** Why a job is set aside: no worker of the deployment may hold what it needs. */
115
- var setAsideError = (needsMb, ceilingMb) => `${SET_ASIDE_WORDS[0]}${String(needsMb - 1)}${SET_ASIDE_WORDS[1]}${String(ceilingMb)}${SET_ASIDE_WORDS[2]}`;
116
116
  // src/engine/jobs/waitingRules.ts
117
117
  /**
118
118
  * What an operator does to the jobs that have not started, at once — the in-process stores' half of `cancelWaiting` and
@@ -605,4 +605,4 @@ var queueOver = (access) => ({
605
605
  cancelWaiting: (...args) => access("cancelWaiting", args),
606
606
  resumeWaiting: (...args) => access("resumeWaiting", args)
607
607
  });
608
- export { flowOf as _, emptyState as a, scheduleKey as c, LOST_ERROR as d, LOST_MEMORY_WORDS as f, outgrewWorker as g, needsAfterLoss as h, changedBy as i, statusCounts as l, lostError as m, WAITING_STATUSES as n, queueOver as o, SET_ASIDE_WORDS as p, applyRule as r, queueRules as s, NEEDING_STATUSES as t, waitingKindOf as u };
608
+ export { outgrewWorker as _, emptyState as a, scheduleKey as c, flowOf as d, LOST_ERROR as f, needsAfterLoss as g, lostError as h, changedBy as i, statusCounts as l, SET_ASIDE_WORDS as m, WAITING_STATUSES as n, queueOver as o, LOST_MEMORY_WORDS as p, applyRule as r, queueRules as s, NEEDING_STATUSES as t, waitingKindOf as u };
@@ -1,4 +1,4 @@
1
- import { I as fetchConnectorRecords } from "./module-RTJHp4G8.mjs";
1
+ import { L as fetchConnectorRecords } from "./module-BGt8qxNC.mjs";
2
2
  import { getSourceName } from "@plitzi/sdk-shared/dataSource/helpers";
3
3
  // src/connectors/projection.ts
4
4
  /**
@@ -0,0 +1,15 @@
1
+ import { JobQueue } from '../../types';
2
+ import { Job } from '@plitzi/sdk-shared';
3
+ /**
4
+ * Whether a job was set aside for what its own code did — stopped at a limit its run reached (its CPU, its memory, its
5
+ * calls…), or failing every attempt — rather than by hand, at its plan's allowance (`quota`), or because a worker died
6
+ * running it (that one waits for a worker large enough, not for new code).
7
+ */
8
+ export declare const setAsideByItsCode: (job: Pick<Job, "status" | "history" | "attempts" | "maxAttempts">) => boolean;
9
+ /**
10
+ * A space's code changed — its functions or its actions saved: every job of it set aside for what its code did goes back
11
+ * in the queue, to run as the code now is. A schedule waiting on one fires again with it (`scheduleHold`); one that
12
+ * meets the same limit is set aside again, and its schedule waits again — one run, not a fire a minute. What was set
13
+ * aside by hand, at the plan's allowance or for a larger worker stays where it is. Answers the jobs it put back.
14
+ */
15
+ export declare const resumeAfterCodeChange: (queue: JobQueue, spaceId: number) => Promise<string[]>;
@@ -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-RTJHp4G8.mjs";
2
- import { i as readFunctionsDir, n as loadFunctions, r as loadFunctionsSource } from "../chunks/load-dDkFegMP.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-BGt8qxNC.mjs";
2
+ import { i as readFunctionsDir, n as loadFunctions, r as loadFunctionsSource } from "../chunks/load-CBBAXiBR.mjs";
3
3
  import { t as credentialsFromEnv } from "../chunks/credentials-DwxZeAvH.mjs";
4
4
  import { randomUUID } from "node:crypto";
5
5
  import { FUNCTIONS_PROTOCOL, FunctionFailure, failedAnswerOf, readResponseMessage } from "@plitzi/sdk-shared/functions";
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { fetchConnectorRecords, rebaseMedia, writeConnectorRecord } from './connectors/engine';
2
2
  export { createConnectorResolver } from './connectors/resolver';
3
3
  export { KEPT_CALL_MS, KEPT_CALLS_PER_SPACE } from './engine/jobs/calls';
4
+ export { resumeAfterCodeChange, setAsideByItsCode } from './engine/jobs/codeChanged';
4
5
  export { createFileJobQueue } from './engine/jobs/fileQueue';
5
6
  export { createActionJobs } from './engine/jobs/jobs';
6
7
  export { createMemoryJobQueue } from './engine/jobs/memoryQueue';
package/dist/index.mjs CHANGED
@@ -1,17 +1,53 @@
1
- import { A as schedulesFor, C as fleetJobQueue, D as DEFAULT_MAX_ATTEMPTS, E as createScheduler, 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-RTJHp4G8.mjs";
2
- import { n as describeTask, r as createConnectorResolver, t as describeCatalog } from "./chunks/taskCatalog-D3vyVCWp.mjs";
3
- import { n as stateOf, t as documentOf } from "./chunks/queueDocument-DCBWcxe_.mjs";
4
- import { a as emptyState, i as changedBy, l as statusCounts, o as queueOver, r as applyRule, s as queueRules } from "./chunks/queueRules-UGZNkho0.mjs";
1
+ import { A as schedulesFor, C as fleetJobQueue, D as DEFAULT_MAX_ATTEMPTS, E as createScheduler, L as fetchConnectorRecords, M as SET_ASIDE_LIMITS, N as KEPT_CALLS_PER_SPACE, O as scheduleFor, P as KEPT_CALL_MS, R as rebaseMedia, T as createJobWorker, _ as DEFAULT_LIMITS, a as createTaskRegistry, b as MAX_LIST_ENTRIES, f as taskName, g as spaceKvPatterns, j as createMemoryJobQueue, k as scheduleJobId, m as createSigning, p as MIN_SIGNING_SECRET_LENGTH, s as jobViewOf, t as createActionsModule, v as createKvStore, w as fleetKv, x as createActionJobs, y as MAX_LIST_BYTES, z as writeConnectorRecord } from "./chunks/module-BGt8qxNC.mjs";
2
+ import { n as describeTask, r as createConnectorResolver, t as describeCatalog } from "./chunks/taskCatalog-GrTxD29I.mjs";
3
+ import { n as stateOf, t as documentOf } from "./chunks/queueDocument-BsYXkDDZ.mjs";
4
+ import { a as emptyState, i as changedBy, l as statusCounts, o as queueOver, r as applyRule, s as queueRules } from "./chunks/queueRules-CJ9Huag3.mjs";
5
5
  import { a as triggerParams, t as ActionRunError } from "./chunks/errors-bCBfIe7c.mjs";
6
6
  import { a as createMapKv, o as createMemoryKv } from "./chunks/grants-ZR79buug.mjs";
7
7
  import { createActionRealtime, n as publishJobView, r as createRealtimeHub, t as createRealtimeRetained } from "./realtime/index.mjs";
8
8
  import { t as credentialsFromEnv } from "./chunks/credentials-DwxZeAvH.mjs";
9
9
  import { hasValidToken } from "@plitzi/sdk-shared/helpers/twigWrapper";
10
+ import { serverLog } from "@plitzi/sdk-kernel/log";
10
11
  import fs from "node:fs";
11
12
  import { parseCron, readSmtpCredential, triggerHasStaleVerify, triggerVerify } from "@plitzi/sdk-shared/actions";
12
13
  import path from "node:path";
13
14
  import { writeFileAtomic } from "@plitzi/sdk-kernel/files";
14
- import { serverLog } from "@plitzi/sdk-kernel/log";
15
+ // src/engine/jobs/codeChanged.ts
16
+ /** How many of a space's jobs set aside are read at a time. */
17
+ var PAGE = 200;
18
+ /**
19
+ * Whether a job was set aside for what its own code did — stopped at a limit its run reached (its CPU, its memory, its
20
+ * calls…), or failing every attempt — rather than by hand, at its plan's allowance (`quota`), or because a worker died
21
+ * running it (that one waits for a worker large enough, not for new code).
22
+ */
23
+ var setAsideByItsCode = (job) => {
24
+ if (job.status !== "paused") return false;
25
+ const last = job.history.at(-1);
26
+ if (last?.limit !== void 0) return last.limit !== "quota" && SET_ASIDE_LIMITS.has(last.limit);
27
+ return last?.status === "failed" && job.attempts >= job.maxAttempts;
28
+ };
29
+ /**
30
+ * A space's code changed — its functions or its actions saved: every job of it set aside for what its code did goes back
31
+ * in the queue, to run as the code now is. A schedule waiting on one fires again with it (`scheduleHold`); one that
32
+ * meets the same limit is set aside again, and its schedule waits again — one run, not a fire a minute. What was set
33
+ * aside by hand, at the plan's allowance or for a larger worker stays where it is. Answers the jobs it put back.
34
+ */
35
+ var resumeAfterCodeChange = async (queue, spaceId) => {
36
+ const setAside = [];
37
+ for (;;) {
38
+ const { jobs, total } = await queue.listJobs({
39
+ spaceIds: [spaceId],
40
+ status: "paused",
41
+ limit: PAGE,
42
+ offset: setAside.length
43
+ });
44
+ setAside.push(...jobs);
45
+ if (jobs.length === 0 || setAside.length >= total) break;
46
+ }
47
+ const again = setAside.filter(setAsideByItsCode);
48
+ const resumed = await Promise.all(again.map((job) => queue.resume([spaceId], job.id)));
49
+ return again.filter((_, index) => resumed[index]).map((job) => job.id);
50
+ };
15
51
  // src/engine/fileStore.ts
16
52
  var holderIn = (lock) => {
17
53
  try {
@@ -566,4 +602,4 @@ var createJobControl = ({ queue, realtime }) => {
566
602
  }
567
603
  };
568
604
  };
569
- export { ActionRunError, DEFAULT_LIMITS, DEFAULT_MAX_ATTEMPTS, FileInUseError, KEPT_CALLS_PER_SPACE, KEPT_CALL_MS, MAX_LIST_BYTES, MAX_LIST_ENTRIES, MIN_SIGNING_SECRET_LENGTH, checkAction, createActionJobs, createActionRealtime, createActionsModule, createConnectorResolver, createFileJobQueue, createFileKv, createJobControl, createJobWorker, createKvStore, createMemoryJobQueue, createMemoryKv, createRedisKv, createRejectLogger, createRunLogger, createScheduler, createSigning, createTaskRegistry, credentialsFromEnv, describeCatalog, describeTask, fetchConnectorRecords, fleetJobQueue, fleetKv, rebaseMedia, scheduleFor, scheduleJobId, schedulesFor, spaceKvPatterns, statusCounts, taskName, writeConnectorRecord };
605
+ export { ActionRunError, DEFAULT_LIMITS, DEFAULT_MAX_ATTEMPTS, FileInUseError, KEPT_CALLS_PER_SPACE, KEPT_CALL_MS, MAX_LIST_BYTES, MAX_LIST_ENTRIES, MIN_SIGNING_SECRET_LENGTH, checkAction, createActionJobs, createActionRealtime, createActionsModule, createConnectorResolver, createFileJobQueue, createFileKv, createJobControl, createJobWorker, createKvStore, createMemoryJobQueue, createMemoryKv, createRedisKv, createRejectLogger, createRunLogger, createScheduler, createSigning, createTaskRegistry, credentialsFromEnv, describeCatalog, describeTask, fetchConnectorRecords, fleetJobQueue, fleetKv, rebaseMedia, resumeAfterCodeChange, scheduleFor, scheduleJobId, schedulesFor, setAsideByItsCode, spaceKvPatterns, statusCounts, taskName, writeConnectorRecord };
@@ -1,4 +1,4 @@
1
- import { _ as flowOf, d as LOST_ERROR, f as LOST_MEMORY_WORDS, l as statusCounts, n as WAITING_STATUSES, p as SET_ASIDE_WORDS, t as NEEDING_STATUSES, u as waitingKindOf } from "../chunks/queueRules-UGZNkho0.mjs";
1
+ import { d as flowOf, f as LOST_ERROR, l as statusCounts, m as SET_ASIDE_WORDS, n as WAITING_STATUSES, p as LOST_MEMORY_WORDS, t as NEEDING_STATUSES, u as waitingKindOf } from "../chunks/queueRules-CJ9Huag3.mjs";
2
2
  import { t as createStoreClock } from "../chunks/storeClock-Btm7EaVm.mjs";
3
3
  import { TERMINAL_JOB_STATUSES } from "@plitzi/sdk-shared/actions";
4
4
  // src/mongo/claimable.ts
@@ -1,4 +1,4 @@
1
- import { _ as flowOf, d as LOST_ERROR, g as outgrewWorker, h as needsAfterLoss, l as statusCounts, m as lostError, p as SET_ASIDE_WORDS, u as waitingKindOf } from "../chunks/queueRules-UGZNkho0.mjs";
1
+ import { _ as outgrewWorker, d as flowOf, f as LOST_ERROR, g as needsAfterLoss, h as lostError, l as statusCounts, m as SET_ASIDE_WORDS, u as waitingKindOf } from "../chunks/queueRules-CJ9Huag3.mjs";
2
2
  import { t as createStoreClock } from "../chunks/storeClock-Btm7EaVm.mjs";
3
3
  import { TERMINAL_JOB_STATUSES } from "@plitzi/sdk-shared/actions";
4
4
  import { execute, selectOne, selectRows } from "@plitzi/sdk-kernel/mysql";
@@ -1,5 +1,5 @@
1
- import { n as stateOf, t as documentOf } from "../chunks/queueDocument-DCBWcxe_.mjs";
2
- import { a as emptyState, i as changedBy, o as queueOver, r as applyRule, s as queueRules } from "../chunks/queueRules-UGZNkho0.mjs";
1
+ import { n as stateOf, t as documentOf } from "../chunks/queueDocument-BsYXkDDZ.mjs";
2
+ import { a as emptyState, i as changedBy, o as queueOver, r as applyRule, s as queueRules } from "../chunks/queueRules-CJ9Huag3.mjs";
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
5
5
  import { DatabaseSync } from "node:sqlite";
@@ -1,15 +1,15 @@
1
1
  import { handleRealtimePublish, handleRealtimeSocket, handleRealtimeSubscribe, realtimeModuleFor } from "../realtime/index.mjs";
2
2
  import { a as createActionResolver, i as readRenderAsk, n as RENDER_PATH, t as createRemoteRenderResolver } from "../chunks/remote-DZSzOO01.mjs";
3
- import { F as readKeptCall, P as keepCall, R as writeConnectorRecord, S as ACTIONS_FLEET_STORES, h as precheckRun, t as createActionsModule } from "../chunks/module-RTJHp4G8.mjs";
3
+ import { F as keepCall, I as readKeptCall, S as ACTIONS_FLEET_STORES, h as precheckRun, t as createActionsModule, z as writeConnectorRecord } from "../chunks/module-BGt8qxNC.mjs";
4
4
  import { a as triggerParams, i as findTriggerNode, t as ActionRunError } from "../chunks/errors-bCBfIe7c.mjs";
5
- import { r as createConnectorResolver, t as describeCatalog } from "../chunks/taskCatalog-D3vyVCWp.mjs";
6
- import { t as isFunctionsDefinition } from "../chunks/load-dDkFegMP.mjs";
5
+ import { r as createConnectorResolver, t as describeCatalog } from "../chunks/taskCatalog-GrTxD29I.mjs";
6
+ import { t as isFunctionsDefinition } from "../chunks/load-CBBAXiBR.mjs";
7
7
  import { privateOriginsOf } from "@plitzi/sdk-kernel/outbound";
8
8
  import { isConnectorManifestDraft, validateConnectorManifest } from "@plitzi/sdk-shared/connectors";
9
9
  import { createHmac, timingSafeEqual } from "node:crypto";
10
+ import { configureServerLog, defaultLogLevel, serverLog } from "@plitzi/sdk-kernel/log";
10
11
  import { isRecord } from "@plitzi/sdk-shared/helpers";
11
12
  import { FUNCTION_ROUTES_PREFIX, isActionDocument, triggerAccess, triggerHasStaleVerify, triggerVerify, validateActionDocument } from "@plitzi/sdk-shared/actions";
12
- import { configureServerLog, defaultLogLevel, serverLog } from "@plitzi/sdk-kernel/log";
13
13
  import { statsRecorderFor, statsStage } from "@plitzi/sdk-kernel/stats";
14
14
  import { protocolRefusal } from "@plitzi/sdk-shared/functions";
15
15
  import { bearerMatches, clientIp, createHttpServer, createMiddlewaresStage, crossSiteWritesStage, healthStage, makeHandler, onAbort, openEventStream, readRawBody, readRawBytes, requestAuthority, requestOrigin, runsFleetJobs, writeWebResponse } from "@plitzi/sdk-kernel/http";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plitzi/sdk-actions",
3
- "version": "0.39.14",
3
+ "version": "0.39.15",
4
4
  "license": "AGPL-3.0",
5
5
  "description": "The actions engine: server actions, a space's functions and runtimes as the platform holds them, the connectors, realtime, jobs, and the stock queues and stores. What a worker runs; what a page server is handed.",
6
6
  "files": [
@@ -37,8 +37,8 @@
37
37
  "build:prod": "vite build"
38
38
  },
39
39
  "dependencies": {
40
- "@plitzi/sdk-kernel": "0.39.14",
41
- "@plitzi/sdk-shared": "0.39.14",
40
+ "@plitzi/sdk-kernel": "0.39.15",
41
+ "@plitzi/sdk-shared": "0.39.15",
42
42
  "nodemailer": "^10.6.0",
43
43
  "ws": "^8.23.0"
44
44
  },
@@ -59,7 +59,7 @@
59
59
  }
60
60
  },
61
61
  "devDependencies": {
62
- "@plitzi/sdk-runtime": "0.39.14",
62
+ "@plitzi/sdk-runtime": "0.39.15",
63
63
  "@types/node": "^26.6.6",
64
64
  "@types/nodemailer": "^8.0.2",
65
65
  "@types/ws": "^8.18.2",