@plitzi/sdk-actions 0.39.11 → 0.39.13

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,25 @@
1
1
  # @plitzi/sdk-actions
2
2
 
3
+ ## 0.39.13
4
+
5
+ ### Patch Changes
6
+
7
+ - 919736b: 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 [919736b]
10
+ - @plitzi/sdk-kernel@0.39.13
11
+ - @plitzi/sdk-shared@0.39.13
12
+
13
+ ## 0.39.12
14
+
15
+ ### Patch Changes
16
+
17
+ - 2f5b44d: 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 [2f5b44d]
20
+ - @plitzi/sdk-kernel@0.39.12
21
+ - @plitzi/sdk-shared@0.39.12
22
+
3
23
  ## 0.39.11
4
24
 
5
25
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import { i as buildFunctions } from "./module-BejdMWyt.mjs";
1
+ import { i as buildFunctions } from "./module-Baod2T6h.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, o as queueOver, p as SET_ASIDE_WORDS, r as applyRule, s as queueRules } from "./queueRules-DCW5x5as.mjs";
1
+ import { a as emptyState, o as queueOver, p as SET_ASIDE_WORDS, r as applyRule, s as queueRules } from "./queueRules-UGZNkho0.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";
@@ -434,7 +434,8 @@ var JOB_QUEUE_METHODS = {
434
434
  pause: true,
435
435
  resume: true,
436
436
  cancelPending: true,
437
- cancelWaiting: true
437
+ cancelWaiting: true,
438
+ resumeWaiting: true
438
439
  };
439
440
  /**
440
441
  * The default queue: one process's Maps.
@@ -1749,21 +1750,13 @@ var createRunGuards = (config = {}, store, idempotency = {}) => {
1749
1750
  return total;
1750
1751
  };
1751
1752
  /**
1752
- * Takes the key, here and — when there is one — everywhere.
1753
- *
1754
- * `increment` is the primitive because it is the only atomic one the adapter contract has, and it says exactly
1755
- * what is needed: the caller whose increment answers `1` created the key and holds it. The lifetime is set by
1756
- * that same caller, which is the rule `createKvStore` already follows for a rate-limit window; the gap between
1757
- * the two calls is a key that outlives its holder if the process dies inside it, and it is the same gap that
1758
- * idiom has always had.
1753
+ * Takes the key, here and — when there is one — everywhere: written only where nothing holds it, with its lifetime in
1754
+ * the same write (`swap`), and holding the run's id. Never a key without one: taken by `increment` and given its
1755
+ * lifetime by an `expire` after, a store that timed out on the second (a rollout's Redis did) kept the key for good —
1756
+ * every later run of it refused as "already running" while nothing ran, its job back in the queue every second.
1759
1757
  */
1760
1758
  const ttlSeconds = (ttlMs) => Math.max(1, Math.ceil(ttlMs / 1e3));
