@elaraai/e3-api-server 1.0.104 → 1.0.105
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/README.md +114 -9
- package/dist/src/call-limits.d.ts +72 -0
- package/dist/src/call-limits.d.ts.map +1 -0
- package/dist/src/call-limits.js +104 -0
- package/dist/src/call-limits.js.map +1 -0
- package/dist/src/call-limits.spec.d.ts +6 -0
- package/dist/src/call-limits.spec.d.ts.map +1 -0
- package/dist/src/call-limits.spec.js +264 -0
- package/dist/src/call-limits.spec.js.map +1 -0
- package/dist/src/cli.js +10 -0
- package/dist/src/cli.js.map +1 -1
- package/dist/src/handlers/calls.d.ts +238 -0
- package/dist/src/handlers/calls.d.ts.map +1 -0
- package/dist/src/handlers/calls.js +383 -0
- package/dist/src/handlers/calls.js.map +1 -0
- package/dist/src/handlers/functions.d.ts +40 -9
- package/dist/src/handlers/functions.d.ts.map +1 -1
- package/dist/src/handlers/functions.js +129 -75
- package/dist/src/handlers/functions.js.map +1 -1
- package/dist/src/handlers/functions.spec.js +33 -2
- package/dist/src/handlers/functions.spec.js.map +1 -1
- package/dist/src/handlers/index.d.ts +2 -1
- package/dist/src/handlers/index.d.ts.map +1 -1
- package/dist/src/handlers/index.js +2 -1
- package/dist/src/handlers/index.js.map +1 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/portable.d.ts +2 -1
- package/dist/src/portable.d.ts.map +1 -1
- package/dist/src/portable.js +4 -1
- package/dist/src/portable.js.map +1 -1
- package/dist/src/portable.spec.js +1 -0
- package/dist/src/portable.spec.js.map +1 -1
- package/dist/src/routes/calls.d.ts +81 -0
- package/dist/src/routes/calls.d.ts.map +1 -0
- package/dist/src/routes/calls.js +141 -0
- package/dist/src/routes/calls.js.map +1 -0
- package/dist/src/routes/functions.d.ts +97 -25
- package/dist/src/routes/functions.d.ts.map +1 -1
- package/dist/src/routes/functions.js +147 -30
- package/dist/src/routes/functions.js.map +1 -1
- package/dist/src/routes/index.d.ts +2 -1
- package/dist/src/routes/index.d.ts.map +1 -1
- package/dist/src/routes/index.js +2 -1
- package/dist/src/routes/index.js.map +1 -1
- package/dist/src/server.d.ts +15 -1
- package/dist/src/server.d.ts.map +1 -1
- package/dist/src/server.js +43 -10
- package/dist/src/server.js.map +1 -1
- package/dist/src/types.d.ts +291 -2
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +13 -2
- package/dist/src/types.js.map +1 -1
- package/package.json +7 -6
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Handlers for the calls of named functions through a workspace, and of
|
|
7
|
+
* one-shots started as calls (east-workspace#1554).
|
|
8
|
+
*
|
|
9
|
+
* A call is filed by e3-core's `functionCallStart` — a one-shot's by
|
|
10
|
+
* `oneShotCallStart`, its caller's program run as an anonymous function — run
|
|
11
|
+
* where the transfer backend's dispatch runs calls (`FunctionCallDispatch`),
|
|
12
|
+
* and kept in the repository's call store (`StorageBackend.calls`) for the
|
|
13
|
+
* lifetime its end gives it. So a call outlasts the request that starts it:
|
|
14
|
+
* its start waits a while for it and answers its result, or `running` with its
|
|
15
|
+
* id, which its caller polls until it ends. The sync call is the same call,
|
|
16
|
+
* waited for within its request. Each handler reads the store for whatever the
|
|
17
|
+
* dispatch cannot say, so a poll is answered alike by whichever instance it
|
|
18
|
+
* reaches.
|
|
19
|
+
*/
|
|
20
|
+
import { none, some, variant } from '@elaraai/east';
|
|
21
|
+
import { FUNCTION_CALL_GRACE_MS, PermissionDeniedError, WorkspaceNotFoundError, functionCallInputs, functionCallLost, functionCallRead, functionCallStart, functionCallStatus, functionCallSummary, oneShotCallStart, } from '@elaraai/e3-core/portable';
|
|
22
|
+
import { sendError, sendSuccess } from '../beast2.js';
|
|
23
|
+
import { errorToVariant } from '../errors.js';
|
|
24
|
+
import { ExecuteResultType, FUNCTION_CALLS_PAGE_DEFAULT, FUNCTION_CALLS_PAGE_MAX, FunctionCallAnswerType, FunctionCallPageType, FunctionCallStatusType, FunctionCallType, } from '../types.js';
|
|
25
|
+
/** How long a wait holds between its looks at the store, for a call whose end
|
|
26
|
+
* its dispatch does not hear of: one run elsewhere, or by another instance. */
|
|
27
|
+
const LOOK_MS = 500;
|
|
28
|
+
/** How long past a sync call's deadline its request waits for the call's run
|
|
29
|
+
* to record its end, which a run does once it stops itself at its timeout,
|
|
30
|
+
* before the request answers `timed_out` itself. */
|
|
31
|
+
const SYNC_GRACE_MS = 1000;
|
|
32
|
+
/**
|
|
33
|
+
* Start a call of a named function through a workspace: file it, run it where
|
|
34
|
+
* the backend runs calls, and wait up to `waitMs` for it to end.
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* The call is checked, its inputs and dataset arguments pinned and its value
|
|
38
|
+
* arguments stored as e3-core's `functionCallStart` does, and it is kept from
|
|
39
|
+
* now until its lifetime ends. A call found wrong is filed ended `invalid`,
|
|
40
|
+
* and answered `completed` with that result. A call is held to its own
|
|
41
|
+
* timeout, never to the request's: one still running when the wait passes is
|
|
42
|
+
* answered `running`, and its caller polls by its id. A call the dispatch
|
|
43
|
+
* cannot hand to the compute that runs calls is recorded `lost`, and answered
|
|
44
|
+
* so.
|
|
45
|
+
*
|
|
46
|
+
* @param storage - Storage backend
|
|
47
|
+
* @param dispatch - Runs the call where the backend runs calls
|
|
48
|
+
* @param repo - The repository's name, which the dispatch takes
|
|
49
|
+
* @param repoPath - The repository's identifier, which the store takes
|
|
50
|
+
* @param workspace - The workspace the call is made through
|
|
51
|
+
* @param fnName - The function's name in the deployed package
|
|
52
|
+
* @param request - The arguments, and any runner and limits the caller names
|
|
53
|
+
* @param options - Who calls, their grant, the ceilings, the lifetimes and how
|
|
54
|
+
* long to wait
|
|
55
|
+
* @returns The response: the call's id and how it stood when the wait ended;
|
|
56
|
+
* or the error that stopped its start — the workspace, its package or the
|
|
57
|
+
* function not found, or `permission_denied` (`path` `runner`)
|
|
58
|
+
*/
|
|
59
|
+
export async function startFunctionCall(storage, dispatch, repo, repoPath, workspace, fnName, request, options) {
|
|
60
|
+
try {
|
|
61
|
+
const job = await functionCallStart(storage, repoPath, workspace, fnName, request, {
|
|
62
|
+
...filingOf(options),
|
|
63
|
+
...(options.id !== undefined && { id: options.id }),
|
|
64
|
+
});
|
|
65
|
+
const status = await runAndWait(storage, dispatch, repo, repoPath, job, options.waitMs);
|
|
66
|
+
return sendSuccess(FunctionCallAnswerType, { id: job.call.id, status });
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
return sendError(FunctionCallAnswerType, errorToVariant(err));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Start a one-shot as a call through a workspace: file it, run it where the
|
|
74
|
+
* backend runs calls, and wait up to `waitMs` for it to end — what a named
|
|
75
|
+
* function's start does, for its caller's program.
|
|
76
|
+
*
|
|
77
|
+
* @remarks
|
|
78
|
+
* The request is held to its caller's grant, as a one-shot run within a
|
|
79
|
+
* request is, before anything is read; its program is filed as an anonymous
|
|
80
|
+
* function, its dataset arguments pinned and its value arguments stored, as
|
|
81
|
+
* e3-core's `oneShotCallStart` does; and it is kept from now until its
|
|
82
|
+
* lifetime ends, listed among the workspace's calls naming no function. A
|
|
83
|
+
* call found wrong is filed ended `invalid`, and answered `completed` with
|
|
84
|
+
* that result. A call is held to its own timeout, never to the request's: one
|
|
85
|
+
* still running when the wait passes is answered `running`, and its caller
|
|
86
|
+
* polls it by its id, and cancels it, through the calls routes. A call the
|
|
87
|
+
* dispatch cannot hand to the compute that runs calls is recorded `lost`, and
|
|
88
|
+
* answered so.
|
|
89
|
+
*
|
|
90
|
+
* @param storage - Storage backend
|
|
91
|
+
* @param dispatch - Runs the call where the backend runs calls
|
|
92
|
+
* @param repo - The repository's name, which the dispatch takes
|
|
93
|
+
* @param repoPath - The repository's identifier, which the store takes
|
|
94
|
+
* @param workspace - The workspace whose datasets the call reads
|
|
95
|
+
* @param request - The program, its arguments, its runner and its limits
|
|
96
|
+
* @param options - Who calls, their grant, the ceilings, the lifetimes and how
|
|
97
|
+
* long to wait
|
|
98
|
+
* @returns The response: the call's id and how it stood when the wait ended;
|
|
99
|
+
* or the error that stopped its start — `permission_denied` (`path`
|
|
100
|
+
* `one-shot`) for a request the caller's grant does not run, and the
|
|
101
|
+
* workspace not found or not deployed
|
|
102
|
+
*/
|
|
103
|
+
export async function startOneShotCall(storage, dispatch, repo, repoPath, workspace, request, options) {
|
|
104
|
+
try {
|
|
105
|
+
const job = await oneShotCallStart(storage, repoPath, workspace, request, {
|
|
106
|
+
...filingOf(options),
|
|
107
|
+
grant: options.grant,
|
|
108
|
+
...(options.id !== undefined && { id: options.id }),
|
|
109
|
+
});
|
|
110
|
+
const status = await runAndWait(storage, dispatch, repo, repoPath, job, options.waitMs);
|
|
111
|
+
return sendSuccess(FunctionCallAnswerType, { id: job.call.id, status });
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
return sendError(FunctionCallAnswerType, errorToVariant(err));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Call a named function through a workspace synchronously: the call is filed
|
|
119
|
+
* and kept as a started one is, and the request waits for it to end.
|
|
120
|
+
*
|
|
121
|
+
* @remarks
|
|
122
|
+
* The call's timeout defaults as a sync call's does, and is clamped under the
|
|
123
|
+
* host's sync deadline, so the caller gets a structured `timed_out` instead of
|
|
124
|
+
* a transport cut. Its run stops it at that timeout and records it so; should
|
|
125
|
+
* the record not land within a second of the deadline, the request answers
|
|
126
|
+
* `timed_out` itself. A call cancelled while the request waits, or lost, has
|
|
127
|
+
* no result: it is answered `internal`, saying which.
|
|
128
|
+
*
|
|
129
|
+
* @param storage - Storage backend
|
|
130
|
+
* @param dispatch - Runs the call where the backend runs calls
|
|
131
|
+
* @param repo - The repository's name, which the dispatch takes
|
|
132
|
+
* @param repoPath - The repository's identifier, which the store takes
|
|
133
|
+
* @param workspace - The workspace the call is made through
|
|
134
|
+
* @param fnName - The function's name in the deployed package
|
|
135
|
+
* @param request - The arguments, and any runner and limits the caller names
|
|
136
|
+
* @param options - Who calls, their grant, the ceilings, the lifetimes and the
|
|
137
|
+
* host's sync deadline
|
|
138
|
+
* @returns The response: the call's result, or the error that stopped it
|
|
139
|
+
*/
|
|
140
|
+
export async function callFunctionInWorkspace(storage, dispatch, repo, repoPath, workspace, fnName, request, options) {
|
|
141
|
+
try {
|
|
142
|
+
const job = await functionCallStart(storage, repoPath, workspace, fnName, request, {
|
|
143
|
+
...filingOf(options),
|
|
144
|
+
sync: options.syncDeadlineMs === undefined ? {} : { deadlineMs: options.syncDeadlineMs },
|
|
145
|
+
});
|
|
146
|
+
const status = await runAndWait(storage, dispatch, repo, repoPath, job, job.deadline.getTime() + SYNC_GRACE_MS - Date.now());
|
|
147
|
+
switch (status.type) {
|
|
148
|
+
case 'completed':
|
|
149
|
+
return sendSuccess(ExecuteResultType, status.value);
|
|
150
|
+
case 'running':
|
|
151
|
+
// Its run stops it at its timeout, which is under the deadline, and
|
|
152
|
+
// records it timed out too
|
|
153
|
+
return sendSuccess(ExecuteResultType, {
|
|
154
|
+
outcome: variant('timed_out', { ms: job.call.limits.timeoutMs }),
|
|
155
|
+
stdout: '',
|
|
156
|
+
stderr: '',
|
|
157
|
+
stdoutTruncated: false,
|
|
158
|
+
stderrTruncated: false,
|
|
159
|
+
inputs: functionCallInputs(job),
|
|
160
|
+
});
|
|
161
|
+
case 'cancelled': {
|
|
162
|
+
const by = status.value.by.type === 'some' ? ` by ${status.value.by.value}` : '';
|
|
163
|
+
return sendError(ExecuteResultType, variant('internal', { message: `call ${job.call.id} was cancelled${by}, and has no result` }));
|
|
164
|
+
}
|
|
165
|
+
case 'lost':
|
|
166
|
+
return sendError(ExecuteResultType, variant('internal', { message: `call ${job.call.id} was lost: ${status.value.message}` }));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
catch (err) {
|
|
170
|
+
return sendError(ExecuteResultType, errorToVariant(err));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* A call's status, as its caller polls it, waiting up to `waitMs` for it to
|
|
175
|
+
* end.
|
|
176
|
+
*
|
|
177
|
+
* @remarks
|
|
178
|
+
* `running` until it ends; then its result, its value read back inline up to
|
|
179
|
+
* its `maxResultBytes`, or `cancelled` or `lost`. A call still recorded running
|
|
180
|
+
* past its deadline and a grace — its host stopped before it ended — is
|
|
181
|
+
* recorded `lost`, and answered so.
|
|
182
|
+
*
|
|
183
|
+
* @param storage - Storage backend
|
|
184
|
+
* @param dispatch - Runs the workspace's calls, and hears of their ends
|
|
185
|
+
* @param repo - The repository's name, which the dispatch takes
|
|
186
|
+
* @param repoPath - The repository's identifier, which the store takes
|
|
187
|
+
* @param workspace - The workspace the call was made through
|
|
188
|
+
* @param id - The call's id
|
|
189
|
+
* @param options - How long to wait, and whether the caller may read the call
|
|
190
|
+
* @returns The response: the status; or the error — `permission_denied`
|
|
191
|
+
* (`path` `call`) for a caller the host does not admit, and `internal` for a
|
|
192
|
+
* call the workspace does not keep: none was made, or its lifetime has ended
|
|
193
|
+
*/
|
|
194
|
+
export async function getFunctionCallStatus(storage, dispatch, repo, repoPath, workspace, id, options) {
|
|
195
|
+
try {
|
|
196
|
+
const job = await readCall(storage, repoPath, workspace, id, options.admit);
|
|
197
|
+
return sendSuccess(FunctionCallStatusType, await waitFor(storage, dispatch, repo, repoPath, job, Date.now() + options.waitMs));
|
|
198
|
+
}
|
|
199
|
+
catch (err) {
|
|
200
|
+
return sendError(FunctionCallStatusType, errorToVariant(err));
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Cancel a running call: record the request, tell the dispatch, and wait up to
|
|
205
|
+
* `waitMs` for the call to stop.
|
|
206
|
+
*
|
|
207
|
+
* @remarks
|
|
208
|
+
* The call's run stops its runner and records it `cancelled`, naming who
|
|
209
|
+
* asked: at once where the dispatch runs the call in its own process, and
|
|
210
|
+
* otherwise at the run's next look at its record. A call that has ended is
|
|
211
|
+
* left as it is, and answered with its status: a cancel changes nothing then.
|
|
212
|
+
*
|
|
213
|
+
* @param storage - Storage backend
|
|
214
|
+
* @param dispatch - Runs the workspace's calls, and stops them
|
|
215
|
+
* @param repo - The repository's name, which the dispatch takes
|
|
216
|
+
* @param repoPath - The repository's identifier, which the store takes
|
|
217
|
+
* @param workspace - The workspace the call was made through
|
|
218
|
+
* @param id - The call's id
|
|
219
|
+
* @param options - Who asks, how long to wait, and whether they may
|
|
220
|
+
* @returns The response: the call's status once it stopped, or `running`
|
|
221
|
+
* while it stops; or the error, as {@link getFunctionCallStatus} answers it
|
|
222
|
+
*/
|
|
223
|
+
export async function cancelFunctionCall(storage, dispatch, repo, repoPath, workspace, id, options) {
|
|
224
|
+
try {
|
|
225
|
+
const job = await readCall(storage, repoPath, workspace, id, options.admit);
|
|
226
|
+
if (job.call.state.type !== 'running') {
|
|
227
|
+
return sendSuccess(FunctionCallStatusType, await functionCallStatus(storage, repoPath, job));
|
|
228
|
+
}
|
|
229
|
+
const asked = await storage.calls.requestCancel(repoPath, workspace, id, {
|
|
230
|
+
by: options.by === null ? none : some(options.by),
|
|
231
|
+
at: new Date(),
|
|
232
|
+
});
|
|
233
|
+
if (asked === null)
|
|
234
|
+
throw noCall(workspace, id);
|
|
235
|
+
await dispatch.cancel(repo, workspace, id);
|
|
236
|
+
return sendSuccess(FunctionCallStatusType, await waitFor(storage, dispatch, repo, repoPath, asked, Date.now() + options.waitMs));
|
|
237
|
+
}
|
|
238
|
+
catch (err) {
|
|
239
|
+
return sendError(FunctionCallStatusType, errorToVariant(err));
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* A page of a workspace's kept calls, the latest first: each by who made it,
|
|
244
|
+
* when, and how it stands or ended.
|
|
245
|
+
*
|
|
246
|
+
* @remarks
|
|
247
|
+
* A call is kept for its lifetime, so the list holds the last hour's successes
|
|
248
|
+
* and the last week's failures, by default, however many calls are made: a
|
|
249
|
+
* client reads it a page at a time, passing a page's `next` as the next one's
|
|
250
|
+
* `before`. A page may hold fewer calls than its limit, or none, and name a
|
|
251
|
+
* next all the same: a store that reads a bounded number of calls a list, as
|
|
252
|
+
* the cloud's does, stops where its reads stopped. A call still recorded
|
|
253
|
+
* running past its deadline and a grace is recorded `lost` as the page passes
|
|
254
|
+
* it, as a read of it records it.
|
|
255
|
+
*
|
|
256
|
+
* @param storage - Storage backend
|
|
257
|
+
* @param repoPath - The repository's identifier
|
|
258
|
+
* @param workspace - The workspace
|
|
259
|
+
* @param query - The page's cursor and size, and only a function's calls, or
|
|
260
|
+
* only those in a state
|
|
261
|
+
* @returns The response: the page; or the error — `workspace_not_found` for a
|
|
262
|
+
* workspace there is not
|
|
263
|
+
*/
|
|
264
|
+
export async function listFunctionCalls(storage, repoPath, workspace, query = {}) {
|
|
265
|
+
try {
|
|
266
|
+
if (await storage.refs.workspaceRead(repoPath, workspace) === null)
|
|
267
|
+
throw new WorkspaceNotFoundError(workspace);
|
|
268
|
+
const limit = Math.min(query.limit ?? FUNCTION_CALLS_PAGE_DEFAULT, FUNCTION_CALLS_PAGE_MAX);
|
|
269
|
+
// The store says where the next page starts: a store that reads a bounded
|
|
270
|
+
// number of calls a list may stop short of the limit, and name a next
|
|
271
|
+
const page = await storage.calls.list(repoPath, workspace, {
|
|
272
|
+
limit,
|
|
273
|
+
...(query.before !== undefined && { before: query.before }),
|
|
274
|
+
...(query.function !== undefined && { function: query.function }),
|
|
275
|
+
...(query.state !== undefined && { state: query.state }),
|
|
276
|
+
});
|
|
277
|
+
const now = Date.now();
|
|
278
|
+
const calls = [];
|
|
279
|
+
for (const job of page.calls) {
|
|
280
|
+
const current = job.call.state.type === 'running' && now > job.deadline.getTime() + FUNCTION_CALL_GRACE_MS
|
|
281
|
+
? await functionCallRead(storage, repoPath, workspace, job.call.id, now)
|
|
282
|
+
: job;
|
|
283
|
+
if (current === null || (query.state !== undefined && current.call.state.type !== query.state))
|
|
284
|
+
continue;
|
|
285
|
+
calls.push(functionCallSummary(current));
|
|
286
|
+
}
|
|
287
|
+
return sendSuccess(FunctionCallPageType, { calls, next: page.next === undefined ? none : some(page.next) });
|
|
288
|
+
}
|
|
289
|
+
catch (err) {
|
|
290
|
+
return sendError(FunctionCallPageType, errorToVariant(err));
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* A kept call, whole: what it ran, its arguments, the versions of the inputs
|
|
295
|
+
* it read, its value by hash, its limits, its log tails and when it is
|
|
296
|
+
* forgotten.
|
|
297
|
+
*
|
|
298
|
+
* @param storage - Storage backend
|
|
299
|
+
* @param repoPath - The repository's identifier
|
|
300
|
+
* @param workspace - The workspace the call was made through
|
|
301
|
+
* @param id - The call's id
|
|
302
|
+
* @param admit - Whether the caller may read the call (default: any caller may)
|
|
303
|
+
* @returns The response: the call; or the error, as
|
|
304
|
+
* {@link getFunctionCallStatus} answers it
|
|
305
|
+
*/
|
|
306
|
+
export async function getFunctionCall(storage, repoPath, workspace, id, admit) {
|
|
307
|
+
try {
|
|
308
|
+
const job = await readCall(storage, repoPath, workspace, id, admit);
|
|
309
|
+
return sendSuccess(FunctionCallType, job.call);
|
|
310
|
+
}
|
|
311
|
+
catch (err) {
|
|
312
|
+
return sendError(FunctionCallType, errorToVariant(err));
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/** The options a filing takes, of a handler's. */
|
|
316
|
+
function filingOf(options) {
|
|
317
|
+
return {
|
|
318
|
+
caller: options.caller,
|
|
319
|
+
grant: options.grant,
|
|
320
|
+
...(options.ceilings !== undefined && { ceilings: options.ceilings }),
|
|
321
|
+
...(options.lifetimes !== undefined && { lifetimes: options.lifetimes }),
|
|
322
|
+
...(options.verbose !== undefined && { verbose: options.verbose }),
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Runs a filed call where the dispatch runs calls, and waits up to `waitMs` for
|
|
327
|
+
* it to end: the dispatch's word, or the store's. A call filed ended is
|
|
328
|
+
* answered as it ended; one the dispatch cannot hand on is recorded `lost`.
|
|
329
|
+
*/
|
|
330
|
+
async function runAndWait(storage, dispatch, repo, repoPath, job, waitMs) {
|
|
331
|
+
if (job.call.state.type !== 'running')
|
|
332
|
+
return functionCallStatus(storage, repoPath, job);
|
|
333
|
+
const until = Date.now() + Math.max(0, waitMs);
|
|
334
|
+
let heard;
|
|
335
|
+
try {
|
|
336
|
+
heard = await dispatch.execute(repo, job.workspace, job.call.id, { waitMs: Math.max(0, waitMs) });
|
|
337
|
+
}
|
|
338
|
+
catch (err) {
|
|
339
|
+
const lost = await functionCallLost(storage, repoPath, job, `the call could not be dispatched: ${err instanceof Error ? err.message : String(err)}`);
|
|
340
|
+
return functionCallStatus(storage, repoPath, lost);
|
|
341
|
+
}
|
|
342
|
+
if (heard !== null)
|
|
343
|
+
return heard;
|
|
344
|
+
return waitFor(storage, dispatch, repo, repoPath, job, until);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Waits until `until` for a call to end: the dispatch's word when it hears of
|
|
348
|
+
* the end, the store's otherwise, which it looks at every {@link LOOK_MS}.
|
|
349
|
+
*
|
|
350
|
+
* @returns The call's status: `running` when the time passed first
|
|
351
|
+
* @throws {Error} When the store keeps the call no longer
|
|
352
|
+
*/
|
|
353
|
+
async function waitFor(storage, dispatch, repo, repoPath, job, until) {
|
|
354
|
+
let current = job;
|
|
355
|
+
for (;;) {
|
|
356
|
+
if (current.call.state.type !== 'running')
|
|
357
|
+
return functionCallStatus(storage, repoPath, current);
|
|
358
|
+
const left = until - Date.now();
|
|
359
|
+
if (left <= 0)
|
|
360
|
+
return variant('running', null);
|
|
361
|
+
const heard = await dispatch.wait(repo, current.workspace, current.call.id, { waitMs: Math.min(left, LOOK_MS) });
|
|
362
|
+
if (heard !== null)
|
|
363
|
+
return heard;
|
|
364
|
+
const read = await functionCallRead(storage, repoPath, current.workspace, current.call.id);
|
|
365
|
+
if (read === null)
|
|
366
|
+
throw noCall(current.workspace, current.call.id);
|
|
367
|
+
current = read;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
/** Reads a kept call for a caller the host admits to it. */
|
|
371
|
+
async function readCall(storage, repoPath, workspace, id, admit) {
|
|
372
|
+
const job = await functionCallRead(storage, repoPath, workspace, id);
|
|
373
|
+
if (job === null)
|
|
374
|
+
throw noCall(workspace, id);
|
|
375
|
+
if (admit !== undefined && !(await admit(job.call)))
|
|
376
|
+
throw new PermissionDeniedError('call');
|
|
377
|
+
return job;
|
|
378
|
+
}
|
|
379
|
+
/** What answers a call the workspace does not keep, as an `internal` error. */
|
|
380
|
+
function noCall(workspace, id) {
|
|
381
|
+
return new Error(`workspace '${workspace}' keeps no call '${id}': none was made, or its lifetime has ended`);
|
|
382
|
+
}
|
|
383
|
+
//# sourceMappingURL=calls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calls.js","sourceRoot":"","sources":["../../../src/handlers/calls.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,2BAA2B,CAAC;AAKnC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EACL,iBAAiB,EACjB,2BAA2B,E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AC,IAAI,CAAC,CAAC;QAAE,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAC7F,OAAO,GAAG,CAAC;AACb,CAAC;AAED,+EAA+E;AAC/E,SAAS,MAAM,CAAC,SAAiB,EAAE,EAAU;IAC3C,OAAO,IAAI,KAAK,CAAC,cAAc,SAAS,oBAAoB,EAAE,6CAA6C,CAAC,CAAC;AAC/G,CAAC"}
|
|
@@ -14,9 +14,12 @@ export declare function listPackageFunctions(storage: StorageBackend, repoPath:
|
|
|
14
14
|
export declare function describePackageFunction(storage: StorageBackend, repoPath: string, pkgName: string, version: string, fnName: string): Promise<Response>;
|
|
15
15
|
/**
|
|
16
16
|
* Call a named function synchronously: resolve → validate arity → run →
|
|
17
|
-
* 200 ExecuteResult. The call's
|
|
18
|
-
* deadline, so the caller gets a structured
|
|
19
|
-
* transport cut.
|
|
17
|
+
* 200 ExecuteResult. The call's limits are held to the host's ceilings, and its
|
|
18
|
+
* timeout under the host's sync deadline too, so the caller gets a structured
|
|
19
|
+
* `timed_out` instead of a transport cut. It runs within the request, on
|
|
20
|
+
* `runner`, and keeps nothing: the package route's. A call through a
|
|
21
|
+
* workspace's routes is kept, and runs where the host runs calls
|
|
22
|
+
* (`callFunctionInWorkspace`).
|
|
20
23
|
*
|
|
21
24
|
* @remarks
|
|
22
25
|
* A call that names no runner runs the function on its own, whatever the
|
|
@@ -46,11 +49,14 @@ export declare function describePackageFunction(storage: StorageBackend, repoPat
|
|
|
46
49
|
* may give the function a platform package the function does not load:
|
|
47
50
|
* only `any` may (default `platform_free`)
|
|
48
51
|
* @param workspace - The workspace the call runs in, whose datasets its
|
|
49
|
-
* arguments may name
|
|
50
|
-
*
|
|
52
|
+
* arguments may name, for a host that calls a workspace's function within
|
|
53
|
+
* its request and keeps nothing; `null`, the default, for the package
|
|
54
|
+
* route's, which has none
|
|
55
|
+
* @param ceilings - The most the call may ask for (default: a server's, a
|
|
56
|
+
* 10-minute timeout, a 1 MiB result and 256 KiB of logs)
|
|
51
57
|
* @returns The call's result, or the error that stopped it
|
|
52
58
|
*/
|
|
53
|
-
export declare function callFunctionSync(storage: StorageBackend, repoPath: string, runner: TaskRunner, pkgName: string, version: string, fnName: string, req: FunctionCallRequest, verbose?: boolean, syncDeadlineMs?: number, grant?: OneShotGrant, workspace?: string | null): Promise<Response>;
|
|
59
|
+
export declare function callFunctionSync(storage: StorageBackend, repoPath: string, runner: TaskRunner, pkgName: string, version: string, fnName: string, req: FunctionCallRequest, verbose?: boolean, syncDeadlineMs?: number, grant?: OneShotGrant, workspace?: string | null, ceilings?: ExecuteCeilings): Promise<Response>;
|
|
54
60
|
/** Options for {@link startSplitCall}. */
|
|
55
61
|
export interface StartSplitCallOptions {
|
|
56
62
|
/** The most a request may ask for (default: a server's). */
|
|
@@ -67,8 +73,9 @@ export interface StartSplitCallOptions {
|
|
|
67
73
|
* The launch applies the caller's grant, pins the call's dataset arguments and
|
|
68
74
|
* writes what the job runs (e3-core `splitCallPrepare`), then files the job and
|
|
69
75
|
* dispatches it to the compute the store chooses. An explain launches the same
|
|
70
|
-
* way, and its job plans the pieces
|
|
71
|
-
*
|
|
76
|
+
* way, and its job plans the pieces as the run would, which a run that
|
|
77
|
+
* follows plans again, finding the pieces it stored: the request does no more
|
|
78
|
+
* than the launch's small writes. A request found
|
|
72
79
|
* wrong is filed as a job already `completed` with its `invalid` result, so
|
|
73
80
|
* every call's result, whatever it is, comes back through the poll. The job
|
|
74
81
|
* records whether a caller whose grant is `platform_free` may poll it
|
|
@@ -89,7 +96,7 @@ export interface StartSplitCallOptions {
|
|
|
89
96
|
export declare function startSplitCall(storage: StorageBackend, repoPath: string, repo: string, workspace: string, request: SplitCallRequest, grant: OneShotGrant, splitCallStore: SplitCallStore, options?: StartSplitCallOptions): Promise<Response>;
|
|
90
97
|
/**
|
|
91
98
|
* A split call's status: how far its job has got, its result, the pieces an
|
|
92
|
-
* explain planned,
|
|
99
|
+
* explain planned, why e3 could not run it, or that it was cancelled.
|
|
93
100
|
*
|
|
94
101
|
* @remarks
|
|
95
102
|
* A job's record holds hashes: a finished call's value is read from the store
|
|
@@ -114,4 +121,28 @@ export declare function startSplitCall(storage: StorageBackend, repoPath: string
|
|
|
114
121
|
* `internal` when this workspace launched no such job
|
|
115
122
|
*/
|
|
116
123
|
export declare function getSplitCallStatus(storage: StorageBackend, repoPath: string, splitCallStore: SplitCallStore, repo: string, workspace: string, id: string, grant: OneShotGrant): Promise<Response>;
|
|
124
|
+
/**
|
|
125
|
+
* Cancel a split call: a job still `processing` ends `cancelled`, and the
|
|
126
|
+
* job's processor stops its units once it finds it so; one that has ended is
|
|
127
|
+
* left as it is.
|
|
128
|
+
*
|
|
129
|
+
* @remarks
|
|
130
|
+
* Whoever may poll the job may cancel it, by the rule
|
|
131
|
+
* {@link getSplitCallStatus} polls by. The store writes the cancel only while
|
|
132
|
+
* the job runs, in one step with its check, so a cancel never overwrites a
|
|
133
|
+
* result, nor a result a cancel. The units that finished stay cached, so a
|
|
134
|
+
* relaunch is served them.
|
|
135
|
+
*
|
|
136
|
+
* @param storage - Storage backend
|
|
137
|
+
* @param repoPath - Repository identifier
|
|
138
|
+
* @param splitCallStore - Where the job is filed
|
|
139
|
+
* @param repo - The repository's name
|
|
140
|
+
* @param workspace - Workspace name
|
|
141
|
+
* @param id - The job's id
|
|
142
|
+
* @param grant - What the caller may run: the grant the host's auth gave it
|
|
143
|
+
* @returns The response: the job's status after the cancel, as a poll answers
|
|
144
|
+
* it — `cancelled`, or the status it had ended with; or the error, as
|
|
145
|
+
* {@link getSplitCallStatus} answers it
|
|
146
|
+
*/
|
|
147
|
+
export declare function cancelSplitCall(storage: StorageBackend, repoPath: string, splitCallStore: SplitCallStore, repo: string, workspace: string, id: string, grant: OneShotGrant): Promise<Response>;
|
|
117
148
|
//# sourceMappingURL=functions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../../../src/handlers/functions.ts"],"names":[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