@abyss-project/runtime 3.6.0 → 3.8.0
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/.eslintrc.js +32 -32
- package/.prettierrc +5 -5
- package/README.md +88 -88
- package/dist/engine/engine-source.js +1 -1
- package/dist/engine/run-in-isolate.js +37 -4
- package/dist/engine/run-in-isolate.js.map +1 -1
- package/dist/interpreter/interpreter.js +1 -0
- package/dist/interpreter/interpreter.js.map +1 -1
- package/dist/interpreter/interpreter.types.d.ts +1 -0
- package/dist/runner-protocol/execution-protocol.types.d.ts +3 -0
- package/dist/runner-protocol/execution-protocol.types.js +2 -1
- package/dist/runner-protocol/execution-protocol.types.js.map +1 -1
- package/jest.config.ts +11 -11
- package/package.json +10 -15
- package/scripts/build-engine.cjs +70 -70
- package/src/__tests__/engine-bundle.test.ts +121 -121
- package/src/__tests__/surface.test.ts +12 -1
- package/src/access/__tests__/host-match.test.ts +24 -24
- package/src/access/access.types.ts +25 -25
- package/src/access/host-match.ts +13 -13
- package/src/cost/__tests__/execution-cost.test.ts +196 -196
- package/src/cost/execution-cost.ts +186 -186
- package/src/definition/__tests__/validate-definition.test.ts +354 -354
- package/src/definition/definition.limits.ts +9 -9
- package/src/definition/definition.schema.ts +172 -172
- package/src/definition/definition.types.ts +171 -171
- package/src/definition/validate-definition.ts +206 -206
- package/src/definition/walk-steps.ts +44 -44
- package/src/discord/__tests__/discord-event-input.test.ts +89 -89
- package/src/discord/discord.types.ts +639 -639
- package/src/engine/__tests__/run-in-isolate.test.ts +56 -5
- package/src/engine/engine-entry.ts +3 -3
- package/src/engine/engine-global.ts +2 -2
- package/src/engine/run-in-isolate.ts +64 -6
- package/src/errors/runtime-error-code.enum.ts +37 -37
- package/src/index.ts +32 -32
- package/src/interpreter/__tests__/interpreter.test.ts +854 -854
- package/src/interpreter/__tests__/log-respond-resume.test.ts +271 -270
- package/src/interpreter/interpreter-error.ts +12 -12
- package/src/interpreter/interpreter.ts +483 -482
- package/src/interpreter/interpreter.types.ts +204 -202
- package/src/interpreter/sequence-path.ts +67 -67
- package/src/interpreter/test-host.ts +85 -85
- package/src/runner-protocol/evaluation.types.ts +21 -21
- package/src/runner-protocol/execution-protocol.types.ts +26 -3
- package/src/schedule/schedule.types.ts +100 -100
- package/src/server/__tests__/code-runner-session.test.ts +311 -311
- package/src/server/code-runner-error.ts +12 -12
- package/src/server/code-runner-session.ts +310 -310
- package/src/server/index.ts +11 -11
- package/src/steps/__tests__/global-references.test.ts +133 -133
- package/src/steps/execute-step.ts +186 -186
- package/src/steps/global-references.ts +48 -48
- package/src/steps/step-access.ts +56 -56
- package/src/steps/step-fields.ts +87 -87
- package/src/steps/value-source.ts +69 -69
- package/tsconfig.check.json +15 -15
- package/tsconfig.json +35 -35
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
import type { RuntimeDefinition } from '../definition/definition.types';
|
|
2
|
-
import { start, step } from './interpreter';
|
|
3
|
-
import { EffectType, RunEventType } from './interpreter.types';
|
|
4
|
-
import type {
|
|
5
|
-
Effect,
|
|
6
|
-
EvaluateEffect,
|
|
7
|
-
HostEffect,
|
|
8
|
-
HttpEffect,
|
|
9
|
-
HttpResponse,
|
|
10
|
-
LogEffect,
|
|
11
|
-
RespondEffect,
|
|
12
|
-
RunEvent,
|
|
13
|
-
RunOptions,
|
|
14
|
-
RunState,
|
|
15
|
-
StepResult,
|
|
16
|
-
WaitEffect,
|
|
17
|
-
} from './interpreter.types';
|
|
18
|
-
import type { EvaluationResult } from '../runner-protocol/evaluation.types';
|
|
19
|
-
|
|
20
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* How a simulated host answers each effect. `evaluate` is mandatory: the package evaluates no
|
|
24
|
-
* JavaScript. The other handlers default to an empty answer; `wait` always elapses at once,
|
|
25
|
-
* `log` and `respond` default to accepting the line or the response.
|
|
26
|
-
*/
|
|
27
|
-
export interface TestHostHandlers {
|
|
28
|
-
evaluate: (effect: EvaluateEffect) => MaybePromise<EvaluationResult[]>;
|
|
29
|
-
http?: (effect: HttpEffect) => MaybePromise<HttpResponse>;
|
|
30
|
-
host?: (effect: HostEffect) => MaybePromise<unknown>;
|
|
31
|
-
wait?: (effect: WaitEffect) => MaybePromise<void>;
|
|
32
|
-
log?: (effect: LogEffect) => MaybePromise<void>;
|
|
33
|
-
respond?: (effect: RespondEffect) => MaybePromise<void>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface TestRunResult {
|
|
37
|
-
state: RunState;
|
|
38
|
-
/** Every effect the interpreter emitted, in order. */
|
|
39
|
-
effects: Effect[];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const DEFAULT_HTTP_RESPONSE: HttpResponse = { status: 200, headers: {}, body: null };
|
|
43
|
-
|
|
44
|
-
const answer = async (effect: Effect, handlers: TestHostHandlers): Promise<RunEvent> => {
|
|
45
|
-
switch (effect.type) {
|
|
46
|
-
case EffectType.EVALUATE:
|
|
47
|
-
return { type: RunEventType.EVALUATED, results: await handlers.evaluate(effect) };
|
|
48
|
-
case EffectType.HTTP:
|
|
49
|
-
return {
|
|
50
|
-
type: RunEventType.HTTP_COMPLETED,
|
|
51
|
-
response: handlers.http ? await handlers.http(effect) : DEFAULT_HTTP_RESPONSE,
|
|
52
|
-
};
|
|
53
|
-
case EffectType.HOST:
|
|
54
|
-
return {
|
|
55
|
-
type: RunEventType.HOST_COMPLETED,
|
|
56
|
-
output: handlers.host ? await handlers.host(effect) : null,
|
|
57
|
-
};
|
|
58
|
-
case EffectType.WAIT:
|
|
59
|
-
await handlers.wait?.(effect);
|
|
60
|
-
return { type: RunEventType.WAIT_ELAPSED };
|
|
61
|
-
case EffectType.LOG:
|
|
62
|
-
await handlers.log?.(effect);
|
|
63
|
-
return { type: RunEventType.LOG_WRITTEN };
|
|
64
|
-
case EffectType.RESPOND:
|
|
65
|
-
await handlers.respond?.(effect);
|
|
66
|
-
return { type: RunEventType.RESPONSE_SENT };
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
/** Runs a definition to its end, answering every effect with `handlers` and executing nothing. */
|
|
71
|
-
export const runToCompletion = async (
|
|
72
|
-
definition: RuntimeDefinition,
|
|
73
|
-
input: unknown,
|
|
74
|
-
options: RunOptions,
|
|
75
|
-
handlers: TestHostHandlers,
|
|
76
|
-
): Promise<TestRunResult> => {
|
|
77
|
-
const effects: Effect[] = [];
|
|
78
|
-
let result: StepResult = start(definition, input, options);
|
|
79
|
-
while (result.effects.length > 0) {
|
|
80
|
-
const [effect] = result.effects;
|
|
81
|
-
effects.push(effect);
|
|
82
|
-
result = step(definition, result.state, await answer(effect, handlers), options);
|
|
83
|
-
}
|
|
84
|
-
return { state: result.state, effects };
|
|
85
|
-
};
|
|
1
|
+
import type { RuntimeDefinition } from '../definition/definition.types';
|
|
2
|
+
import { start, step } from './interpreter';
|
|
3
|
+
import { EffectType, RunEventType } from './interpreter.types';
|
|
4
|
+
import type {
|
|
5
|
+
Effect,
|
|
6
|
+
EvaluateEffect,
|
|
7
|
+
HostEffect,
|
|
8
|
+
HttpEffect,
|
|
9
|
+
HttpResponse,
|
|
10
|
+
LogEffect,
|
|
11
|
+
RespondEffect,
|
|
12
|
+
RunEvent,
|
|
13
|
+
RunOptions,
|
|
14
|
+
RunState,
|
|
15
|
+
StepResult,
|
|
16
|
+
WaitEffect,
|
|
17
|
+
} from './interpreter.types';
|
|
18
|
+
import type { EvaluationResult } from '../runner-protocol/evaluation.types';
|
|
19
|
+
|
|
20
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* How a simulated host answers each effect. `evaluate` is mandatory: the package evaluates no
|
|
24
|
+
* JavaScript. The other handlers default to an empty answer; `wait` always elapses at once,
|
|
25
|
+
* `log` and `respond` default to accepting the line or the response.
|
|
26
|
+
*/
|
|
27
|
+
export interface TestHostHandlers {
|
|
28
|
+
evaluate: (effect: EvaluateEffect) => MaybePromise<EvaluationResult[]>;
|
|
29
|
+
http?: (effect: HttpEffect) => MaybePromise<HttpResponse>;
|
|
30
|
+
host?: (effect: HostEffect) => MaybePromise<unknown>;
|
|
31
|
+
wait?: (effect: WaitEffect) => MaybePromise<void>;
|
|
32
|
+
log?: (effect: LogEffect) => MaybePromise<void>;
|
|
33
|
+
respond?: (effect: RespondEffect) => MaybePromise<void>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface TestRunResult {
|
|
37
|
+
state: RunState;
|
|
38
|
+
/** Every effect the interpreter emitted, in order. */
|
|
39
|
+
effects: Effect[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const DEFAULT_HTTP_RESPONSE: HttpResponse = { status: 200, headers: {}, body: null };
|
|
43
|
+
|
|
44
|
+
const answer = async (effect: Effect, handlers: TestHostHandlers): Promise<RunEvent> => {
|
|
45
|
+
switch (effect.type) {
|
|
46
|
+
case EffectType.EVALUATE:
|
|
47
|
+
return { type: RunEventType.EVALUATED, results: await handlers.evaluate(effect) };
|
|
48
|
+
case EffectType.HTTP:
|
|
49
|
+
return {
|
|
50
|
+
type: RunEventType.HTTP_COMPLETED,
|
|
51
|
+
response: handlers.http ? await handlers.http(effect) : DEFAULT_HTTP_RESPONSE,
|
|
52
|
+
};
|
|
53
|
+
case EffectType.HOST:
|
|
54
|
+
return {
|
|
55
|
+
type: RunEventType.HOST_COMPLETED,
|
|
56
|
+
output: handlers.host ? await handlers.host(effect) : null,
|
|
57
|
+
};
|
|
58
|
+
case EffectType.WAIT:
|
|
59
|
+
await handlers.wait?.(effect);
|
|
60
|
+
return { type: RunEventType.WAIT_ELAPSED };
|
|
61
|
+
case EffectType.LOG:
|
|
62
|
+
await handlers.log?.(effect);
|
|
63
|
+
return { type: RunEventType.LOG_WRITTEN };
|
|
64
|
+
case EffectType.RESPOND:
|
|
65
|
+
await handlers.respond?.(effect);
|
|
66
|
+
return { type: RunEventType.RESPONSE_SENT };
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/** Runs a definition to its end, answering every effect with `handlers` and executing nothing. */
|
|
71
|
+
export const runToCompletion = async (
|
|
72
|
+
definition: RuntimeDefinition,
|
|
73
|
+
input: unknown,
|
|
74
|
+
options: RunOptions,
|
|
75
|
+
handlers: TestHostHandlers,
|
|
76
|
+
): Promise<TestRunResult> => {
|
|
77
|
+
const effects: Effect[] = [];
|
|
78
|
+
let result: StepResult = start(definition, input, options);
|
|
79
|
+
while (result.effects.length > 0) {
|
|
80
|
+
const [effect] = result.effects;
|
|
81
|
+
effects.push(effect);
|
|
82
|
+
result = step(definition, result.state, await answer(effect, handlers), options);
|
|
83
|
+
}
|
|
84
|
+
return { state: result.state, effects };
|
|
85
|
+
};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import type { RuntimeErrorDetail } from '../errors/runtime-error-code.enum';
|
|
2
|
-
|
|
3
|
-
export enum EvaluationKind {
|
|
4
|
-
/** A full JavaScript expression. */
|
|
5
|
-
EXPRESSION = 'EXPRESSION',
|
|
6
|
-
/** A string with `{{ … }}` placeholders; a lone placeholder keeps its value's type. */
|
|
7
|
-
TEMPLATE = 'TEMPLATE',
|
|
8
|
-
/** JavaScript statements; the value of their `return` is the result. */
|
|
9
|
-
CODE = 'CODE',
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface EvaluationItem {
|
|
13
|
-
/** Unique within the step. */
|
|
14
|
-
id: string;
|
|
15
|
-
kind: EvaluationKind;
|
|
16
|
-
source: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type EvaluationResult =
|
|
20
|
-
| { id: string; ok: true; value: unknown }
|
|
21
|
-
| { id: string; ok: false; error: RuntimeErrorDetail };
|
|
1
|
+
import type { RuntimeErrorDetail } from '../errors/runtime-error-code.enum';
|
|
2
|
+
|
|
3
|
+
export enum EvaluationKind {
|
|
4
|
+
/** A full JavaScript expression. */
|
|
5
|
+
EXPRESSION = 'EXPRESSION',
|
|
6
|
+
/** A string with `{{ … }}` placeholders; a lone placeholder keeps its value's type. */
|
|
7
|
+
TEMPLATE = 'TEMPLATE',
|
|
8
|
+
/** JavaScript statements; the value of their `return` is the result. */
|
|
9
|
+
CODE = 'CODE',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface EvaluationItem {
|
|
13
|
+
/** Unique within the step. */
|
|
14
|
+
id: string;
|
|
15
|
+
kind: EvaluationKind;
|
|
16
|
+
source: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type EvaluationResult =
|
|
20
|
+
| { id: string; ok: true; value: unknown }
|
|
21
|
+
| { id: string; ok: false; error: RuntimeErrorDetail };
|
|
@@ -11,7 +11,17 @@ export const EXECUTION_PROTOCOL = 'abyss-runtime.v2';
|
|
|
11
11
|
/** Upper bound, in JSON bytes, on the arguments of one `call` and on the value of its result. */
|
|
12
12
|
export const MAX_CALL_PAYLOAD_BYTES = 1_048_576;
|
|
13
13
|
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Upper bound, in UTF-8 bytes of JSON, on the step output a `progress` message carries whole. Past
|
|
16
|
+
* it the message carries a preview of `MAX_PROGRESS_OUTPUT_CHARS` bytes and the real size.
|
|
17
|
+
*/
|
|
18
|
+
export const MAX_PROGRESS_OUTPUT_BYTES = 65_536;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Size, in UTF-8 bytes of JSON, of the preview a `progress` message carries for a step output over
|
|
22
|
+
* `MAX_PROGRESS_OUTPUT_BYTES` (cut on a character boundary, so never more than this many bytes).
|
|
23
|
+
* The name predates the byte unit and is kept: renaming a published export needs a major version.
|
|
24
|
+
*/
|
|
15
25
|
export const MAX_PROGRESS_OUTPUT_CHARS = 4_096;
|
|
16
26
|
|
|
17
27
|
/** Upper bound, in characters, on the `errorStack` of an outcome or a failed `progress`. */
|
|
@@ -191,11 +201,18 @@ export interface ProgressMessage {
|
|
|
191
201
|
/** On `finished`, measured by the runner. */
|
|
192
202
|
metrics?: StepMetrics;
|
|
193
203
|
/**
|
|
194
|
-
* On `finished` with SUCCEEDED: the step's output
|
|
195
|
-
*
|
|
204
|
+
* On `finished` with SUCCEEDED: the step's output whole when its JSON is at most
|
|
205
|
+
* `MAX_PROGRESS_OUTPUT_BYTES` bytes of UTF-8; past that, the first `MAX_PROGRESS_OUTPUT_CHARS`
|
|
206
|
+
* bytes of its JSON (a string, cut on a character boundary) with `outputTruncated` and
|
|
207
|
+
* `outputSizeBytes`.
|
|
196
208
|
*/
|
|
197
209
|
output?: unknown;
|
|
198
210
|
outputTruncated?: boolean;
|
|
211
|
+
/**
|
|
212
|
+
* With `outputTruncated`: the real size of the output's JSON, in UTF-8 bytes. Absent when the
|
|
213
|
+
* output could not be serialized (no preview either).
|
|
214
|
+
*/
|
|
215
|
+
outputSizeBytes?: number;
|
|
199
216
|
/** On `finished` with FAILED. */
|
|
200
217
|
errorCode?: RuntimeErrorCode;
|
|
201
218
|
/** On `finished` with FAILED by client code. */
|
|
@@ -223,6 +240,12 @@ export interface ExecutionOutcome {
|
|
|
223
240
|
errorLocation?: IExecutionErrorLocation;
|
|
224
241
|
/** FAILED by client code: at most `MAX_ERROR_STACK_CHARS` characters. */
|
|
225
242
|
errorStack?: string;
|
|
243
|
+
/**
|
|
244
|
+
* Lines not relayed to the host because of `budget.maxLogLines`, the single total: the LOG steps
|
|
245
|
+
* the interpreter skipped past the cap plus the `log.write` calls the runner answered without
|
|
246
|
+
* relaying (client code and engine). Counts this execution segment only. Absent when none.
|
|
247
|
+
*/
|
|
248
|
+
droppedLogLines?: number;
|
|
226
249
|
/** SUSPENDED: what to send back as `state` to resume. */
|
|
227
250
|
state?: RunState;
|
|
228
251
|
}
|
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
import type { JSONValue } from '../runner-protocol/execution-protocol.types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Host capabilities of the delayed runs of a Service. The host declares them in the execution's
|
|
5
|
-
* capabilities; client code reaches them through `abyss.schedule.<name>(...)`; every helper
|
|
6
|
-
* exists, and one whose capability is not granted rejects with an error naming the action to
|
|
7
|
-
* declare. The argument shapes below are the `args` of the `call`.
|
|
8
|
-
*/
|
|
9
|
-
export enum ScheduleCapability {
|
|
10
|
-
/** Schedules a run of a task after a delay. Arguments: `ScheduleAfterArgs`; result: `ScheduleResult`. */
|
|
11
|
-
SCHEDULE_AFTER = 'schedule.after',
|
|
12
|
-
/** Schedules a run of a task at a date. Arguments: `ScheduleAtArgs`; result: `ScheduleResult`. */
|
|
13
|
-
SCHEDULE_AT = 'schedule.at',
|
|
14
|
-
/** Cancels a pending delayed run. Arguments: `ScheduleCancelArgs`; result: `ScheduleCancelResult`. */
|
|
15
|
-
SCHEDULE_CANCEL = 'schedule.cancel',
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Codes of the errors `abyss.schedule.*` throws. The host fails the call with the message
|
|
20
|
-
* `<code>: <detail>` (or the bare code); the helper rethrows an `Error` named `ScheduleError`
|
|
21
|
-
* whose `code` is the code and whose `message` is the detail.
|
|
22
|
-
*/
|
|
23
|
-
export enum ScheduleErrorCode {
|
|
24
|
-
/** No task of that name in the version in service. */
|
|
25
|
-
SCHEDULE_TASK_UNKNOWN = 'SCHEDULE_TASK_UNKNOWN',
|
|
26
|
-
/** The due date is less than the minimal delay away, or beyond the horizon. */
|
|
27
|
-
SCHEDULE_HORIZON_EXCEEDED = 'SCHEDULE_HORIZON_EXCEEDED',
|
|
28
|
-
/** The Service already has as many pending delayed runs in this environment as its plan allows. */
|
|
29
|
-
SCHEDULE_LIMIT_REACHED = 'SCHEDULE_LIMIT_REACHED',
|
|
30
|
-
/** The attached payload is longer than allowed once serialized to JSON. */
|
|
31
|
-
SCHEDULE_PAYLOAD_TOO_LARGE = 'SCHEDULE_PAYLOAD_TOO_LARGE',
|
|
32
|
-
/** The arguments are malformed (delay not a number, date not ISO 8601, empty key...). */
|
|
33
|
-
SCHEDULE_INVALID = 'SCHEDULE_INVALID',
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Options shared by `abyss.schedule.after` and `abyss.schedule.at`. */
|
|
37
|
-
export interface ScheduleOptions {
|
|
38
|
-
/**
|
|
39
|
-
* Deduplication key: while a delayed run of the same task with the same key is pending in the
|
|
40
|
-
* environment, scheduling again returns that run's id with `deduplicated: true`.
|
|
41
|
-
* `abyss.schedule.cancel(key)` cancels the pending runs with that key across every task of the
|
|
42
|
-
* Service in the environment.
|
|
43
|
-
*/
|
|
44
|
-
key?: string;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface ScheduleAfterArgs extends ScheduleOptions {
|
|
48
|
-
/** Delay before the run, in seconds. */
|
|
49
|
-
seconds: number;
|
|
50
|
-
/** Name of the task of the Service to run. */
|
|
51
|
-
taskName: string;
|
|
52
|
-
/** Data handed to the run as `input.payload`. */
|
|
53
|
-
payload?: JSONValue;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface ScheduleAtArgs extends ScheduleOptions {
|
|
57
|
-
/** Due date, ISO 8601. */
|
|
58
|
-
at: string;
|
|
59
|
-
/** Name of the task of the Service to run. */
|
|
60
|
-
taskName: string;
|
|
61
|
-
/** Data handed to the run as `input.payload`. */
|
|
62
|
-
payload?: JSONValue;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface ScheduleCancelArgs {
|
|
66
|
-
/** The id `schedule.after` or `schedule.at` returned, or the deduplication key of the run. */
|
|
67
|
-
idOrKey: string;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export interface ScheduleResult {
|
|
71
|
-
/** Id of the delayed run. */
|
|
72
|
-
id: string;
|
|
73
|
-
/** True when a pending run with the same key already existed: its id is returned, nothing is added. */
|
|
74
|
-
deduplicated: boolean;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export interface ScheduleCancelResult {
|
|
78
|
-
/** False when no pending run matched (unknown, already run or already cancelled). */
|
|
79
|
-
cancelled: boolean;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** What started a scheduled run: a tick of the task's cron, or a delayed run. */
|
|
83
|
-
export enum ScheduledRunKind {
|
|
84
|
-
SCHEDULE = 'SCHEDULE',
|
|
85
|
-
DELAYED = 'DELAYED',
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/** The `input` of a function started by a task: a cron tick or a delayed run. */
|
|
89
|
-
export interface ScheduledRunInput {
|
|
90
|
-
kind: ScheduledRunKind;
|
|
91
|
-
task: { id: string; name: string };
|
|
92
|
-
/** When the run was due, ISO 8601. */
|
|
93
|
-
scheduledFor: string;
|
|
94
|
-
/** When this attempt started, ISO 8601. */
|
|
95
|
-
firedAt: string;
|
|
96
|
-
/** Attempt number, from 1. */
|
|
97
|
-
attempt: number;
|
|
98
|
-
/** The payload of a delayed run, when it has one. */
|
|
99
|
-
payload?: JSONValue;
|
|
100
|
-
}
|
|
1
|
+
import type { JSONValue } from '../runner-protocol/execution-protocol.types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Host capabilities of the delayed runs of a Service. The host declares them in the execution's
|
|
5
|
+
* capabilities; client code reaches them through `abyss.schedule.<name>(...)`; every helper
|
|
6
|
+
* exists, and one whose capability is not granted rejects with an error naming the action to
|
|
7
|
+
* declare. The argument shapes below are the `args` of the `call`.
|
|
8
|
+
*/
|
|
9
|
+
export enum ScheduleCapability {
|
|
10
|
+
/** Schedules a run of a task after a delay. Arguments: `ScheduleAfterArgs`; result: `ScheduleResult`. */
|
|
11
|
+
SCHEDULE_AFTER = 'schedule.after',
|
|
12
|
+
/** Schedules a run of a task at a date. Arguments: `ScheduleAtArgs`; result: `ScheduleResult`. */
|
|
13
|
+
SCHEDULE_AT = 'schedule.at',
|
|
14
|
+
/** Cancels a pending delayed run. Arguments: `ScheduleCancelArgs`; result: `ScheduleCancelResult`. */
|
|
15
|
+
SCHEDULE_CANCEL = 'schedule.cancel',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Codes of the errors `abyss.schedule.*` throws. The host fails the call with the message
|
|
20
|
+
* `<code>: <detail>` (or the bare code); the helper rethrows an `Error` named `ScheduleError`
|
|
21
|
+
* whose `code` is the code and whose `message` is the detail.
|
|
22
|
+
*/
|
|
23
|
+
export enum ScheduleErrorCode {
|
|
24
|
+
/** No task of that name in the version in service. */
|
|
25
|
+
SCHEDULE_TASK_UNKNOWN = 'SCHEDULE_TASK_UNKNOWN',
|
|
26
|
+
/** The due date is less than the minimal delay away, or beyond the horizon. */
|
|
27
|
+
SCHEDULE_HORIZON_EXCEEDED = 'SCHEDULE_HORIZON_EXCEEDED',
|
|
28
|
+
/** The Service already has as many pending delayed runs in this environment as its plan allows. */
|
|
29
|
+
SCHEDULE_LIMIT_REACHED = 'SCHEDULE_LIMIT_REACHED',
|
|
30
|
+
/** The attached payload is longer than allowed once serialized to JSON. */
|
|
31
|
+
SCHEDULE_PAYLOAD_TOO_LARGE = 'SCHEDULE_PAYLOAD_TOO_LARGE',
|
|
32
|
+
/** The arguments are malformed (delay not a number, date not ISO 8601, empty key...). */
|
|
33
|
+
SCHEDULE_INVALID = 'SCHEDULE_INVALID',
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Options shared by `abyss.schedule.after` and `abyss.schedule.at`. */
|
|
37
|
+
export interface ScheduleOptions {
|
|
38
|
+
/**
|
|
39
|
+
* Deduplication key: while a delayed run of the same task with the same key is pending in the
|
|
40
|
+
* environment, scheduling again returns that run's id with `deduplicated: true`.
|
|
41
|
+
* `abyss.schedule.cancel(key)` cancels the pending runs with that key across every task of the
|
|
42
|
+
* Service in the environment.
|
|
43
|
+
*/
|
|
44
|
+
key?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface ScheduleAfterArgs extends ScheduleOptions {
|
|
48
|
+
/** Delay before the run, in seconds. */
|
|
49
|
+
seconds: number;
|
|
50
|
+
/** Name of the task of the Service to run. */
|
|
51
|
+
taskName: string;
|
|
52
|
+
/** Data handed to the run as `input.payload`. */
|
|
53
|
+
payload?: JSONValue;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface ScheduleAtArgs extends ScheduleOptions {
|
|
57
|
+
/** Due date, ISO 8601. */
|
|
58
|
+
at: string;
|
|
59
|
+
/** Name of the task of the Service to run. */
|
|
60
|
+
taskName: string;
|
|
61
|
+
/** Data handed to the run as `input.payload`. */
|
|
62
|
+
payload?: JSONValue;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface ScheduleCancelArgs {
|
|
66
|
+
/** The id `schedule.after` or `schedule.at` returned, or the deduplication key of the run. */
|
|
67
|
+
idOrKey: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface ScheduleResult {
|
|
71
|
+
/** Id of the delayed run. */
|
|
72
|
+
id: string;
|
|
73
|
+
/** True when a pending run with the same key already existed: its id is returned, nothing is added. */
|
|
74
|
+
deduplicated: boolean;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface ScheduleCancelResult {
|
|
78
|
+
/** False when no pending run matched (unknown, already run or already cancelled). */
|
|
79
|
+
cancelled: boolean;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** What started a scheduled run: a tick of the task's cron, or a delayed run. */
|
|
83
|
+
export enum ScheduledRunKind {
|
|
84
|
+
SCHEDULE = 'SCHEDULE',
|
|
85
|
+
DELAYED = 'DELAYED',
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The `input` of a function started by a task: a cron tick or a delayed run. */
|
|
89
|
+
export interface ScheduledRunInput {
|
|
90
|
+
kind: ScheduledRunKind;
|
|
91
|
+
task: { id: string; name: string };
|
|
92
|
+
/** When the run was due, ISO 8601. */
|
|
93
|
+
scheduledFor: string;
|
|
94
|
+
/** When this attempt started, ISO 8601. */
|
|
95
|
+
firedAt: string;
|
|
96
|
+
/** Attempt number, from 1. */
|
|
97
|
+
attempt: number;
|
|
98
|
+
/** The payload of a delayed run, when it has one. */
|
|
99
|
+
payload?: JSONValue;
|
|
100
|
+
}
|