@plitzi/sdk-actions 0.0.0-stage → 0.39.3
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 +18 -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,317 @@
|
|
|
1
|
+
import { Environment, Job, JobAttempt, JobInput, JobProgress, JobStatus, JobTarget } from '@plitzi/sdk-shared';
|
|
2
|
+
/**
|
|
3
|
+
* Which spaces' jobs a worker takes: only these — a worker kept for some spaces — or every space but these, whose own
|
|
4
|
+
* workers take theirs. Absent, every space's.
|
|
5
|
+
*/
|
|
6
|
+
export type JobSpaces = {
|
|
7
|
+
only: number[];
|
|
8
|
+
} | {
|
|
9
|
+
except: number[];
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* How replicas tell each other a job is due now, beside each worker looking every `pollMs`: `notify` as one is enqueued
|
|
13
|
+
* or handed back due, `listen` for it — a deployment's pub/sub. Without it a worker finds a new job on its next look: up
|
|
14
|
+
* to `pollMs` late, half of it on average, with nothing else to do.
|
|
15
|
+
*/
|
|
16
|
+
export type JobWake = {
|
|
17
|
+
notify: () => void;
|
|
18
|
+
/** Called on every notice from any replica, this one's included; answers how to stop listening. */
|
|
19
|
+
listen: (onWake: () => void) => () => void;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* A kind of work, as a worker's claim shares its room between them: actions that run no space code (`light`, needing no
|
|
23
|
+
* runner), actions that do (`codeActions`, `target.code`), and the spaces' functions' jobs (`functionJobs`).
|
|
24
|
+
*/
|
|
25
|
+
export type JobTake = 'light' | 'codeActions' | 'functionJobs';
|
|
26
|
+
/** Why a worker is asked to stop a job it holds: an operator or the code cancelled it, or set it aside. */
|
|
27
|
+
export type JobStop = 'cancel' | 'pause';
|
|
28
|
+
/**
|
|
29
|
+
* How a worker reports what became of a claim.
|
|
30
|
+
*
|
|
31
|
+
* `delayMs` rather than an instant, and no timestamps: every moment the queue records is read from the QUEUE's
|
|
32
|
+
* clock, because a cluster whose nodes sit in different countries agrees about durations and not about now.
|
|
33
|
+
*/
|
|
34
|
+
export type JobSettlement = {
|
|
35
|
+
jobId: string;
|
|
36
|
+
workerId: string;
|
|
37
|
+
status: Extract<JobStatus, 'succeeded' | 'failed' | 'dead' | 'cancelled' | 'pending' | 'paused'>;
|
|
38
|
+
/** For a retry: how long from now before it may be claimed again. */
|
|
39
|
+
delayMs?: number;
|
|
40
|
+
runId?: string;
|
|
41
|
+
error?: string;
|
|
42
|
+
/** The attempt to append to the history. Omitted only when the claim is being handed back untouched. */
|
|
43
|
+
attempt?: Omit<JobAttempt, 'attempt' | 'startedAt' | 'endedAt'>;
|
|
44
|
+
/** What a job of the space's functions answered, when it succeeded. */
|
|
45
|
+
result?: unknown;
|
|
46
|
+
/** How long this slice ran, added to the job's `activeMs`. */
|
|
47
|
+
spentMs?: number;
|
|
48
|
+
/**
|
|
49
|
+
* The attempt the claim took is given back: a slice that ended without failing — set aside, cut by its time, or by a
|
|
50
|
+
* replica going away — is not one. Absent, it is given back only for a claim handed back untouched (`pending`, no
|
|
51
|
+
* `attempt`).
|
|
52
|
+
*/
|
|
53
|
+
refund?: boolean;
|
|
54
|
+
};
|
|
55
|
+
/** What a job's code saved while it runs — only by the worker holding it, so a stalled one cannot write over the next. */
|
|
56
|
+
export type JobWrite = {
|
|
57
|
+
jobId: string;
|
|
58
|
+
workerId: string;
|
|
59
|
+
state?: unknown;
|
|
60
|
+
progress?: Omit<JobProgress, 'at'>;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* What a worker may hold, said as it claims, so the queue moves a job a worker died running to a larger one rather than
|
|
64
|
+
* let it kill the next of the same size. A deployment whose workers say nothing keeps the queue as it always was: a job
|
|
65
|
+
* whose worker died runs again on whichever claims it.
|
|
66
|
+
*/
|
|
67
|
+
export type JobClaimMemory = {
|
|
68
|
+
/** What this worker may hold, in MiB: its container's memory. */
|
|
69
|
+
mb: number;
|
|
70
|
+
/** The most any worker of the deployment may hold, in MiB: a job that needs more is set aside (`paused`), saying so. */
|
|
71
|
+
ceilingMb: number;
|
|
72
|
+
/**
|
|
73
|
+
* Whether it takes a job a worker died running, besides its own: not while it runs one already — each may need all it
|
|
74
|
+
* has. Default yes.
|
|
75
|
+
*/
|
|
76
|
+
takesNeeding?: boolean;
|
|
77
|
+
};
|
|
78
|
+
/** The jobs a worker died running, as `summarize` counts them. */
|
|
79
|
+
export type JobsNeedingMemory = {
|
|
80
|
+
/** Waiting for a worker that may hold more than the one that died running them. */
|
|
81
|
+
waiting: number;
|
|
82
|
+
/** Set aside: no worker of the deployment may hold what they need. */
|
|
83
|
+
paused: number;
|
|
84
|
+
/** The most any of them waiting needs, in MiB: what a deployment keeps a worker of, while they wait. */
|
|
85
|
+
mostMb?: number;
|
|
86
|
+
};
|
|
87
|
+
/** What waits in the queue — `pending` or `paused` — by what it is. */
|
|
88
|
+
export type WaitingJobs = {
|
|
89
|
+
/** Visitors' calls kept because nothing could run them when they were made. */
|
|
90
|
+
calls: number;
|
|
91
|
+
/** Schedules' fires. */
|
|
92
|
+
schedules: number;
|
|
93
|
+
/** Runs set for later (`ctx.later`). */
|
|
94
|
+
later: number;
|
|
95
|
+
/** Jobs of the spaces' functions. */
|
|
96
|
+
functionJobs: number;
|
|
97
|
+
/** Anything else: a webhook's, a custom trigger's. */
|
|
98
|
+
other: number;
|
|
99
|
+
};
|
|
100
|
+
/** A queue at a glance — see `JobQueue.summarize`. */
|
|
101
|
+
export type JobQueueSummary = {
|
|
102
|
+
byStatus: Record<JobStatus, number>;
|
|
103
|
+
waiting: WaitingJobs;
|
|
104
|
+
/** When the job waiting longest was due, epoch ms by the queue's clock; absent with nothing waiting. */
|
|
105
|
+
oldestDueAt?: number;
|
|
106
|
+
/** The jobs a worker died running, waiting for a larger one or set aside. */
|
|
107
|
+
needingMemory: JobsNeedingMemory;
|
|
108
|
+
/** The spaces with the most waiting, the most first: how many, how many of them kept calls, since when, and why. */
|
|
109
|
+
spaces: {
|
|
110
|
+
spaceId: number;
|
|
111
|
+
waiting: number;
|
|
112
|
+
calls: number;
|
|
113
|
+
oldestDueAt: number;
|
|
114
|
+
/** What the last job of it handed back said: `Waiting for a functions runner to answer`. */
|
|
115
|
+
lastError?: string;
|
|
116
|
+
}[];
|
|
117
|
+
};
|
|
118
|
+
/** One minute of the queue's flow (`flow`): what an operator reads to tell whether it keeps up. */
|
|
119
|
+
export type JobFlowMinute = {
|
|
120
|
+
/** Minutes since the epoch, UTC. */
|
|
121
|
+
minute: number;
|
|
122
|
+
/** Jobs that fell due in it: a schedule's fire, a kept call, a run set for later reaching its time. */
|
|
123
|
+
due: number;
|
|
124
|
+
/** Attempts started in it — the one running now included. */
|
|
125
|
+
started: number;
|
|
126
|
+
/** Attempts that ended in it, however they ended. */
|
|
127
|
+
ended: number;
|
|
128
|
+
/** Of the jobs whose first attempt started in it, the p95 of how long each waited from due to that start. */
|
|
129
|
+
waitP95Ms?: number;
|
|
130
|
+
};
|
|
131
|
+
export type JobQuery = {
|
|
132
|
+
spaceIds: number[];
|
|
133
|
+
status?: JobStatus;
|
|
134
|
+
/** Only runs of actions, or only jobs of the spaces' functions. */
|
|
135
|
+
kind?: JobTarget['kind'];
|
|
136
|
+
/** Only what runs this action, or this job (`target.name`). */
|
|
137
|
+
name?: string;
|
|
138
|
+
limit: number;
|
|
139
|
+
offset: number;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* A recurring intent, as a row rather than as a timer.
|
|
143
|
+
*
|
|
144
|
+
* `nextRunAt` is the point of the whole design: the instant of the next fire is DECIDED ONCE and written down, so
|
|
145
|
+
* every replica afterwards reads the same number instead of asking its own clock whether the moment has come. Two
|
|
146
|
+
* nodes whose clocks differ by a minute then produce the same fires, in the same order, exactly once each — the
|
|
147
|
+
* disagreement moves the WHEN by their skew and can never move the WHETHER.
|
|
148
|
+
*/
|
|
149
|
+
export type ActionSchedule = {
|
|
150
|
+
spaceId: number;
|
|
151
|
+
actionId: string;
|
|
152
|
+
cron: string;
|
|
153
|
+
timezone?: string;
|
|
154
|
+
environment: Environment;
|
|
155
|
+
enabled: boolean;
|
|
156
|
+
/** Epoch ms of the next fire this schedule owes. The queue's clock decides when that has arrived. */
|
|
157
|
+
nextRunAt: number;
|
|
158
|
+
/** The last fire actually enqueued. */
|
|
159
|
+
lastFireAt?: number;
|
|
160
|
+
/** Fires that went by while nothing was running to take them. Cumulative, and shown to an operator. */
|
|
161
|
+
missed: number;
|
|
162
|
+
maxAttempts: number;
|
|
163
|
+
updatedAt: number;
|
|
164
|
+
};
|
|
165
|
+
/** A schedule as it is derived from an action document — everything the queue does not own itself. */
|
|
166
|
+
export type ActionScheduleInput = Omit<ActionSchedule, 'missed' | 'updatedAt' | 'lastFireAt'>;
|
|
167
|
+
/**
|
|
168
|
+
* Where a deployment keeps its jobs and schedules.
|
|
169
|
+
*
|
|
170
|
+
* The same kind of seam as {@link ActionKvAdapter} and for the same reason — the server never learns where a
|
|
171
|
+
* deployment stores anything — but with one rule this one cannot be written without, and it is written here so no
|
|
172
|
+
* deployment has to rediscover it:
|
|
173
|
+
*
|
|
174
|
+
* **Every instant comes from the store.** `now` is the cluster's clock, and every comparison the queue makes
|
|
175
|
+
* internally — is this schedule due, has this lease lapsed, may this retry be claimed — is made against it, never
|
|
176
|
+
* against the caller's. That is why `settle` takes a `delayMs` and not a deadline, and why `claim` takes a
|
|
177
|
+
* `leaseMs` and not a `leaseUntil`: durations survive a cluster spread across time zones and machines whose clocks
|
|
178
|
+
* drift, and absolute instants minted by a caller do not.
|
|
179
|
+
*
|
|
180
|
+
* **`enqueue` is idempotent by `id`,** and answers whether it was the one that created the job. That, and nothing
|
|
181
|
+
* else, is what makes a fire happen exactly once when several replicas are racing to produce it.
|
|
182
|
+
*
|
|
183
|
+
* **`claim` is atomic, and it also reaps.** A job whose lease has lapsed is a job whose worker died, and it is
|
|
184
|
+
* taken by whoever claims next — the same operation, because a separate reaper is a second thing to deploy, to
|
|
185
|
+
* schedule and to forget. When the claims say what their workers may hold (`memory`), a reaped job that took its
|
|
186
|
+
* worker down needs more than that one could: it waits for a worker that may, and is set aside (`paused`) when none may.
|
|
187
|
+
*/
|
|
188
|
+
export type JobQueue = {
|
|
189
|
+
/** The cluster's clock. The only clock anything in the scheduling path is allowed to read. */
|
|
190
|
+
now: () => Promise<Date>;
|
|
191
|
+
/** True when this call created the job; false when that id was already there. Never throws on a duplicate. */
|
|
192
|
+
enqueue: (job: JobInput) => Promise<boolean>;
|
|
193
|
+
/**
|
|
194
|
+
* Takes up to `limit` jobs that are due, and any whose lease has lapsed — atomically, one worker per job.
|
|
195
|
+
*
|
|
196
|
+
* A reaped job has its previous holder's attempt written to the history as `lost`. One that took that holder down —
|
|
197
|
+
* it neared its memory holding it (`heartbeat`'s `nearMemoryLimit`), or the attempt before was lost too — then needs
|
|
198
|
+
* more than the holder could hold, when its claim said (`needsMemoryMb`): taken by a worker that may, whatever its
|
|
199
|
+
* `spaces`, or set aside (`paused`) when more than `memory.ceilingMb`. A job that needs more than this worker may hold
|
|
200
|
+
* is left to another.
|
|
201
|
+
*/
|
|
202
|
+
claim: (params: {
|
|
203
|
+
workerId: string;
|
|
204
|
+
leaseMs: number;
|
|
205
|
+
limit: number;
|
|
206
|
+
spaces?: JobSpaces;
|
|
207
|
+
memory?: JobClaimMemory;
|
|
208
|
+
/** Only jobs of one kind of work (`JobTake`): what a worker shares its room between. Absent, every job. */
|
|
209
|
+
takes?: JobTake;
|
|
210
|
+
}) => Promise<Job[]>;
|
|
211
|
+
/**
|
|
212
|
+
* Extends the lease on jobs this worker still holds, and answers which of them it is asked to stop — cancelled, or
|
|
213
|
+
* set aside (`pause`). With `nearMemoryLimit`, this worker neared its memory: should it die holding them, they need
|
|
214
|
+
* a larger one.
|
|
215
|
+
*/
|
|
216
|
+
heartbeat: (params: {
|
|
217
|
+
jobIds: string[];
|
|
218
|
+
workerId: string;
|
|
219
|
+
leaseMs: number;
|
|
220
|
+
nearMemoryLimit?: boolean;
|
|
221
|
+
}) => Promise<{
|
|
222
|
+
jobId: string;
|
|
223
|
+
stop: JobStop;
|
|
224
|
+
}[]>;
|
|
225
|
+
settle: (settlement: JobSettlement) => Promise<void>;
|
|
226
|
+
/** Writes what a running job's code saved or reported. False when this worker no longer holds it. */
|
|
227
|
+
write: (write: JobWrite) => Promise<boolean>;
|
|
228
|
+
/** Due schedules, oldest fire first. */
|
|
229
|
+
dueSchedules: (limit: number) => Promise<ActionSchedule[]>;
|
|
230
|
+
/**
|
|
231
|
+
* Moves a schedule forward, but only if it is still where the caller last saw it.
|
|
232
|
+
*
|
|
233
|
+
* The compare-and-set is what stops two replicas from advancing the same schedule twice. Answers false when
|
|
234
|
+
* somebody else got there first, which is not an error — it is the other replica having done the work.
|
|
235
|
+
*/
|
|
236
|
+
advanceSchedule: (params: {
|
|
237
|
+
spaceId: number;
|
|
238
|
+
actionId: string;
|
|
239
|
+
from: number;
|
|
240
|
+
to: number;
|
|
241
|
+
missed: number;
|
|
242
|
+
}) => Promise<boolean>;
|
|
243
|
+
/** Replaces what this space has scheduled. An action no longer listed stops having a schedule at all. */
|
|
244
|
+
putSchedules: (params: {
|
|
245
|
+
spaceId: number;
|
|
246
|
+
schedules: ActionScheduleInput[];
|
|
247
|
+
}) => Promise<void>;
|
|
248
|
+
listJobs: (query: JobQuery) => Promise<{
|
|
249
|
+
jobs: Job[];
|
|
250
|
+
total: number;
|
|
251
|
+
}>;
|
|
252
|
+
/**
|
|
253
|
+
* Jobs of EVERY space in these statuses — an operator's view, never a space's own (`listJobs` is): the longest due first
|
|
254
|
+
* (`due`), or the latest written first (`latest`). What a monitoring screen lists of what waits, runs and just ended.
|
|
255
|
+
*/
|
|
256
|
+
listAcross: (query: {
|
|
257
|
+
statuses: JobStatus[];
|
|
258
|
+
limit: number;
|
|
259
|
+
order: 'due' | 'latest';
|
|
260
|
+
}) => Promise<Job[]>;
|
|
261
|
+
/**
|
|
262
|
+
* The whole queue at a glance, every space: what an operator reads to tell a queue that drains from one that fills —
|
|
263
|
+
* its jobs by status, what waits by what it is, the oldest of it, and the spaces with the most waiting.
|
|
264
|
+
*/
|
|
265
|
+
summarize: (options?: {
|
|
266
|
+
spaces?: number;
|
|
267
|
+
}) => Promise<JobQueueSummary>;
|
|
268
|
+
/**
|
|
269
|
+
* How many jobs a claim with these `spaces` and `memoryMb` would take now — due and waiting, as `claim` reads them:
|
|
270
|
+
* what an autoscaler adds to the work its workers hold, so a queue that grows behind a slow job grows the pool.
|
|
271
|
+
*/
|
|
272
|
+
countDue: (params?: {
|
|
273
|
+
spaces?: JobSpaces;
|
|
274
|
+
memoryMb?: number;
|
|
275
|
+
}) => Promise<number>;
|
|
276
|
+
/**
|
|
277
|
+
* The queue's flow minute by minute over `[from, to)` (epoch ms, the queue's clock): what fell due, was started and
|
|
278
|
+
* ended in each minute, and how long jobs waited for their first attempt — every space.
|
|
279
|
+
*/
|
|
280
|
+
flow: (params: {
|
|
281
|
+
from: number;
|
|
282
|
+
to: number;
|
|
283
|
+
}) => Promise<JobFlowMinute[]>;
|
|
284
|
+
getJob: (spaceIds: number[], jobId: string) => Promise<Job | undefined>;
|
|
285
|
+
listSchedules: (spaceIds: number[]) => Promise<ActionSchedule[]>;
|
|
286
|
+
/**
|
|
287
|
+
* Puts a finished job back in the queue — an operator retrying it, or the code starting a keyed job again. Answers false
|
|
288
|
+
* when it is not finished. With `input`, it runs with that; with `fresh`, a job of the space's functions starts over
|
|
289
|
+
* rather than from what it saved.
|
|
290
|
+
*/
|
|
291
|
+
requeue: (spaceIds: number[], jobId: string, options?: {
|
|
292
|
+
input?: Record<string, unknown>;
|
|
293
|
+
fresh?: boolean;
|
|
294
|
+
}) => Promise<boolean>;
|
|
295
|
+
/** Stops a job: dropped if it is waiting or set aside, aborted at its next step if it is running. */
|
|
296
|
+
cancel: (spaceIds: number[], jobId: string) => Promise<boolean>;
|
|
297
|
+
/**
|
|
298
|
+
* Sets a job of the space's functions aside: one waiting is `paused` at once, one running is flagged for the worker
|
|
299
|
+
* holding it, which stops it once its code has saved. Answers whether it changed anything.
|
|
300
|
+
*/
|
|
301
|
+
pause: (spaceIds: number[], jobId: string) => Promise<boolean>;
|
|
302
|
+
/**
|
|
303
|
+
* Puts a `paused` job back in the queue, to start again from what it saved — one set aside after failing every
|
|
304
|
+
* attempt with every attempt again.
|
|
305
|
+
*/
|
|
306
|
+
resume: (spaceIds: number[], jobId: string) => Promise<boolean>;
|
|
307
|
+
/**
|
|
308
|
+
* Drops the space's jobs waiting under `key` (`cancelled`), and answers how many. With `olderThan`, only the ones
|
|
309
|
+
* enqueued before that job — created earlier, or at the same instant with a smaller id — so of two set at once the
|
|
310
|
+
* newer is the one left, on every replica. A running one is left: it is usually the run that set the next.
|
|
311
|
+
*/
|
|
312
|
+
cancelPending: (params: {
|
|
313
|
+
spaceId: number;
|
|
314
|
+
key: string;
|
|
315
|
+
olderThan?: string;
|
|
316
|
+
}) => Promise<number>;
|
|
317
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RemoteRenderOptions } from '../render/remote';
|
|
2
|
+
import { EngineConfig } from '../types';
|
|
3
|
+
import { PageEngine } from '@plitzi/sdk-kernel/engine';
|
|
4
|
+
/**
|
|
5
|
+
* What a page server is handed when its actions run on a worker (`createWorker`): where its pages call them and where
|
|
6
|
+
* their channels are, and nothing that runs here — the gateway sends those paths to the worker. Give it the `action` and
|
|
7
|
+
* `realtime` the worker has, for the same paths — and, when the worker is on another origin, its `action.origin`: the pages
|
|
8
|
+
* are told the address there.
|
|
9
|
+
*
|
|
10
|
+
* With `render` its server elements that name an action or a connector are asked of the worker too (`/_render`, behind
|
|
11
|
+
* the worker's `render.secret`): this server then runs no action at all. Without it, a page that renders one shows it
|
|
12
|
+
* in its error state, said as an element no engine here resolves.
|
|
13
|
+
*/
|
|
14
|
+
export declare const engineOnWorker: ({ action, realtime, render }?: Pick<EngineConfig, "action" | "realtime"> & {
|
|
15
|
+
render?: RemoteRenderOptions;
|
|
16
|
+
}) => PageEngine;
|