1761
- const takeShared = async (runKey, ttlMs) => {
1762
- if (!store) return true;
1763
- if (await store.increment(`${keyPrefix}${runKey}`, 1) !== 1) return false;
1764
- await store.expire(`${keyPrefix}${runKey}`, ttlSeconds(ttlMs));
1765
- return true;
1766
- };
1759
+ const takeShared = async (runKey, runId, ttlMs) => store ? store.swap(`${keyPrefix}${runKey}`, void 0, runId, ttlSeconds(ttlMs)) : true;
1767
1760
  const begin = async (params) => {
1768
1761
  sweep();
1769
1762
  const runKey = deriveRunKey(params);
@@ -1811,7 +1804,7 @@ var createRunGuards = (config = {}, store, idempotency = {}) => {
1811
1804
  byKey.set(runKey, run);
1812
1805
  byId.set(run.runId, run);
1813
1806
  try {
1814
- if (!await takeShared(runKey, params.ttlMs)) throw new ActionRunError("duplicate", "This action is already running");
1807
+ if (!await takeShared(runKey, run.runId, params.ttlMs)) throw new ActionRunError("duplicate", "This action is already running");
1815
1808
  } catch (error) {
1816
1809
  byKey.delete(runKey);
1817
1810
  byId.delete(run.runId);
@@ -2320,7 +2313,8 @@ var flagsForRun = async (config, request) => {
2320
2313
  undeclaredFlagOverrides(declared, { server: overrides.server }).forEach(({ name }) => serverLog.warn("Actions", `The server sets the flag "${name}", which space ${spaceId} does not declare.`));
2321
2314
  return flagValues(resolveFlags(declared, {
2322
2315
  environment,
2323
- user: flagUserFromSSR(user)
2316
+ user: flagUserFromSSR(user),
2317
+ rollout: request.rolloutBuckets
2324
2318
  }, overrides));
2325
2319
  };
2326
2320
  // src/engine/runtime/scope.ts
@@ -1,4 +1,4 @@
1
- import { c as scheduleKey } from "./queueRules-DCW5x5as.mjs";
1
+ import { c as scheduleKey } from "./queueRules-UGZNkho0.mjs";
2
2
  import { isRecord } from "@plitzi/sdk-shared/helpers";
3
3
  // src/engine/jobs/queueDocument.ts
4
4
  var documentOf = ({ jobs, schedules }) => ({
@@ -1,3 +1,4 @@
1
+ import { isRecord } from "@plitzi/sdk-shared/helpers";
1
2
  import { isTerminalJobStatus } from "@plitzi/sdk-shared/actions";
2
3
  // src/engine/jobs/flow.ts
3
4
  var MINUTE = 6e4;
@@ -112,6 +113,46 @@ var needsAfterLoss = (needsMb, holderMb, outgrew) => holderMb === void 0 || !out
112
113
  var lostError = (holderMb, outgrew) => holderMb === void 0 || !outgrew ? LOST_ERROR : `${LOST_MEMORY_WORDS[0]}${String(holderMb)}${LOST_MEMORY_WORDS[1]}`;
113
114
  /** Why a job is set aside: no worker of the deployment may hold what it needs. */
114
115
  var setAsideError = (needsMb, ceilingMb) => `${SET_ASIDE_WORDS[0]}${String(needsMb - 1)}${SET_ASIDE_WORDS[1]}${String(ceilingMb)}${SET_ASIDE_WORDS[2]}`;
116
+ // src/engine/jobs/waitingRules.ts
117
+ /**
118
+ * What an operator does to the jobs that have not started, at once — the in-process stores' half of `cancelWaiting` and
119
+ * `resumeWaiting` (`queueRules`), over the jobs those keep and the instant their clock reads.
120
+ */
121
+ /** A job set aside, back in the queue at `at`: one set aside after failing every attempt has them all again. */
122
+ var putBack = (job, at) => {
123
+ job.status = "pending";
124
+ job.runAt = at;
125
+ job.updatedAt = at;
126
+ if (job.attempts >= job.maxAttempts) job.attempts = 0;
127
+ };
128
+ var named = (job, kind, name) => (kind === void 0 || job.target.kind === kind) && (name === void 0 || job.target.name === name);
129
+ var cancelWaitingIn = (jobs, { spaceIds, status, kind, name }, at) => {
130
+ const dropped = {
131
+ cancelled: 0,
132
+ functionJobs: []
133
+ };
134
+ for (const job of jobs) if (spaceIds.includes(job.spaceId) && (job.status === "pending" || job.status === "paused") && (status === void 0 || job.status === status) && named(job, kind, name)) {
135
+ job.status = "cancelled";
136
+ job.workerId = void 0;
137
+ job.pauseRequested = void 0;
138
+ job.updatedAt = at;
139
+ dropped.cancelled += 1;
140
+ if (job.target.kind === "function") dropped.functionJobs.push(job.id);
141
+ }
142
+ return dropped;
143
+ };
144
+ var resumeWaitingIn = (jobs, { spaceIds, kind, name }, at) => {
145
+ const put = {
146
+ resumed: 0,
147
+ functionJobs: []
148
+ };
149
+ for (const job of jobs) if (spaceIds.includes(job.spaceId) && job.status === "paused" && named(job, kind, name)) {
150
+ putBack(job, at);
151
+ put.resumed += 1;
152
+ if (job.target.kind === "function") put.functionJobs.push(job.id);
153
+ }
154
+ return put;
155
+ };
115
156
  // src/engine/jobs/queueRules.ts
116
157
  /** The kind of work a job is (`JobTake`): what a claim's `takes` picks by. */
117
158
  var takeOf = (target) => target.kind === "function" ? "functionJobs" : target.code ? "codeActions" : "light";
@@ -122,8 +163,11 @@ var takesSpace = (spaces, spaceId) => !spaces || ("only" in spaces ? spaces.only
122
163
  * 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.
123
164
  */
124
165
  var fits = (job, spaces, memory) => job.needsMemoryMb === void 0 ? takesSpace(spaces, job.spaceId) : memory !== void 0 && memory.takesNeeding !== false && memory.mb >= job.needsMemoryMb;
125
- /** Whether what `cancelWaiting` answered says it dropped a job. */
126
- var droppedSome = (answer) => typeof answer === "object" && answer !== null && "cancelled" in answer && typeof answer.cancelled === "number" && answer.cancelled > 0;
166
+ /** Whether what `cancelWaiting` or `resumeWaiting` answered says it moved a job: its count under `field`. */
167
+ var movedSome = (answer, field) => {
168
+ const moved = isRecord(answer) ? answer[field] : void 0;
169
+ return typeof moved === "number" && moved > 0;
170
+ };
127
171
  /**
128
172
  * Whether a call changed the state, by its method and what it answered — what a store keeping the state elsewhere writes
129
173
  * back after. A worker claims every second: a claim that took nothing, a refused `write` or `cancel` change nothing, and
@@ -140,7 +184,8 @@ var changedBy = (method, answer) => {
140
184
  case "pause":
141
185
  case "resume": return answer === true;
142
186
  case "cancelPending": return typeof answer === "number" && answer > 0;
143
- case "cancelWaiting": return droppedSome(answer);
187
+ case "cancelWaiting": return movedSome(answer, "cancelled");
188
+ case "resumeWaiting": return movedSome(answer, "resumed");
144
189
  case "heartbeat":
145
190
  case "settle":
146
191
  case "putSchedules": return true;
@@ -390,10 +435,7 @@ var queueRules = ({ jobs, schedules }, { retainFinished, clock, onUnansweredChan
390
435
  resume: (spaceIds, jobId) => {
391
436
  const job = owned(spaceIds, jobId);
392
437
  if (job?.status !== "paused") return false;
393
- job.status = "pending";
394
- job.runAt = now();
395
- job.updatedAt = now();
396
- if (job.attempts >= job.maxAttempts) job.attempts = 0;
438
+ putBack(job, now());
397
439
  return true;
398
440
  },
399
441
  cancelPending: ({ spaceId, key, olderThan }) => {
@@ -408,22 +450,8 @@ var queueRules = ({ jobs, schedules }, { retainFinished, clock, onUnansweredChan
408
450
  }
409
451
  return dropped;
410
452
  },
411
- cancelWaiting: ({ spaceIds, status, kind, name }) => {
412
- const at = now();
413
- const dropped = {
414
- cancelled: 0,
415
- functionJobs: []
416
- };
417
- 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)) {
418
- job.status = "cancelled";
419
- job.workerId = void 0;
420
- job.pauseRequested = void 0;
421
- job.updatedAt = at;
422
- dropped.cancelled += 1;
423
- if (job.target.kind === "function") dropped.functionJobs.push(job.id);
424
- }
425
- return dropped;
426
- }
453
+ cancelWaiting: (query) => cancelWaitingIn(jobs.values(), query, now()),
454
+ resumeWaiting: (query) => resumeWaitingIn(jobs.values(), query, now())
427
455
  };
428
456
  };
429
457
  /** A state with nothing in it. */
@@ -574,6 +602,7 @@ var queueOver = (access) => ({
574
602
  pause: (...args) => access("pause", args),
575
603
  resume: (...args) => access("resume", args),
576
604
  cancelPending: (...args) => access("cancelPending", args),
577
- cancelWaiting: (...args) => access("cancelWaiting", args)
605
+ cancelWaiting: (...args) => access("cancelWaiting", args),
606
+ resumeWaiting: (...args) => access("resumeWaiting", args)
578
607
  });
579
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 };
@@ -1,4 +1,4 @@
1
- import { I as fetchConnectorRecords } from "./module-BejdMWyt.mjs";
1
+ import { I as fetchConnectorRecords } from "./module-Baod2T6h.mjs";
2
2
  import { getSourceName } from "@plitzi/sdk-shared/dataSource/helpers";
3
3
  // src/connectors/projection.ts
4
4
  /**
@@ -0,0 +1,10 @@
1
+ import { JobsDropped, JobsResumed, JobsToDrop, JobsToResume } from '../../types';
2
+ import { Job } from '@plitzi/sdk-shared';
3
+ /**
4
+ * What an operator does to the jobs that have not started, at once — the in-process stores' half of `cancelWaiting` and
5
+ * `resumeWaiting` (`queueRules`), over the jobs those keep and the instant their clock reads.
6
+ */
7
+ /** A job set aside, back in the queue at `at`: one set aside after failing every attempt has them all again. */
8
+ export declare const putBack: (job: Job, at: number) => void;
9
+ export declare const cancelWaitingIn: (jobs: Iterable<Job>, { spaceIds, status, kind, name }: JobsToDrop, at: number) => JobsDropped;
10
+ export declare const resumeWaitingIn: (jobs: Iterable<Job>, { spaceIds, kind, name }: JobsToResume, at: number) => JobsResumed;
@@ -13,4 +13,4 @@ export declare const readsFlags: (document: object) => boolean;
13
13
  * environment and visitor, then the server's own layer and a tester's forced one — the same order a page resolves
14
14
  * them in. A run has no URL, so a rule on the host or the route does not match here.
15
15
  */
16
- export declare const flagsForRun: (config: Pick<ActionsConfig, "lookups" | "flags">, request: Pick<ActionRunRequest, "entry" | "spaceId" | "environment" | "at" | "user" | "forcedFlags">) => Promise<Record<string, boolean>>;
16
+ export declare const flagsForRun: (config: Pick<ActionsConfig, "lookups" | "flags">, request: Pick<ActionRunRequest, "entry" | "spaceId" | "environment" | "at" | "user" | "forcedFlags" | "rolloutBuckets">) => Promise<Record<string, boolean>>;
@@ -1,3 +1,4 @@
1
+ import { ActionKvAdapter } from '../types';
1
2
  import { MemoryReading } from '@plitzi/sdk-kernel/stats';
2
3
  import { ActionCallResult } from '@plitzi/sdk-shared';
3
4
  /**
@@ -44,16 +45,11 @@ export type ActiveRun = {
44
45
  * The half of a key/value store the guards need, and nothing more.
45
46
  *
46
47
  * The same methods `ActionKvAdapter` already declares, so a deployment that configured `action.kv` has already
47
- * provided this: no second store to stand up, and no adapter change. `increment` is what takes a single-flight
48
- * key; `get`/`set` are what carry a cancellation and a replayable answer between replicas.
48
+ * provided this: no second store to stand up, and no adapter change. `swap` is what takes a single-flight key — written
49
+ * where none is, with its lifetime, at once; `get`/`set` are what carry a cancellation and a replayable answer between
50
+ * replicas.
49
51
  */
50
- export type RunKeyStore = {
51
- get: (key: string) => Promise<string | undefined>;
52
- set: (key: string, value: string, ttlSeconds?: number) => Promise<void>;
53
- increment: (key: string, amount: number) => Promise<number>;
54
- expire: (key: string, ttlSeconds: number) => Promise<void>;
55
- delete: (key: string) => Promise<void>;
56
- };
52
+ export type RunKeyStore = Pick<ActionKvAdapter, 'get' | 'set' | 'swap' | 'delete'>;
57
53
  export type RunGuardsConfig = {
58
54
  /**
59
55
  * Concurrent CALLS one space may have in flight — its fair share of the process: a job worker gives it more of the
@@ -413,6 +413,11 @@ export type ActionRunRequest = {
413
413
  * `flags` say: those are the browser's claim, and a flow does not take a claim as a fact.
414
414
  */
415
415
  forcedFlags?: Record<string, boolean>;
416
+ /**
417
+ * Where the visitor who started the run stands in the space's gradual rollouts — their places, from their cookie — so
418
+ * a flow sees a rolled-out flag as the page that called it was drawn with. None, a rollout's flag answers its own value.
419
+ */
420
+ rolloutBuckets?: Record<string, number>;
416
421
  emit?: (chunk: unknown) => void;
417
422
  /** Reports each step as it settles, for a caller watching the run happen. Absent for a plain request/response. */
418
423
  onNode?: (id: string, status: InteractionNodeStatus) => void;
@@ -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-BejdMWyt.mjs";
2
- import { i as readFunctionsDir, n as loadFunctions, r as loadFunctionsSource } from "../chunks/load-Dhjk46sd.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-Baod2T6h.mjs";
2
+ import { i as readFunctionsDir, n as loadFunctions, r as loadFunctionsSource } from "../chunks/load-tw8iAgZy.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' | 'cancelWaiting'>;
16
+ export type JobControl = Pick<JobQueue, 'pause' | 'resume' | 'cancel' | 'requeue' | 'cancelWaiting' | 'resumeWaiting'>;
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`, `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.
19
+ * queue's own `pause`, `resume`, `cancel`, `requeue`, `cancelWaiting` and `resumeWaiting`, each said on `$job:<id>` when it
20
+ * changed a job 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-BejdMWyt.mjs";
2
- import { n as describeTask, r as createConnectorResolver, t as describeCatalog } from "./chunks/taskCatalog-Crx-1ixP.mjs";
3
- import { n as stateOf, t as documentOf } from "./chunks/queueDocument-wwfFHQvw.mjs";
4
- import { a as emptyState, i as changedBy, l as statusCounts, o as queueOver, r as applyRule, s as queueRules } from "./chunks/queueRules-DCW5x5as.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-Baod2T6h.mjs";
2
+ import { n as describeTask, r as createConnectorResolver, t as describeCatalog } from "./chunks/taskCatalog-J9hBMCsz.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";
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,12 +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. */
510
+ /** How many of the jobs moved at once (`cancelWaiting`, `resumeWaiting`) have their watchers told at a time. */
511
511
  var ANNOUNCED_AT_ONCE = 20;
512
512
  /**
513
513
  * An operator's hold on the jobs, from a process that serves no pages — a deployment's API behind its Queue panel: the
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
+ * queue's own `pause`, `resume`, `cancel`, `requeue`, `cancelWaiting` and `resumeWaiting`, each said on `$job:<id>` when it
515
+ * changed a job of the spaces' functions, as the page server says it when its code does the same.
516
516
  */
517
517
  var createJobControl = ({ queue, realtime }) => {
518
518
  const said = realtime ? {
@@ -537,6 +537,9 @@ var createJobControl = ({ queue, realtime }) => {
537
537
  if (changed) await announce(spaceIds, jobId);
538
538
  return changed;
539
539
  };
540
+ const announceAll = async (spaceIds, jobIds) => {
541
+ for (let from = 0; from < jobIds.length; from += ANNOUNCED_AT_ONCE) await Promise.all(jobIds.slice(from, from + ANNOUNCED_AT_ONCE).map((jobId) => announce(spaceIds, jobId)));
542
+ };
540
543
  return {
541
544
  pause: told((spaceIds, jobId) => queue.pause(spaceIds, jobId)),
542
545
  resume: told((spaceIds, jobId) => queue.resume(spaceIds, jobId)),
@@ -544,8 +547,13 @@ var createJobControl = ({ queue, realtime }) => {
544
547
  requeue: told((spaceIds, jobId, options) => queue.requeue(spaceIds, jobId, options)),
545
548
  cancelWaiting: async (query) => {
546
549
  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)));
550
+ await announceAll(query.spaceIds, dropped.functionJobs);
548
551
  return dropped;
552
+ },
553
+ resumeWaiting: async (query) => {
554
+ const resumed = await queue.resumeWaiting(query);
555
+ await announceAll(query.spaceIds, resumed.functionJobs);
556
+ return resumed;
549
557
  }
550
558
  };
551
559
  };
@@ -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-DCW5x5as.mjs";
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";
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
@@ -113,6 +113,38 @@ var listJobGroupsOf = async (jobs, query) => {
113
113
  jobs: total?.jobs ?? 0
114
114
  };
115
115
  };
116
+ // src/mongo/resumeWaiting.ts
117
+ /**
118
+ * A job set aside, back in the queue at `at` (`resume`, `resumeWaiting`): one set aside after failing every attempt has
119
+ * them all again.
120
+ */
121
+ var putBack = (at) => [{ $set: {
122
+ status: "pending",
123
+ runAt: at,
124
+ updatedAt: at,
125
+ attempts: { $cond: [
126
+ { $gte: ["$attempts", "$maxAttempts"] },
127
+ 0,
128
+ "$attempts"
129
+ ] }
130
+ } }];
131
+ /** `JobQueue.resumeWaiting` over the jobs' collection: every job of these spaces set aside, back in one statement. */
132
+ var resumeWaiting = async (jobs, { spaceIds, kind, name }, at) => {
133
+ const filter = {
134
+ spaceId: { $in: spaceIds },
135
+ status: "paused",
136
+ ...name ? { "target.name": name } : {},
137
+ ...kind ? { "target.kind": kind } : {}
138
+ };
139
+ const watched = kind === "action" ? [] : await jobs.find({
140
+ ...filter,
141
+ "target.kind": "function"
142
+ }, { projection: { _id: 1 } }).toArray();
143
+ return {
144
+ resumed: (await jobs.updateMany(filter, putBack(at))).modifiedCount,
145
+ functionJobs: watched.map((job) => job._id)
146
+ };
147
+ };
116
148
  // src/mongo/jobQueue.ts
117
149
  /** Mongo's code for a unique index that refused a second document with the same key. */
118
150
  var DUPLICATE_KEY$1 = 11e3;
@@ -715,16 +747,7 @@ var createMongoJobQueue = ({ db, collections: names = {}, retentionDays = 90 })
715
747
  _id: jobId,
716
748
  spaceId: { $in: spaceIds },
717
749
  status: "paused"
718
- }, [{ $set: {
719
- status: "pending",
720
- runAt: at,
721
- updatedAt: at,
722
- attempts: { $cond: [
723
- { $gte: ["$attempts", "$maxAttempts"] },
724
- 0,
725
- "$attempts"
726
- ] }
727
- } }])).matchedCount === 1;
750
+ }, putBack(at))).matchedCount === 1;
728
751
  },
