@plitzi/sdk-actions 0.0.0-stage → 0.39.2
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 +11 -0
- package/README.md +54 -2
- package/dist/chunks/credentials-DwxZeAvH.mjs +27 -0
- package/dist/chunks/errors-bCBfIe7c.mjs +54 -0
- package/dist/chunks/grants-BsD-WlLE.mjs +168 -0
- package/dist/chunks/load-DBWRZn7G.mjs +48 -0
- package/dist/chunks/module-WdDzbjHy.mjs +7032 -0
- package/dist/chunks/queueDocument-xYz-KZ5V.mjs +21 -0
- package/dist/chunks/queueRules-BCCVgeUE.mjs +487 -0
- package/dist/chunks/remote-DopPgCMK.mjs +404 -0
- package/dist/chunks/storeClock-Btm7EaVm.mjs +31 -0
- package/dist/chunks/taskCatalog-S1IozUTD.mjs +201 -0
- package/dist/connectors/connectors.d.ts +7 -0
- package/dist/connectors/engine.d.ts +47 -0
- package/dist/connectors/getByPath.d.ts +8 -0
- package/dist/connectors/projection.d.ts +18 -0
- package/dist/connectors/resolver.d.ts +27 -0
- package/dist/connectors/types.d.ts +19 -0
- package/dist/engine/configSeam.d.ts +10 -0
- package/dist/engine/connectorWrite.d.ts +12 -0
- package/dist/engine/fileStore.d.ts +60 -0
- package/dist/engine/fleet.d.ts +20 -0
- package/dist/engine/jobs/calls.d.ts +49 -0
- package/dist/engine/jobs/claimSpaces.d.ts +10 -0
- package/dist/engine/jobs/codeMarks.d.ts +10 -0
- package/dist/engine/jobs/endings.d.ts +42 -0
- package/dist/engine/jobs/failureStreak.d.ts +15 -0
- package/dist/engine/jobs/fileQueue.d.ts +34 -0
- package/dist/engine/jobs/flow.d.ts +11 -0
- package/dist/engine/jobs/jobs.d.ts +36 -0
- package/dist/engine/jobs/later.d.ts +27 -0
- package/dist/engine/jobs/memoryNeeds.d.ts +24 -0
- package/dist/engine/jobs/memoryQueue.d.ts +33 -0
- package/dist/engine/jobs/memoryWatch.d.ts +21 -0
- package/dist/engine/jobs/notNow.d.ts +39 -0
- package/dist/engine/jobs/queueDocument.d.ts +15 -0
- package/dist/engine/jobs/queueRules.d.ts +64 -0
- package/dist/engine/jobs/scheduler.d.ts +70 -0
- package/dist/engine/jobs/schedules.d.ts +24 -0
- package/dist/engine/jobs/storeClock.d.ts +16 -0
- package/dist/engine/jobs/wake.d.ts +6 -0
- package/dist/engine/jobs/worker.d.ts +99 -0
- package/dist/engine/module.d.ts +96 -0
- package/dist/engine/moduleFor.d.ts +3 -0
- package/dist/engine/runtime/check.d.ts +24 -0
- package/dist/engine/runtime/credentials.d.ts +8 -0
- package/dist/engine/runtime/deadline.d.ts +19 -0
- package/dist/engine/runtime/email.d.ts +38 -0
- package/dist/engine/runtime/errors.d.ts +28 -0
- package/dist/engine/runtime/fileKv.d.ts +35 -0
- package/dist/engine/runtime/flags.d.ts +16 -0
- package/dist/engine/runtime/guards.d.ts +190 -0
- package/dist/engine/runtime/kvList.d.ts +28 -0
- package/dist/engine/runtime/kvStore.d.ts +36 -0
- package/dist/engine/runtime/limits.d.ts +12 -0
- package/dist/engine/runtime/memoryKv.d.ts +28 -0
- package/dist/engine/runtime/namespaceKv.d.ts +9 -0
- package/dist/engine/runtime/precheck.d.ts +28 -0
- package/dist/engine/runtime/rateLimit.d.ts +9 -0
- package/dist/engine/runtime/redisKv.d.ts +27 -0
- package/dist/engine/runtime/renderFailure.d.ts +24 -0
- package/dist/engine/runtime/renderResolver.d.ts +16 -0
- package/dist/engine/runtime/renderShare.d.ts +12 -0
- package/dist/engine/runtime/report.d.ts +15 -0
- package/dist/engine/runtime/runAction.d.ts +26 -0
- package/dist/engine/runtime/runLogger.d.ts +37 -0
- package/dist/engine/runtime/runStats.d.ts +8 -0
- package/dist/engine/runtime/scope.d.ts +40 -0
- package/dist/engine/runtime/signing.d.ts +27 -0
- package/dist/engine/runtime/taskContext.d.ts +54 -0
- package/dist/engine/runtime/triggers.d.ts +12 -0
- package/dist/engine/taskCatalog.d.ts +28 -0
- package/dist/engine/tasks/auth.d.ts +2 -0
- package/dist/engine/tasks/builtins.d.ts +10 -0
- package/dist/engine/tasks/connector.d.ts +2 -0
- package/dist/engine/tasks/db.d.ts +2 -0
- package/dist/engine/tasks/email.d.ts +2 -0
- package/dist/engine/tasks/flow.d.ts +3 -0
- package/dist/engine/tasks/helpers.d.ts +16 -0
- package/dist/engine/tasks/http.d.ts +2 -0
- package/dist/engine/tasks/kv.d.ts +2 -0
- package/dist/engine/tasks/list.d.ts +2 -0
- package/dist/engine/tasks/names.d.ts +8 -0
- package/dist/engine/tasks/realtime.d.ts +3 -0
- package/dist/engine/tasks/registry.d.ts +19 -0
- package/dist/engine/tasks/transform.d.ts +2 -0
- package/dist/engine/transport/callHandler.d.ts +34 -0
- package/dist/engine/transport/cancelHandler.d.ts +23 -0
- package/dist/engine/transport/catalogHandler.d.ts +22 -0
- package/dist/engine/transport/stream.d.ts +22 -0
- package/dist/engine/transport/verifySignature.d.ts +16 -0
- package/dist/engine/transport/webhookHandler.d.ts +26 -0
- package/dist/engine/types.d.ts +442 -0
- package/dist/functions/build.d.ts +27 -0
- package/dist/functions/capabilities.d.ts +11 -0
- package/dist/functions/config.d.ts +111 -0
- package/dist/functions/context.d.ts +15 -0
- package/dist/functions/index.d.ts +17 -0
- package/dist/functions/index.mjs +461 -0
- package/dist/functions/jobControl.d.ts +22 -0
- package/dist/functions/jobs.d.ts +104 -0
- package/dist/functions/load.d.ts +22 -0
- package/dist/functions/local.d.ts +36 -0
- package/dist/functions/manifest.d.ts +32 -0
- package/dist/functions/native.d.ts +13 -0
- package/dist/functions/oauth.d.ts +33 -0
- package/dist/functions/routes.d.ts +50 -0
- package/dist/functions/runner/remote.d.ts +26 -0
- package/dist/functions/scope.d.ts +28 -0
- package/dist/functions/space.d.ts +41 -0
- package/dist/functions/tryEntry.d.ts +9 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.mjs +545 -0
- package/dist/mongo/claimable.d.ts +5 -0
- package/dist/mongo/index.d.ts +4 -0
- package/dist/mongo/index.mjs +779 -0
- package/dist/mongo/jobQueue.d.ts +38 -0
- package/dist/mongo/kv.d.ts +15 -0
- package/dist/mysql/index.d.ts +5 -0
- package/dist/mysql/index.mjs +808 -0
- package/dist/mysql/jobQueue.d.ts +40 -0
- package/dist/mysql/kv.d.ts +18 -0
- package/dist/mysql/rows.d.ts +64 -0
- package/dist/mysql/schema.d.ts +28 -0
- package/dist/mysql/summary.d.ts +7 -0
- package/dist/realtime/declarations.d.ts +11 -0
- package/dist/realtime/failure.d.ts +6 -0
- package/dist/realtime/grants.d.ts +22 -0
- package/dist/realtime/handlers.d.ts +86 -0
- package/dist/realtime/hub.d.ts +71 -0
- package/dist/realtime/index.d.ts +105 -0
- package/dist/realtime/index.mjs +824 -0
- package/dist/realtime/jobs.d.ts +18 -0
- package/dist/realtime/message.d.ts +3 -0
- package/dist/realtime/presence.d.ts +33 -0
- package/dist/realtime/retained.d.ts +21 -0
- package/dist/realtime/socket.d.ts +30 -0
- package/dist/render/index.d.ts +10 -0
- package/dist/render/index.mjs +1 -0
- package/dist/render/protocol.d.ts +47 -0
- package/dist/render/remote.d.ts +16 -0
- package/dist/runtimes/bundle.d.ts +29 -0
- package/dist/runtimes/index.d.ts +3 -0
- package/dist/runtimes/index.mjs +229 -0
- package/dist/runtimes/stages.d.ts +52 -0
- package/dist/sqlite/index.d.ts +4 -0
- package/dist/sqlite/index.mjs +160 -0
- package/dist/sqlite/jobQueue.d.ts +35 -0
- package/dist/sqlite/kv.d.ts +34 -0
- package/dist/sqlite/open.d.ts +3 -0
- package/dist/types/config.d.ts +293 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/jobs.d.ts +317 -0
- package/dist/worker/elsewhere.d.ts +16 -0
- package/dist/worker/index.d.ts +5 -0
- package/dist/worker/index.mjs +1703 -0
- package/dist/worker/origin.d.ts +12 -0
- package/dist/worker/pageEngine.d.ts +11 -0
- package/dist/worker/stages/action.d.ts +24 -0
- package/dist/worker/stages/cors.d.ts +9 -0
- package/dist/worker/stages/forward.d.ts +12 -0
- package/dist/worker/stages/functionRoutes.d.ts +10 -0
- package/dist/worker/stages/queuedCalls.d.ts +15 -0
- package/dist/worker/stages/realtime.d.ts +9 -0
- package/dist/worker/stages/render.d.ts +9 -0
- package/dist/worker/worker.d.ts +39 -0
- package/package.json +76 -3
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads a dot path out of an arbitrary JSON response (`data.items`, `meta.pagination.total`). Kept local and
|
|
3
|
+
* dependency-free on purpose: the equivalent helper in plitzi-ui would drag the UI bundle into the request path.
|
|
4
|
+
*
|
|
5
|
+
* A path of `.` or an empty path returns the value itself, which is how a manifest says "the response *is* the
|
|
6
|
+
* array" or "the record *is* its own values".
|
|
7
|
+
*/
|
|
8
|
+
export declare const getByPath: (source: unknown, path?: string) => unknown;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Element } from '@plitzi/sdk-shared';
|
|
2
|
+
/**
|
|
3
|
+
* Collects the paths a page actually reads out of one provider source.
|
|
4
|
+
*
|
|
5
|
+
* Bindings declare `<source>.<path>` directly; transformer params, `when` rules and attribute templates can carry
|
|
6
|
+
* the same reference inside a twig token, so both are scanned. Returning an empty set means nothing statically
|
|
7
|
+
* references the source — the caller must then keep the slice whole rather than serve an empty one.
|
|
8
|
+
*/
|
|
9
|
+
export declare const collectBoundPaths: (flat: Record<string, Element>, rootId: string, sourceName: string) => string[];
|
|
10
|
+
/**
|
|
11
|
+
* Narrows a provider slice to what the page reads.
|
|
12
|
+
*
|
|
13
|
+
* A CMS entry routinely carries fields nobody bound — author emails, internal notes, unpublished translations.
|
|
14
|
+
* Those would otherwise land in the client store and in the HTML, so anything unreferenced is dropped here. With no
|
|
15
|
+
* declared paths the slice passes through untouched: an empty projection would blank the page, and shipping too
|
|
16
|
+
* much is a smaller failure than rendering nothing.
|
|
17
|
+
*/
|
|
18
|
+
export declare const projectSlice: (slice: unknown, paths: string[]) => unknown;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ConnectorCredential, ConnectorManifest } from './types';
|
|
2
|
+
import { RscElementResolver } from '@plitzi/sdk-kernel/engine';
|
|
3
|
+
import { OutboundOptions } from '@plitzi/sdk-kernel/outbound';
|
|
4
|
+
import { SpaceRevision } from '@plitzi/sdk-shared';
|
|
5
|
+
export type ConnectorLookups = {
|
|
6
|
+
/**
|
|
7
|
+
* Reads a manifest by id, as of a published revision. Server-side state: manifests name endpoints and must never
|
|
8
|
+
* reach the browser.
|
|
9
|
+
*
|
|
10
|
+
* `at` absent means the live document, the one the builder edits. A page passes the revision it was published
|
|
11
|
+
* at, so it reads through the manifest it shipped with rather than whatever it says after somebody points that
|
|
12
|
+
* connector at a different API.
|
|
13
|
+
*/
|
|
14
|
+
getConnector: (spaceId: number, connectorId: string, at?: SpaceRevision) => Promise<ConnectorManifest | undefined>;
|
|
15
|
+
/** Resolves the secret referenced by `manifest.credential`. */
|
|
16
|
+
getCredential?: (spaceId: number, identifier: string) => Promise<ConnectorCredential | undefined>;
|
|
17
|
+
fetchImpl?: typeof fetch;
|
|
18
|
+
};
|
|
19
|
+
export type ProviderPagination = 'none' | 'url' | 'append';
|
|
20
|
+
/**
|
|
21
|
+
* Bridges the connector engine into the RSC pipeline: reads the provider element's own configuration, resolves its
|
|
22
|
+
* manifest and credential server-side, and returns the slice the element will publish as a binding source.
|
|
23
|
+
*
|
|
24
|
+
* An element without a connector resolves to nothing rather than failing — an unconfigured provider on a page is a
|
|
25
|
+
* draft, not an error.
|
|
26
|
+
*/
|
|
27
|
+
export declare const createConnectorResolver: ({ getConnector, getCredential, fetchImpl }: ConnectorLookups, outbound?: OutboundOptions) => RscElementResolver;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ConnectorRecord, PageInfo } from '@plitzi/sdk-shared';
|
|
2
|
+
/**
|
|
3
|
+
* The manifest vocabulary lives in `@plitzi/sdk-shared` because the builder authors the document the engine
|
|
4
|
+
* executes. Only the result shapes below are server-side: nothing outside this process ever sees them.
|
|
5
|
+
*/
|
|
6
|
+
export type { ConnectorAuth, ConnectorCredential, ConnectorEndpoints, ConnectorFilter, ConnectorManifest, ConnectorManifestDraft, ConnectorPagination, ConnectorQuery, ConnectorReadEndpoint, ConnectorRecord, ConnectorResponseMapping, ConnectorWriteEndpoint } from '@plitzi/sdk-shared';
|
|
7
|
+
/**
|
|
8
|
+
* `PageInfo` is the cursor-shaped connection contract shared with GraphQL. A pager cannot be rendered from cursors
|
|
9
|
+
* alone, so a connector result also carries the ordinal window it just read.
|
|
10
|
+
*/
|
|
11
|
+
export type ConnectorPageInfo = PageInfo & {
|
|
12
|
+
page: number;
|
|
13
|
+
/** Total pages when the provider reports a total; `0` when it does not and paging relies on page size. */
|
|
14
|
+
pageCount: number;
|
|
15
|
+
};
|
|
16
|
+
export type ConnectorResult = {
|
|
17
|
+
records: ConnectorRecord[];
|
|
18
|
+
pageInfo: ConnectorPageInfo;
|
|
19
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ActionDbDriver, ActionLookups, ActionsConfig } from './types';
|
|
2
|
+
import { ConnectorLookups } from '../connectors/resolver';
|
|
3
|
+
import { ActionLookupsConfig, ConnectorLookupsConfig } from '../types';
|
|
4
|
+
/** The connector lookups a deployment configured, each manifest checked as it is read. One per config object. */
|
|
5
|
+
export declare const connectorLookupsOf: (config: ConnectorLookupsConfig) => ConnectorLookups;
|
|
6
|
+
export declare const actionLookupsOf: (config: ActionLookupsConfig) => ActionLookups;
|
|
7
|
+
/** The deployment's database drivers, each held to what a `db` task calls — or why one is not, as the server starts. */
|
|
8
|
+
export declare const dbDriversOf: (drivers: readonly unknown[] | undefined) => ActionDbDriver[] | undefined;
|
|
9
|
+
/** The deployment's functions config, held to what runs a space's code — or why it is not, as the server starts. */
|
|
10
|
+
export declare const functionsConfigOf: (config: unknown) => ActionsConfig["functions"];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ConnectorLookups } from '../connectors/resolver';
|
|
2
|
+
import { EngineServerConfig } from '../types';
|
|
3
|
+
import { SSRRequest, SSRResponseHelpers } from '@plitzi/sdk-kernel/types';
|
|
4
|
+
/**
|
|
5
|
+
* Handles POST /_action — the write counterpart of the RSC read endpoint.
|
|
6
|
+
*
|
|
7
|
+
* The browser names an **element**, never a connector or a URL. The element must exist in the published schema,
|
|
8
|
+
* be server-driven and declare a connector, and the connector must declare the action. That chain is what stops
|
|
9
|
+
* the endpoint from being a general-purpose proxy into the customer's backend: nothing reachable here is
|
|
10
|
+
* reachable that the page itself does not already do.
|
|
11
|
+
*/
|
|
12
|
+
export declare const handleAction: (req: SSRRequest, res: SSRResponseHelpers, config: EngineServerConfig, lookups: ConnectorLookups) => Promise<void>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a store kept in one JSON file needs beside its own rules: the file held by one process, and its document written
|
|
3
|
+
* whole after each change. `createFileKv` and `createFileJobQueue` keep theirs this way.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Who holds a file: written beside it (`<file>.lock`) while a process has it — and, for a server, the address it
|
|
7
|
+
* answers at (`serves`), which a second one started beside it is pointed to.
|
|
8
|
+
*/
|
|
9
|
+
export type FileHolder = {
|
|
10
|
+
pid: number;
|
|
11
|
+
since: string;
|
|
12
|
+
owner?: string;
|
|
13
|
+
serves?: string;
|
|
14
|
+
};
|
|
15
|
+
/** What a process says of itself as it takes a file: who it is, and where it answers. */
|
|
16
|
+
export type HolderOf = {
|
|
17
|
+
owner?: string;
|
|
18
|
+
serves?: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* A file another running process holds: its message is the whole report — who holds it and how to stop it — said as it
|
|
22
|
+
* is when the server starts (`serveProject`). Thrown plain, it was a stack ending on its cause's `EEXIST`, and the agent
|
|
23
|
+
* reading the end of it found no word of what to do.
|
|
24
|
+
*/
|
|
25
|
+
export declare class FileInUseError extends Error {
|
|
26
|
+
/** The process that holds it: a server says where it answers, for the one refused to point there. */
|
|
27
|
+
readonly holder: FileHolder;
|
|
28
|
+
constructor(message: string, holder: FileHolder, options?: ErrorOptions);
|
|
29
|
+
}
|
|
30
|
+
/** Lets go of a file this process holds. */
|
|
31
|
+
export declare const letGo: (lock: string) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Takes the file for this process, or says who has it — `store` names the store in what is said (`createFileKv`).
|
|
34
|
+
*
|
|
35
|
+
* Two processes on one file each load it and then write their whole document over it: every change one makes, the
|
|
36
|
+
* other erases with its next write, and nothing anywhere says so — a second server started beside the first, a
|
|
37
|
+
* `--watch` left running after a restart. So a file has one holder: a second is refused, naming the first. A lock whose
|
|
38
|
+
* process is gone — killed, crashed — is taken over.
|
|
39
|
+
*/
|
|
40
|
+
export declare const holdFile: (file: string, { owner, serves }: HolderOf, store: string) => string;
|
|
41
|
+
export type DocumentWriter = {
|
|
42
|
+
/** Says the document changed: it is written as soon as the write under way, if any, is done. */
|
|
43
|
+
changed: () => void;
|
|
44
|
+
/** Resolves once everything changed so far is on disk; rejects when it could not be written. */
|
|
45
|
+
flush: () => Promise<void>;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Writes `document()` to `file` whole after each change, through a temporary file renamed over the old one — changes
|
|
49
|
+
* that arrive while a write is under way are written together right after it, so a crash loses at most the changes of
|
|
50
|
+
* that instant and never leaves half a file. A write that failed is said in the log and tried again by the next change
|
|
51
|
+
* or `flush`, never in a loop against a disk that keeps refusing.
|
|
52
|
+
*/
|
|
53
|
+
export declare const documentWriter: ({ file, document, store, what }: {
|
|
54
|
+
file: string;
|
|
55
|
+
document: () => string;
|
|
56
|
+
/** The store, as an error names it: `createFileKv`. */
|
|
57
|
+
store: string;
|
|
58
|
+
/** What the file is, as the log says it: `kv file`. */
|
|
59
|
+
what: string;
|
|
60
|
+
}) => DocumentWriter;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ActionKvAdapter } from './types';
|
|
2
|
+
import { JobQueue } from '../types';
|
|
3
|
+
import { FleetStores } from '@plitzi/sdk-kernel/http';
|
|
4
|
+
/**
|
|
5
|
+
* A `kv` the deployment makes — a file — opened by ONE process of a fleet and reached by the rest: made in the primary
|
|
6
|
+
* (or the single process there is), and in a worker the primary's, over the channel. Made in every worker instead,
|
|
7
|
+
* each would hold its own copy of the file and write it over the others'.
|
|
8
|
+
*/
|
|
9
|
+
export declare const fleetKv: (make: () => ActionKvAdapter) => ActionKvAdapter;
|
|
10
|
+
/**
|
|
11
|
+
* The job queue of a server — ONE for the primary and its workers, as `fleetKv` is: made in the primary (or the single
|
|
12
|
+
* process there is), and in a worker the primary's, over the channel. The primary's jobs made apart from what it offered
|
|
13
|
+
* its workers would be two queues: a worker's `ctx.later` waiting where nobody claims.
|
|
14
|
+
*/
|
|
15
|
+
export declare const fleetJobQueue: (make: () => JobQueue) => JobQueue;
|
|
16
|
+
/**
|
|
17
|
+
* What the primary keeps for its workers of the actions' and the realtime's: the same in-memory defaults a single server
|
|
18
|
+
* makes for itself, made once — when a worker first asks — so the fleet has one of each rather than one per worker.
|
|
19
|
+
*/
|
|
20
|
+
export declare const ACTIONS_FLEET_STORES: FleetStores;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { JobQueue } from '../../types/jobs';
|
|
2
|
+
import { Environment, QueuedCallStatus, RunUser, SpaceRevision } from '@plitzi/sdk-shared';
|
|
3
|
+
/**
|
|
4
|
+
* A visitor's call kept in the queue because nothing could run it then — no worker answered the page, or no runner its
|
|
5
|
+
* code — to run, as theirs, as soon as something can. Only a call that never started is kept: one that started and
|
|
6
|
+
* lost its runner half-way answers as it always did, so nothing it did runs twice.
|
|
7
|
+
*/
|
|
8
|
+
export type CallToKeep = {
|
|
9
|
+
spaceId: number;
|
|
10
|
+
environment: Environment;
|
|
11
|
+
actionId: string;
|
|
12
|
+
input: Record<string, unknown>;
|
|
13
|
+
/** Who made it, as the session said when it was accepted: the run is theirs, with their permissions. */
|
|
14
|
+
user?: RunUser;
|
|
15
|
+
callerId: string;
|
|
16
|
+
idempotencyKey?: string;
|
|
17
|
+
origin?: string;
|
|
18
|
+
at?: SpaceRevision;
|
|
19
|
+
};
|
|
20
|
+
/** How many calls one space may have waiting: past it, a call is refused, saying so, rather than piled up. */
|
|
21
|
+
export declare const KEPT_CALLS_PER_SPACE = 500;
|
|
22
|
+
/** How long a kept call waits at most: one no worker or runner could run within a day is not run after it. */
|
|
23
|
+
export declare const KEPT_CALL_MS: number;
|
|
24
|
+
/** A user as a job keeps them: what the run reads of them, never the session's token. */
|
|
25
|
+
export declare const runUserOf: (user: RunUser | undefined) => RunUser | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Keeps a call in the queue: answered with its job and the secret its caller reads the answer with, or why it was
|
|
28
|
+
* not kept. A call asked again under the same key is the one already kept — its caller's, never anybody else's.
|
|
29
|
+
*/
|
|
30
|
+
export declare const keepCall: (queue: JobQueue, call: CallToKeep) => Promise<{
|
|
31
|
+
jobId: string;
|
|
32
|
+
ticket: string;
|
|
33
|
+
} | {
|
|
34
|
+
refused: string;
|
|
35
|
+
}>;
|
|
36
|
+
/** What a kept call's run answered, as the job keeps it (`result`). */
|
|
37
|
+
export type KeptCallAnswer = {
|
|
38
|
+
runId: string;
|
|
39
|
+
status: 'completed' | 'failed';
|
|
40
|
+
output: Record<string, unknown>;
|
|
41
|
+
error?: string;
|
|
42
|
+
code?: string;
|
|
43
|
+
reason?: string;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* A kept call as its caller reads it, with the secret it was given: waiting, running, or what it answered. Undefined
|
|
47
|
+
* for a job that is not a kept call or a secret that is not its — the same answer, so neither is told from the other.
|
|
48
|
+
*/
|
|
49
|
+
export declare const readKeptCall: (queue: JobQueue, spaceId: number, jobId: string, ticket: string) => Promise<QueuedCallStatus | undefined>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { JobSpaces } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Which spaces a worker's claim takes, by their share of it (`perSpace`, `room().fullSpaces`): first those not at their
|
|
4
|
+
* share — every space's work gets its share before any gets more — then, in the slots nothing else waits for, those that
|
|
5
|
+
* are.
|
|
6
|
+
*/
|
|
7
|
+
/** `spaces` without those at their ceiling: what a claim takes, so no job is claimed only to be handed back refused. */
|
|
8
|
+
export declare const withoutFull: (spaces: JobSpaces | undefined, full: number[]) => JobSpaces | undefined;
|
|
9
|
+
/** Of the spaces this worker takes, those already at their share (`full`): where its spare slots go. None, none. */
|
|
10
|
+
export declare const onlyFull: (spaces: JobSpaces | undefined, full: number[]) => JobSpaces | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { JobQueue } from '../../types';
|
|
2
|
+
import { ActionLookups } from '../types';
|
|
3
|
+
import { ActionDocument } from '@plitzi/sdk-shared';
|
|
4
|
+
/**
|
|
5
|
+
* The queue, marking each action job it is given whose action runs the space's own code (`target.code`) — read off its
|
|
6
|
+
* document as it is queued, wherever from: a schedule's fire, a run set for later, a call kept for when a runner is
|
|
7
|
+
* back. What lets a worker whose runs wait for a runner with room go on taking the jobs that need none
|
|
8
|
+
* (`claim({ takes: 'light' })`). A mark that misses costs only that: the job waits beside the others, as before.
|
|
9
|
+
*/
|
|
10
|
+
export declare const codeMarkingQueue: (queue: JobQueue, lookups: ActionLookups, runsCode: (document: ActionDocument) => boolean) => JobQueue;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { JobSettlement } from '../../types';
|
|
2
|
+
import { ActionRunResult } from '../types';
|
|
3
|
+
import { ActionRunLimit, Job } from '@plitzi/sdk-shared';
|
|
4
|
+
/** How a job ends badly: given up, set aside at a limit, or out of attempts — and what its line says. */
|
|
5
|
+
/**
|
|
6
|
+
* Why a run that ended badly did, in the words an operator can act on: the step that failed and what it said.
|
|
7
|
+
*
|
|
8
|
+
* Read from `steps` — the outline, whose errors are already redacted of every credential the run resolved — so
|
|
9
|
+
* nothing lands on the job that the run history would not show. A run that failed without any step failing (a
|
|
10
|
+
* timeout between steps, a budget spent) has no step to name, and says how it ended instead.
|
|
11
|
+
*/
|
|
12
|
+
export declare const failureOf: (result: ActionRunResult) => string;
|
|
13
|
+
/**
|
|
14
|
+
* Refusals no number of attempts will change: the action was deleted, its schedule was switched off, or the
|
|
15
|
+
* document refuses this trigger. Retrying is noise, and the job stops where an operator can see why.
|
|
16
|
+
*/
|
|
17
|
+
export declare const GIVE_UP: Set<string>;
|
|
18
|
+
/**
|
|
19
|
+
* The limits the same code meets again on every attempt — what it spends of CPU, memory, calls, output, steps or
|
|
20
|
+
* requests, and its plan's allowance for the period spent (`quota`): a job stopped at one is set aside at once, for its
|
|
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
|
+
* for a minute answers the next attempt.
|
|
23
|
+
*/
|
|
24
|
+
export declare const SET_ASIDE_LIMITS: Set<string>;
|
|
25
|
+
/** Why a job stopped at one of {@link SET_ASIDE_LIMITS} waits for somebody. */
|
|
26
|
+
export declare const limitSetAsideError: (said: string) => string;
|
|
27
|
+
/**
|
|
28
|
+
* Why a job that failed every attempt waits: it is set aside (`paused`) for somebody to read its runs and decide —
|
|
29
|
+
* resume it once fixed, with every attempt again, or cancel it.
|
|
30
|
+
*/
|
|
31
|
+
export declare const failedOutError: (attempts: number, last: string) => string;
|
|
32
|
+
/**
|
|
33
|
+
* A run stopped at a limit is not retried as a failure, whether it was reached as the run went or refused before it
|
|
34
|
+
* started: its account's CPU for the minute is not now — back next minute, its attempt refunded — and a limit its plan
|
|
35
|
+
* sets is reached again on every attempt, so it is set aside at once. Answers whether it was one.
|
|
36
|
+
*/
|
|
37
|
+
export declare const limitEndings: ({ workerId, settle, release, nextMinuteMs }: {
|
|
38
|
+
workerId: string;
|
|
39
|
+
settle: (settlement: JobSettlement) => Promise<void>;
|
|
40
|
+
release: (job: Job, delayMs: number, error: string) => Promise<void>;
|
|
41
|
+
nextMinuteMs: () => Promise<number>;
|
|
42
|
+
}) => (job: Job, runId: string, limit: ActionRunLimit | undefined, said: string) => Promise<boolean>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type FailureStreak = {
|
|
2
|
+
failed: (error: unknown) => void;
|
|
3
|
+
succeeded: () => void;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* How a pass that runs again by itself reports failing: a schedule sweep, a claim, a heartbeat.
|
|
7
|
+
*
|
|
8
|
+
* A store that drops its connections for a moment — a failover, a driver resetting its pool because the host stalled
|
|
9
|
+
* — fails one pass, and the next, seconds later, works. Nothing is lost: every pass is safe to repeat. Reported as an
|
|
10
|
+
* error with a stack, each of those read as an incident, and the ones that are an incident read the same.
|
|
11
|
+
*
|
|
12
|
+
* So the first failure of a streak is a warning with its reason; a streak still going after `escalateAfterMs` is the
|
|
13
|
+
* error, with the whole cause, once; and the pass that ends a streak that got that far says so.
|
|
14
|
+
*/
|
|
15
|
+
export declare const createFailureStreak: (scope: string, what: string, escalateAfterMs?: number, now?: () => number) => FailureStreak;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { JobQueue } from '../../types';
|
|
2
|
+
export type FileJobQueueOptions = {
|
|
3
|
+
/** The JSON file the queue lives in — created, with its folder, on the first change. */
|
|
4
|
+
file: string;
|
|
5
|
+
/** Who holds it, said to a second process that tries: `the server of "acme", on port 8080`. */
|
|
6
|
+
owner?: string;
|
|
7
|
+
/** Where the process that holds it answers, for a second one to be pointed there: `http://localhost:8080`. */
|
|
8
|
+
serves?: string;
|
|
9
|
+
/** How many finished jobs to keep before the oldest are dropped. Default 500. */
|
|
10
|
+
retainFinished?: number;
|
|
11
|
+
/** What the queue calls now, in epoch ms. */
|
|
12
|
+
clock?: () => number;
|
|
13
|
+
};
|
|
14
|
+
export type FileJobQueue = JobQueue & {
|
|
15
|
+
/** Resolves once everything changed so far is on disk: for a shutdown, or a test that reads the file. */
|
|
16
|
+
flush: () => Promise<void>;
|
|
17
|
+
/** Writes what is pending and lets go of the file, for the next process to take. */
|
|
18
|
+
close: () => Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The job queue in one JSON file: what `ctx.later`, a schedule's fires and a function's jobs wait in, surviving a
|
|
22
|
+
* restart — for a deployment with no database. A job due while the server was down runs once it is back; one a worker
|
|
23
|
+
* held when it went down is taken again, its attempt written `lost`.
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* createServer({ action: { jobs: { queue: createFileJobQueue({ file: 'state/jobs.json' }) } } });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* The rules are the in-process queue's, to the letter (`queueRules`): the file is only where its state is kept, written
|
|
30
|
+
* whole after each change that changed something, as `createFileKv` writes its own. ONE process holds the file
|
|
31
|
+
* (`<file>.lock`); the workers of one server reach the primary's through the fleet (`fleetJobQueue`); replicas share
|
|
32
|
+
* `createSqliteJobQueue` (`@plitzi/sdk-actions/sqlite`) or a database's queue.
|
|
33
|
+
*/
|
|
34
|
+
export declare const createFileJobQueue: ({ file, owner, serves, retainFinished, clock }: FileJobQueueOptions) => FileJobQueue;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { JobFlowMinute } from '../../types';
|
|
2
|
+
import { Job } from '@plitzi/sdk-shared';
|
|
3
|
+
/** What `flowOf` reads of a job: when it was due, its attempts, and the one it is running, if any. */
|
|
4
|
+
export type FlowJob = Pick<Job, 'dueAt' | 'history' | 'status' | 'updatedAt' | 'attempts'>;
|
|
5
|
+
/**
|
|
6
|
+
* The queue's flow minute by minute over `[from, to)`, from the jobs that touch it: what fell due in each, what was
|
|
7
|
+
* started and ended, and how long a job waited from due to its first attempt — what tells a queue that keeps up from
|
|
8
|
+
* one that falls behind. A job running now started its attempt when it was claimed (`updatedAt`). Every store reads
|
|
9
|
+
* the jobs it may have to count — due in the span, or written since it began — and hands them here.
|
|
10
|
+
*/
|
|
11
|
+
export declare const flowOf: (jobs: Iterable<FlowJob>, from: number, to: number) => JobFlowMinute[];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Scheduler } from './scheduler';
|
|
2
|
+
import { JobWorker } from './worker';
|
|
3
|
+
import { FunctionJobsService } from '../../functions/jobs';
|
|
4
|
+
import { JobQueue } from '../../types';
|
|
5
|
+
import { ActionsModule } from '../module';
|
|
6
|
+
import { ActionJobsConfig, ActionLookups } from '../types';
|
|
7
|
+
/** Jobs a replica runs at once when its deployment does not say (`jobs.workers`). */
|
|
8
|
+
export declare const DEFAULT_JOB_WORKERS = 4;
|
|
9
|
+
export type ActionJobs = {
|
|
10
|
+
queue: JobQueue;
|
|
11
|
+
scheduler: Scheduler;
|
|
12
|
+
worker: JobWorker;
|
|
13
|
+
start: () => void;
|
|
14
|
+
stop: () => Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The scheduling half of actions: a producer, a consumer and the store they meet in.
|
|
18
|
+
*
|
|
19
|
+
* Both halves run in EVERY replica by default, and neither needs to know about the others. The producer is safe to
|
|
20
|
+
* duplicate because a fire's job id is the fire's own instant; the consumer is safe to duplicate because a claim is
|
|
21
|
+
* atomic. What a deployment tunes is how many jobs each replica carries (`workers`) and whether it produces at all
|
|
22
|
+
* — a pod dedicated to running jobs sets `produce: false`, a pod serving pages sets `workers: 0`.
|
|
23
|
+
*
|
|
24
|
+
* With no `queue` supplied this is one process's memory, which is right for a single replica and wrong the moment
|
|
25
|
+
* there are two. That is a sentence rather than a silent behaviour because the failure is invisible: everything
|
|
26
|
+
* works, and the nightly email goes out once per replica. The workers of one server are one replica: they share
|
|
27
|
+
* the primary's queue, and only one of them runs the scheduler and the jobs (`runsFleetJobs`).
|
|
28
|
+
*/
|
|
29
|
+
export declare const createActionJobs: (config: ActionJobsConfig, module: ActionsModule, lookups: ActionLookups, functionJobs?: FunctionJobsService) => ActionJobs;
|
|
30
|
+
export { createMemoryJobQueue } from './memoryQueue';
|
|
31
|
+
export { createScheduler } from './scheduler';
|
|
32
|
+
export { createJobWorker } from './worker';
|
|
33
|
+
export { DEFAULT_MAX_ATTEMPTS, scheduleFor, scheduleJobId, schedulesFor } from './schedules';
|
|
34
|
+
export type { MemoryJobQueueOptions } from './memoryQueue';
|
|
35
|
+
export type { Scheduler, SchedulerOptions, SweepResult } from './scheduler';
|
|
36
|
+
export type { JobWorker, JobWorkerOptions } from './worker';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { JobQueue } from '../../types';
|
|
2
|
+
import { ActionLookups } from '../types';
|
|
3
|
+
import { Environment, SpaceRevision } from '@plitzi/sdk-shared';
|
|
4
|
+
import { LaterAnswer, LaterRequest } from '@plitzi/sdk-shared/functions';
|
|
5
|
+
/** A month: past it, a run set for later is a schedule, and a cron says it better. */
|
|
6
|
+
export declare const MAX_LATER_SECONDS: number;
|
|
7
|
+
export type LaterDeps = {
|
|
8
|
+
/** Read when asked: the queue is made after the runner, and a server may run none. */
|
|
9
|
+
queue: () => JobQueue | undefined;
|
|
10
|
+
lookups: Pick<ActionLookups, 'getAction'>;
|
|
11
|
+
maxAttempts: number;
|
|
12
|
+
};
|
|
13
|
+
export type LaterScope = {
|
|
14
|
+
spaceId: number;
|
|
15
|
+
environment: Environment;
|
|
16
|
+
at?: SpaceRevision;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Runs of a space's actions that start in a while — a turn that runs out, a bot's move, a hold that lapses — held by the
|
|
20
|
+
* same queue as its schedules: they outlive a restart where the queue does, run once across replicas, retry, and show
|
|
21
|
+
* in the queue an operator reads. Every refusal says why, before anything is queued.
|
|
22
|
+
*/
|
|
23
|
+
export declare const laterFor: ({ queue, lookups, maxAttempts }: LaterDeps, { spaceId, environment, at }: LaterScope) => {
|
|
24
|
+
later: ({ action, in: seconds, input, key }: LaterRequest) => Promise<LaterAnswer>;
|
|
25
|
+
/** Drops what is waiting under `key`, and answers how many. */
|
|
26
|
+
cancelLater: (key: string) => Promise<number>;
|
|
27
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Job } from '@plitzi/sdk-shared';
|
|
2
|
+
/**
|
|
3
|
+
* What a job needs once the worker running it died, in the words every store writes: the in-process ones through
|
|
4
|
+
* `queueRules`, Mongo and MySQL in their own queries — each composing the same sentences from these parts.
|
|
5
|
+
*
|
|
6
|
+
* A worker dies for many reasons — a node lost, a deploy past its grace — and the job is simply run again. But one that
|
|
7
|
+
* died near its memory (it said so: `heartbeat`'s `nearMemoryLimit`), or a second in a row to die running the same job,
|
|
8
|
+
* 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
|
|
9
|
+
* the worker could hold, when the claims say what their workers may (`JobClaimMemory`).
|
|
10
|
+
*/
|
|
11
|
+
/** What the history says of an attempt nobody reported. */
|
|
12
|
+
export declare const LOST_ERROR = "the worker holding this job stopped reporting";
|
|
13
|
+
/** {@link lostError}'s words around what the worker could hold. */
|
|
14
|
+
export declare const LOST_MEMORY_WORDS: readonly ["the worker holding this job stopped reporting near its memory — it could hold ", " MiB, so the job runs next on a worker that may hold more"];
|
|
15
|
+
/** {@link setAsideError}'s words around what the job needs more than, and what the largest worker may hold. */
|
|
16
|
+
export declare const SET_ASIDE_WORDS: readonly ["Set aside: a worker died running it — it needs more than ", " MiB, and the largest worker here may hold ", " MiB. Give a worker more memory, then resume it."];
|
|
17
|
+
/** Whether the job took its worker down: it neared its memory holding it, or the attempt before was lost too. */
|
|
18
|
+
export declare const outgrewWorker: (job: Pick<Job, "nearMemoryLimit" | "history">) => boolean;
|
|
19
|
+
/** The least a job needs after the worker holding it died: more than that one could hold when the job took it down. */
|
|
20
|
+
export declare const needsAfterLoss: (needsMb: number | undefined, holderMb: number | undefined, outgrew: boolean) => number | undefined;
|
|
21
|
+
/** Why a job waits after its worker died: for a larger one, when it took that worker down and it said its size. */
|
|
22
|
+
export declare const lostError: (holderMb: number | undefined, outgrew: boolean) => string;
|
|
23
|
+
/** Why a job is set aside: no worker of the deployment may hold what it needs. */
|
|
24
|
+
export declare const setAsideError: (needsMb: number, ceilingMb: number) => string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { JobQueue } from '../../types';
|
|
2
|
+
import { StoreMethods } from '@plitzi/sdk-kernel/http';
|
|
3
|
+
export type MemoryJobQueueOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* How many finished jobs to keep before the oldest are dropped.
|
|
6
|
+
*
|
|
7
|
+
* A bound rather than a retention period, because this store has no eviction of its own and an unbounded history
|
|
8
|
+
* in a long-lived process is a leak with a nice name. A deployment that wants jobs it can still read next week
|
|
9
|
+
* supplies a queue backed by something that survives a restart.
|
|
10
|
+
*/
|
|
11
|
+
retainFinished?: number;
|
|
12
|
+
/**
|
|
13
|
+
* What this queue calls now, in epoch ms.
|
|
14
|
+
*
|
|
15
|
+
* The seam that makes a lease, a backoff and an overdue schedule testable without waiting for one — and the
|
|
16
|
+
* shape of the rule a shared store keeps too: everything here reads ONE clock, and it is the store's.
|
|
17
|
+
*/
|
|
18
|
+
clock?: () => number;
|
|
19
|
+
};
|
|
20
|
+
/** Every method of the queue, for the copy a server's workers share (`FleetStores`, `core/server/fleet/link.ts`). */
|
|
21
|
+
export declare const JOB_QUEUE_METHODS: StoreMethods<JobQueue>;
|
|
22
|
+
/**
|
|
23
|
+
* The default queue: one process's Maps.
|
|
24
|
+
*
|
|
25
|
+
* Correct for a deployment that runs ONE replica, which is most self-hosted ones, and honest about the rest — a
|
|
26
|
+
* second replica running on this gets its own schedules and its own jobs, so a nightly digest goes out twice. The
|
|
27
|
+
* cure is any store the replicas share, behind the same {@link JobQueue} seam.
|
|
28
|
+
*
|
|
29
|
+
* It keeps the contract exactly, rather than approximately: enqueue is idempotent by id, a claim reaps lapsed
|
|
30
|
+
* leases, and every instant is read here rather than accepted from a caller. A test that passes against this one
|
|
31
|
+
* is testing the rules a shared store has to keep too.
|
|
32
|
+
*/
|
|
33
|
+
export declare const createMemoryJobQueue: ({ retainFinished, clock }?: MemoryJobQueueOptions) => JobQueue;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How near its memory a worker is: what its jobs are marked by while it holds them, so that should it die, the queue
|
|
3
|
+
* knows the jobs took it down (`heartbeat`'s `nearMemoryLimit`) — and sends them to a larger worker, not its twin.
|
|
4
|
+
*/
|
|
5
|
+
/** A process's memory, in MiB: what it holds, and its JavaScript heap beside the most V8 lets it grow to. */
|
|
6
|
+
export type MemoryReading = {
|
|
7
|
+
rssMb: number;
|
|
8
|
+
heapUsedMb: number;
|
|
9
|
+
heapLimitMb: number;
|
|
10
|
+
};
|
|
11
|
+
/** The share of a limit past which a worker is near it: a kernel or V8 ends it at the limit, not before. */
|
|
12
|
+
export declare const NEAR_MEMORY_SHARE = 0.85;
|
|
13
|
+
/** This process's memory: `rss()` alone, which reads no more than it must, and V8's heap. */
|
|
14
|
+
export declare const readProcessMemory: () => MemoryReading;
|
|
15
|
+
/**
|
|
16
|
+
* Whether a worker is near its memory: what it holds near what its container may (`limitMb`), or its heap near what V8
|
|
17
|
+
* lets it grow to — which, sized from the container, is often the limit a job meets first ("heap out of memory").
|
|
18
|
+
*/
|
|
19
|
+
export declare const nearMemory: (reading: MemoryReading, limitMb: number) => boolean;
|
|
20
|
+
/** The reading in words, beside the limit: `450 of 512 MiB held · heap 240 of 259 MiB`. */
|
|
21
|
+
export declare const memoryWords: (reading: MemoryReading, limitMb: number) => string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { JobQueue } from '../../types';
|
|
2
|
+
import { Job } from '@plitzi/sdk-shared';
|
|
3
|
+
/** Why a worker takes a job later, not never: handed back "not now", or held back from claiming. */
|
|
4
|
+
/**
|
|
5
|
+
* Refusals that mean "not now" rather than "not ever".
|
|
6
|
+
*
|
|
7
|
+
* Both are the cluster protecting itself — another run holds the single-flight key, or this replica is already
|
|
8
|
+
* carrying as much as it will — and neither says anything about the job. So the job goes back to the queue with
|
|
9
|
+
* its attempt REFUNDED: burning one would let a busy afternoon retire a nightly digest as dead.
|
|
10
|
+
*/
|
|
11
|
+
export declare const TRY_AGAIN: Set<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Why a job was handed back "not now", in the words its line in the queue says — again in a second or two. Short and
|
|
14
|
+
* plain: it is read beside every waiting job of a burst; which ceiling (`concurrency.perSpace`, the worker's own) is the
|
|
15
|
+
* docs' to say, not every line's.
|
|
16
|
+
*/
|
|
17
|
+
export declare const NOT_NOW_WORDS: Partial<Record<string, string>>;
|
|
18
|
+
/**
|
|
19
|
+
* How long from `now` — the queue's clock, which every instant of it is read by — until the next minute begins, and a
|
|
20
|
+
* moment more: when a budget over the minute may be spent again.
|
|
21
|
+
*/
|
|
22
|
+
export declare const msToNextMinute: (now: number) => number;
|
|
23
|
+
/**
|
|
24
|
+
* How soon a job refused "not now" comes round again: a slot of its space frees in seconds, not the half minute and more
|
|
25
|
+
* a failure's backoff waits — a burst's jobs refused at their space's ceiling each waited 30–60 s for nothing.
|
|
26
|
+
*/
|
|
27
|
+
export declare const tryAgainMs: () => number;
|
|
28
|
+
/** Why a worker claims no more for now — its runs waiting for a runner with room — or nothing. */
|
|
29
|
+
export declare const runnersFull: (waiting: number) => string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* A worker's claims for one look. Of the jobs that need a runner, no more than its runs waiting for one leave room for
|
|
32
|
+
* (`RUNNER_WAITING_MOST`) — one claim of every free slot took 160 jobs of space code at once, before any reached a runner
|
|
33
|
+
* to be counted — shared by turns between their two kinds, the actions that run code and the functions' jobs: half the
|
|
34
|
+
* room each, the first of them `turn`'s (alternated look by look), what one leaves the other takes. They are offered
|
|
35
|
+
* their room first, and every job that needs none (`light`) the slots left: taken in the queue's order, a burst's
|
|
36
|
+
* actions held 100 minute-long jobs back for two and a half minutes, and light jobs first, a steady flow of them would
|
|
37
|
+
* have held both kinds back for ever.
|
|
38
|
+
*/
|
|
39
|
+
export declare const claimsWithin: (queue: JobQueue, waiting: number, turn: "codeActions" | "functionJobs") => (claim: Parameters<JobQueue["claim"]>[0]) => Promise<Job[]>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { QueueState } from './queueRules';
|
|
2
|
+
import { ActionSchedule } from '../../types';
|
|
3
|
+
import { Job } from '@plitzi/sdk-shared';
|
|
4
|
+
/**
|
|
5
|
+
* A queue's state as one document — what `createFileJobQueue` writes to its file and `createSqliteJobQueue` to its row —
|
|
6
|
+
* versioned so a later layout can tell an old one from a broken one.
|
|
7
|
+
*/
|
|
8
|
+
export type QueueDocument = {
|
|
9
|
+
format: 1;
|
|
10
|
+
jobs: Job[];
|
|
11
|
+
schedules: ActionSchedule[];
|
|
12
|
+
};
|
|
13
|
+
export declare const documentOf: ({ jobs, schedules }: QueueState) => QueueDocument;
|
|
14
|
+
/** The state a document holds — or why it is no queue's, for the store to say with its fix. */
|
|
15
|
+
export declare const stateOf: (parsed: unknown) => QueueState | string;
|