729
752
  cancelPending: async ({ spaceId, key, olderThan }) => {
730
753
  const { jobs } = await collections();
@@ -751,6 +774,10 @@ var createMongoJobQueue = ({ db, collections: names = {}, retentionDays = 90 })
751
774
  const { jobs } = await collections();
752
775
  const at = await clock.now();
753
776
  return dropWaiting(jobs, query, at, expiryOf(at));
777
+ },
778
+ resumeWaiting: async (query) => {
779
+ const { jobs } = await collections();
780
+ return resumeWaiting(jobs, query, await clock.now());
754
781
  }
755
782
  };
756
783
  };
@@ -0,0 +1,10 @@
1
+ import { JobDocument } from './jobQueue';
2
+ import { JobsResumed, JobsToResume } from '../types';
3
+ import { Collection, Document } from 'mongodb';
4
+ /**
5
+ * A job set aside, back in the queue at `at` (`resume`, `resumeWaiting`): one set aside after failing every attempt has
6
+ * them all again.
7
+ */
8
+ export declare const putBack: (at: number) => Document[];
9
+ /** `JobQueue.resumeWaiting` over the jobs' collection: every job of these spaces set aside, back in one statement. */
10
+ export declare const resumeWaiting: (jobs: Collection<JobDocument>, { spaceIds, kind, name }: JobsToResume, at: number) => Promise<JobsResumed>;
@@ -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-DCW5x5as.mjs";
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";
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";
@@ -165,6 +165,38 @@ var listJobGroupsOf = async (conn, table, query) => {
165
165
  jobs: Number(count?.jobs ?? 0)
166
166
  };
167
167
  };
168
+ // src/mysql/resumeWaiting.ts
169
+ /**
170
+ * A job set aside, back in the queue at the instant of the statement's first two parameters (`resume`,
171
+ * `resumeWaiting`): one set aside after failing every attempt has them all again.
172
+ */
173
+ var PUT_BACK = "status = 'pending', run_at = ?, updated_at = ?, attempts = IF(attempts >= max_attempts, 0, attempts)";
174
+ /**
175
+ * `JobQueue.resumeWaiting` over the jobs table: every job of these spaces set aside, back in one statement. A query
176
+ * naming no space is answered empty by the caller (`IN ()` is not SQL).
177
+ */
178
+ var resumeWaitingOf = async (conn, table, { spaceIds, kind, name }, at) => {
179
+ const where = [
180
+ "space_id IN (?)",
181
+ "status = 'paused'",
182
+ ...name ? ["target_name = ?"] : [],
183
+ ...kind ? ["target_kind = ?"] : []
184
+ ].join(" AND ");
185
+ const params = [
186
+ spaceIds,
187
+ ...name ? [name] : [],
188
+ ...kind ? [kind] : []
189
+ ];
190
+ const watched = kind === "action" ? [] : await selectRows(conn, `SELECT id FROM ${table} WHERE ${where} AND target_kind = 'function'`, params);
191
+ return {
192
+ resumed: (await execute(conn, `UPDATE ${table} SET ${PUT_BACK} WHERE ${where}`, [
193
+ at,
194
+ at,
195
+ ...params
196
+ ])).affectedRows,
197
+ functionJobs: watched.map((row) => row.id)
198
+ };
199
+ };
168
200
  // src/mysql/schema.ts
169
201
  var PREFIX = /^[A-Za-z0-9_]*$/;
170
202
  /**
@@ -758,9 +790,7 @@ var createMysqlJobQueue = ({ pool, tablePrefix = "", createTables = true, retent
758
790
  if (!inSpaces(spaceIds)) return false;
759
791
  const conn = await db();
760
792
  const at = await clock.now();
761
- return (await execute(conn, `UPDATE ${t.jobs} SET status = 'pending', run_at = ?, updated_at = ?,
762
- attempts = IF(attempts >= max_attempts, 0, attempts)
763
- WHERE id = ? AND space_id IN (?) AND status = 'paused'`, [
793
+ return (await execute(conn, `UPDATE ${t.jobs} SET ${PUT_BACK} WHERE id = ? AND space_id IN (?) AND status = 'paused'`, [
764
794
  at,
765
795
  at,
766
796
  jobId,
@@ -813,6 +843,10 @@ var createMysqlJobQueue = ({ pool, tablePrefix = "", createTables = true, retent
813
843
  ])).affectedRows,
814
844
  functionJobs: watched.map((job) => job.id)
815
845
  };
846
+ },
847
+ resumeWaiting: async (query) => inSpaces(query.spaceIds) ? resumeWaitingOf(await db(), t.jobs, query, await clock.now()) : {
848
+ resumed: 0,
849
+ functionJobs: []
816
850
  }
817
851
  };
818
852
  };
@@ -0,0 +1,12 @@
1
+ import { JobsResumed, JobsToResume } from '../types';
2
+ import { Pool } from 'mysql2/promise';
3
+ /**
4
+ * A job set aside, back in the queue at the instant of the statement's first two parameters (`resume`,
5
+ * `resumeWaiting`): one set aside after failing every attempt has them all again.
6
+ */
7
+ export declare const PUT_BACK = "status = 'pending', run_at = ?, updated_at = ?, attempts = IF(attempts >= max_attempts, 0, attempts)";
8
+ /**
9
+ * `JobQueue.resumeWaiting` over the jobs table: every job of these spaces set aside, back in one statement. A query
10
+ * naming no space is answered empty by the caller (`IN ()` is not SQL).
11
+ */
12
+ export declare const resumeWaitingOf: (conn: Pool, table: string, { spaceIds, kind, name }: JobsToResume, at: number) => Promise<JobsResumed>;
@@ -1,5 +1,5 @@
1
- import { n as stateOf, t as documentOf } from "../chunks/queueDocument-wwfFHQvw.mjs";
2
- import { a as emptyState, i as changedBy, o as queueOver, r as applyRule, s as queueRules } from "../chunks/queueRules-DCW5x5as.mjs";
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";
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
5
5
  import { DatabaseSync } from "node:sqlite";
@@ -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, JobGroup, JobQueueSummary, JobSettlement, JobsDropped, JobsNeedingMemory, JobsToDrop, JobSpaces, JobStop, JobTake, JobWake, JobWrite, WaitingJobs } from './jobs';
2
+ export type { ActionSchedule, ActionScheduleInput, JobClaimMemory, JobQuery, JobQueue, JobFlowMinute, JobGroup, JobQueueSummary, JobSettlement, JobsDropped, JobsResumed, JobsNeedingMemory, JobsToDrop, JobsToResume, JobSpaces, JobStop, JobTake, JobWake, JobWrite, WaitingJobs } from './jobs';
@@ -173,6 +173,17 @@ export type JobsToDrop = {
173
173
  /** Only what runs this action, or this job (`target.name`). */
174
174
  name?: string;
175
175
  };
176
+ /**
177
+ * Which jobs set aside an operator puts back in the queue at once (`JobQueue.resumeWaiting`): every `paused` job of these
178
+ * spaces, narrowed like a list of them is — what one group of `listJobGroups` holds, when set aside.
179
+ */
180
+ export type JobsToResume = Omit<JobsToDrop, 'status'>;
181
+ /** What `JobQueue.resumeWaiting` put back. */
182
+ export type JobsResumed = {
183
+ resumed: number;
184
+ /** The jobs of the spaces' functions among them: the ones somebody may be watching, for whoever tells them. */
185
+ functionJobs: string[];
186
+ };
176
187
  /** What `JobQueue.cancelWaiting` dropped. */
177
188
  export type JobsDropped = {
178
189
  cancelled: number;
@@ -379,4 +390,10 @@ export type JobQueue = {
379
390
  * holding it can stop it.
380
391
  */
381
392
  cancelWaiting: (query: JobsToDrop) => Promise<JobsDropped>;
393
+ /**
394
+ * Puts every job of these spaces set aside (`paused`) back in the queue at once, as `resume` puts one — each set aside
395
+ * after failing every attempt with every attempt again. What a group of a schedule's runs set aside asks of an
396
+ * operator once its cause is fixed, rather than a press a job.
397
+ */
398
+ resumeWaiting: (query: JobsToResume) => Promise<JobsResumed>;
382
399
  };
@@ -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-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-BejdMWyt.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-Baod2T6h.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-Crx-1ixP.mjs";
6
- import { t as isFunctionsDefinition } from "../chunks/load-Dhjk46sd.mjs";
5
+ import { r as createConnectorResolver, t as describeCatalog } from "../chunks/taskCatalog-J9hBMCsz.mjs";
6
+ import { t as isFunctionsDefinition } from "../chunks/load-tw8iAgZy.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";
@@ -13,7 +13,7 @@ import { configureServerLog, defaultLogLevel, serverLog } from "@plitzi/sdk-kern
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";
16
- import { forcedFlagsFor } from "@plitzi/sdk-shared/flags";
16
+ import { forcedFlagsFor, keptRollout } from "@plitzi/sdk-shared/flags";
17
17
  import { resolveDebugAuthorization } from "@plitzi/sdk-kernel/identity";
18
18
  import { request } from "node:http";
19
19
  // src/engine/transport/stream.ts
@@ -328,6 +328,7 @@ var handleActionCall = async (deps) => {
328
328
  revision
329
329
  },
330
330
  ...forcedFlags ? { forcedFlags } : {},
331
+ rolloutBuckets: keptRollout(req.headers.cookie, requestAuthority(req)),
331
332
  signal: run.controller.signal,
332
333
  ...stream ? {
333
334
  emit: (chunk) => stream.send({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plitzi/sdk-actions",
3
- "version": "0.39.11",
3
+ "version": "0.39.13",
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.11",
41
- "@plitzi/sdk-shared": "0.39.11",
40
+ "@plitzi/sdk-kernel": "0.39.13",
41
+ "@plitzi/sdk-shared": "0.39.13",
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.11",
62
+ "@plitzi/sdk-runtime": "0.39.13",
63
63
  "@types/node": "^26.6.6",
64
64
  "@types/nodemailer": "^8.0.2",
65
65
  "@types/ws": "^8.18.2",