@gmitch215/folio 1.1.0 → 1.2.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/README.md +78 -810
- package/dist/boot.d.ts +1 -0
- package/dist/boot.js +1 -0
- package/dist/browser/index.d.ts +73 -0
- package/dist/browser/index.js +277 -0
- package/dist/browser.d.ts +1 -68
- package/dist/browser.js +1 -274
- package/dist/continuation.d.ts +1 -0
- package/dist/continuation.js +1 -0
- package/dist/{compiler.d.ts → execution/compiler.d.ts} +1 -1
- package/dist/{compiler.js → execution/compiler.js} +5 -12
- package/dist/{coordinator.d.ts → execution/coordinator.d.ts} +1 -1
- package/dist/{coordinator.js → execution/coordinator.js} +5 -5
- package/dist/{extract.d.ts → execution/extract.d.ts} +3 -13
- package/dist/{extract.js → execution/extract.js} +7 -8
- package/dist/{fold.d.ts → execution/fold.d.ts} +15 -3
- package/dist/{guards.d.ts → execution/guards.d.ts} +2 -1
- package/dist/execution/types.d.ts +221 -0
- package/dist/{affine-state.d.ts → folds/affine-state.d.ts} +18 -47
- package/dist/{affine-state.js → folds/affine-state.js} +18 -44
- package/dist/{affine.d.ts → folds/affine.d.ts} +12 -24
- package/dist/{affine.js → folds/affine.js} +8 -17
- package/dist/{boundaries.d.ts → folds/boundaries.d.ts} +7 -18
- package/dist/{boundaries.js → folds/boundaries.js} +5 -13
- package/dist/{certified.d.ts → folds/certified.d.ts} +13 -24
- package/dist/{certified.js → folds/certified.js} +12 -26
- package/dist/{certify.d.ts → folds/certify.d.ts} +11 -22
- package/dist/{certify.js → folds/certify.js} +24 -41
- package/dist/{memo.d.ts → footprints/memo.d.ts} +8 -33
- package/dist/{memo.js → footprints/memo.js} +8 -2
- package/dist/{ranges.js → footprints/ranges.js} +1 -1
- package/dist/{read-scan.js → footprints/read-scan.js} +1 -1
- package/dist/{read-windows.d.ts → footprints/read-windows.d.ts} +6 -32
- package/dist/{read-windows.js → footprints/read-windows.js} +8 -7
- package/dist/index.d.ts +16 -4
- package/dist/index.js +14 -2
- package/dist/{iteration-admission.d.ts → iteration/admission.d.ts} +2 -38
- package/dist/{iteration.d.ts → iteration/index.d.ts} +8 -98
- package/dist/{iteration.js → iteration/index.js} +28 -28
- package/dist/{inline.js → iteration/inline.js} +2 -9
- package/dist/{iteration-owner.d.ts → iteration/owner.d.ts} +3 -3
- package/dist/{iteration-owner.js → iteration/owner.js} +4 -3
- package/dist/{iteration-worker.js → iteration/worker.js} +3 -3
- package/dist/{managed.d.ts → managed/index.d.ts} +3 -3
- package/dist/{managed.js → managed/index.js} +7 -9
- package/dist/managed/outbox.d.ts +128 -0
- package/dist/managed/outbox.js +156 -0
- package/dist/managed/pool.d.ts +221 -0
- package/dist/managed/pool.js +310 -0
- package/dist/managed/tasks.d.ts +154 -0
- package/dist/managed/tasks.js +183 -0
- package/dist/{bake.d.ts → memory/bake.d.ts} +12 -6
- package/dist/{bake.js → memory/bake.js} +9 -7
- package/dist/memory/continuation.d.ts +141 -0
- package/dist/memory/continuation.js +495 -0
- package/dist/memory/elastic-peer.d.ts +20 -0
- package/dist/memory/elastic-peer.js +39 -0
- package/dist/memory/elastic-sql.d.ts +11 -0
- package/dist/memory/elastic-sql.js +35 -0
- package/dist/memory/elastic.d.ts +130 -0
- package/dist/memory/elastic.js +475 -0
- package/dist/memory/growth-governor.d.ts +16 -0
- package/dist/memory/growth-governor.js +42 -0
- package/dist/memory/imports.d.ts +10 -0
- package/dist/memory/imports.js +89 -0
- package/dist/{iteration-layout.d.ts → memory/iteration-layout.d.ts} +1 -1
- package/dist/{pages.d.ts → memory/pages.d.ts} +3 -3
- package/dist/memory.d.ts +5 -10
- package/dist/memory.js +5 -89
- package/dist/{context.d.ts → node/context.d.ts} +1 -1
- package/dist/{host.d.ts → node/host.d.ts} +1 -1
- package/dist/{host.js → node/host.js} +2 -2
- package/dist/{node.d.ts → node/index.d.ts} +4 -49
- package/dist/{node.js → node/index.js} +16 -17
- package/dist/{tasks.d.ts → node/tasks.d.ts} +2 -13
- package/dist/{worker.js → node/worker.js} +2 -2
- package/dist/{ownership.js → ownership/index.js} +7 -10
- package/dist/{ownership-redirect.d.ts → ownership/redirect.d.ts} +2 -2
- package/dist/{ownership-redirect.js → ownership/redirect.js} +2 -2
- package/dist/{ownership-slices.d.ts → ownership/slices.d.ts} +3 -3
- package/dist/{ownership-slices.js → ownership/slices.js} +3 -3
- package/dist/{frames.d.ts → remote/frames.d.ts} +1 -1
- package/dist/{frames.js → remote/frames.js} +2 -2
- package/dist/{remote.d.ts → remote/index.d.ts} +7 -2
- package/dist/{remote.js → remote/index.js} +7 -2
- package/dist/{router.d.ts → routing/index.d.ts} +3 -3
- package/dist/{router.js → routing/index.js} +19 -15
- package/dist/{router-worker.js → routing/worker.js} +1 -1
- package/dist/{slices.d.ts → slices/index.d.ts} +2 -2
- package/dist/{slices.js → slices/index.js} +5 -5
- package/dist/slices/worker.d.ts +1 -0
- package/dist/{slices-worker.js → slices/worker.js} +2 -2
- package/dist/workers.d.ts +5 -0
- package/dist/workers.js +5 -0
- package/package.json +30 -80
- /package/dist/{browser-worker.d.ts → browser/worker.d.ts} +0 -0
- /package/dist/{browser-worker.js → browser/worker.js} +0 -0
- /package/dist/{fold.js → execution/fold.js} +0 -0
- /package/dist/{guards.js → execution/guards.js} +0 -0
- /package/dist/{import-order.d.ts → execution/import-order.d.ts} +0 -0
- /package/dist/{import-order.js → execution/import-order.js} +0 -0
- /package/dist/{runs.d.ts → execution/runs.d.ts} +0 -0
- /package/dist/{runs.js → execution/runs.js} +0 -0
- /package/dist/{transaction.d.ts → execution/transaction.d.ts} +0 -0
- /package/dist/{transaction.js → execution/transaction.js} +0 -0
- /package/dist/{iteration-worker.d.ts → execution/types.js} +0 -0
- /package/dist/{ranges.d.ts → footprints/ranges.d.ts} +0 -0
- /package/dist/{read-scan.d.ts → footprints/read-scan.d.ts} +0 -0
- /package/dist/{iteration-admission.js → iteration/admission.js} +0 -0
- /package/dist/{inline.d.ts → iteration/inline.d.ts} +0 -0
- /package/dist/{worker.d.ts → iteration/worker.d.ts} +0 -0
- /package/dist/{iteration-layout.js → memory/iteration-layout.js} +0 -0
- /package/dist/{lease.d.ts → memory/lease.d.ts} +0 -0
- /package/dist/{lease.js → memory/lease.js} +0 -0
- /package/dist/{pages.js → memory/pages.js} +0 -0
- /package/dist/{context.js → node/context.js} +0 -0
- /package/dist/{tasks.js → node/tasks.js} +0 -0
- /package/dist/{router-worker.d.ts → node/worker.d.ts} +0 -0
- /package/dist/{ownership.d.ts → ownership/index.d.ts} +0 -0
- /package/dist/{values.d.ts → remote/values.d.ts} +0 -0
- /package/dist/{values.js → remote/values.js} +0 -0
- /package/dist/{slices-worker.d.ts → routing/worker.d.ts} +0 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { TaskTable } from "./tasks.js";
|
|
2
|
+
/** Thrown by an effect to end its row as `failed` with no retry. */
|
|
3
|
+
export class PermanentError extends Error {
|
|
4
|
+
constructor(message, options) {
|
|
5
|
+
super(message, options);
|
|
6
|
+
this.name = 'PermanentError';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
const minLeaseMs = 5000;
|
|
10
|
+
const isValue = (value) => typeof value === 'string' || value instanceof Uint8Array;
|
|
11
|
+
const message = (error) => (error instanceof Error ? error.message : String(error)).slice(0, 1000);
|
|
12
|
+
/**
|
|
13
|
+
* A durable outbox for effects that must not be lost or repeated without notice: mail, outbound
|
|
14
|
+
* requests, Redis commands, cron units. Rows live in the task table of the object's own SQLite.
|
|
15
|
+
*
|
|
16
|
+
* Each row goes through four steps in this order: claim, flush, effect, complete, flush. The
|
|
17
|
+
* flush after the claim is what gives `report` its meaning. A reset after it leaves a running
|
|
18
|
+
* row that a successor knows may have run its effect, and the successor ends it as `failed`
|
|
19
|
+
* instead of running it again. A reset before it loses the claim, and nothing ran. The flush
|
|
20
|
+
* after the completion keeps a finished effect from being replayed after a reset.
|
|
21
|
+
*
|
|
22
|
+
* So a `resend` kind runs its effect at least once and a `report` kind at most once. A reported
|
|
23
|
+
* row is the operator's: it is final, and sending the effect again means a new id.
|
|
24
|
+
*/
|
|
25
|
+
export class Outbox {
|
|
26
|
+
/** The task table, for callers that read rows directly. */
|
|
27
|
+
table;
|
|
28
|
+
#effect;
|
|
29
|
+
#policies;
|
|
30
|
+
#flush;
|
|
31
|
+
#clock;
|
|
32
|
+
#leaseMs;
|
|
33
|
+
#width;
|
|
34
|
+
constructor(sql, options) {
|
|
35
|
+
const { leaseMs = 15000, width = 1 } = options;
|
|
36
|
+
if (typeof options.effect !== 'function')
|
|
37
|
+
throw new TypeError('effect must be a function');
|
|
38
|
+
if (!Number.isInteger(leaseMs) || leaseMs < minLeaseMs)
|
|
39
|
+
throw new RangeError(`leaseMs must be an integer of at least ${minLeaseMs}`);
|
|
40
|
+
if (!Number.isInteger(width) || width < 1)
|
|
41
|
+
throw new RangeError('width must be a positive integer');
|
|
42
|
+
for (const [kind, policy] of Object.entries(options.policies ?? {}))
|
|
43
|
+
if (policy !== 'resend' && policy !== 'report')
|
|
44
|
+
throw new TypeError(`the policy of ${kind} must be resend or report`);
|
|
45
|
+
this.#policies = { ...options.policies };
|
|
46
|
+
this.table = new TaskTable(sql, { table: options.table, maxAttempts: options.maxAttempts });
|
|
47
|
+
this.#effect = options.effect;
|
|
48
|
+
this.#flush = options.flush ?? (async () => { });
|
|
49
|
+
this.#clock = options.clock ?? { now: () => Date.now() };
|
|
50
|
+
this.#leaseMs = leaseMs;
|
|
51
|
+
this.#width = width;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Adds rows and returns how many were new, once they are flushed. An id that exists is
|
|
55
|
+
* ignored, so repeating an enqueue that failed is safe.
|
|
56
|
+
*/
|
|
57
|
+
async enqueue(items) {
|
|
58
|
+
let added = 0;
|
|
59
|
+
for (const item of items) {
|
|
60
|
+
if (typeof item.id !== 'string' || !item.id)
|
|
61
|
+
throw new TypeError('a row needs an id');
|
|
62
|
+
if (typeof item.kind !== 'string' || !item.kind)
|
|
63
|
+
throw new TypeError(`row ${item.id} needs a kind`);
|
|
64
|
+
if (item.args !== undefined && item.argsJson !== undefined)
|
|
65
|
+
throw new TypeError('pass args or argsJson, not both');
|
|
66
|
+
const args = item.argsJson === undefined ? (item.args ?? '') : JSON.stringify(item.argsJson);
|
|
67
|
+
if (!isValue(args))
|
|
68
|
+
throw new TypeError(`args of row ${item.id} must be a string or bytes`);
|
|
69
|
+
if (this.table.enqueue(item.id, item.kind, args, item.kind))
|
|
70
|
+
added++;
|
|
71
|
+
}
|
|
72
|
+
await this.#flush();
|
|
73
|
+
return added;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Runs every row that is ready, `width` at a time, and returns what happened. A row whose
|
|
77
|
+
* effect threw waits for the next `drain` instead of running again at once. Rows whose lease
|
|
78
|
+
* ended are replayed or reported by their kind first.
|
|
79
|
+
*/
|
|
80
|
+
async drain() {
|
|
81
|
+
const report = { done: 0, failed: 0, retried: 0, reported: 0 };
|
|
82
|
+
const attempted = [];
|
|
83
|
+
for (;;) {
|
|
84
|
+
const now = this.#clock.now();
|
|
85
|
+
report.reported += this.table.reportLost(now, this.#policies);
|
|
86
|
+
report.failed += this.table.expire(now);
|
|
87
|
+
const rows = this.table.claim(now, this.#leaseMs, this.#width, {
|
|
88
|
+
policies: this.#policies,
|
|
89
|
+
skip: attempted
|
|
90
|
+
});
|
|
91
|
+
await this.#flush();
|
|
92
|
+
if (!rows.length)
|
|
93
|
+
return report;
|
|
94
|
+
attempted.push(...rows.map((row) => row.id));
|
|
95
|
+
await Promise.all(rows.map((row) => this.#run(row, report)));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* One pass for an alarm: `drain`, then when to call again. `wake` is at least 5 s ahead and
|
|
100
|
+
* never before the soonest lease ends, and it is unset when no row is open.
|
|
101
|
+
*/
|
|
102
|
+
async resume() {
|
|
103
|
+
const report = await this.drain();
|
|
104
|
+
const now = this.#clock.now();
|
|
105
|
+
const open = this.table.pending(now);
|
|
106
|
+
return {
|
|
107
|
+
...report,
|
|
108
|
+
...(open.open === 0 ? {} : { wake: Math.max(open.nextExpiry ?? 0, now + minLeaseMs) })
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/** Every row in id order, whatever its state. */
|
|
112
|
+
results() {
|
|
113
|
+
return this.table.snapshot();
|
|
114
|
+
}
|
|
115
|
+
async #run(row, report) {
|
|
116
|
+
let timer;
|
|
117
|
+
let outcome;
|
|
118
|
+
try {
|
|
119
|
+
const pending = this.#effect({
|
|
120
|
+
id: row.id,
|
|
121
|
+
kind: row.kind ?? '',
|
|
122
|
+
attempt: row.attempt,
|
|
123
|
+
key: row.id,
|
|
124
|
+
args: row.args
|
|
125
|
+
});
|
|
126
|
+
let value = pending;
|
|
127
|
+
if (typeof pending?.then === 'function') {
|
|
128
|
+
timer = setInterval(() => this.table.renew(row.id, row.attempt, this.#clock.now(), this.#leaseMs), Math.max(1000, Math.floor(this.#leaseMs / 3)));
|
|
129
|
+
value = await pending;
|
|
130
|
+
}
|
|
131
|
+
// a result of the wrong type is a bug in the effect, and running it again would repeat the effect
|
|
132
|
+
if (value !== undefined && !isValue(value))
|
|
133
|
+
throw new PermanentError(`effect of kind ${row.kind} returned neither text, bytes nor nothing`);
|
|
134
|
+
outcome = { value: value ?? '' };
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
outcome = { error };
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
clearInterval(timer);
|
|
141
|
+
}
|
|
142
|
+
if ('value' in outcome) {
|
|
143
|
+
const completion = this.table.complete(row.id, row.attempt, outcome.value);
|
|
144
|
+
await this.#flush();
|
|
145
|
+
if (completion !== 'ignored')
|
|
146
|
+
report.done++;
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const failure = this.table.fail(row.id, row.attempt, message(outcome.error), outcome.error instanceof PermanentError);
|
|
150
|
+
await this.#flush();
|
|
151
|
+
if (failure === 'retry')
|
|
152
|
+
report.retried++;
|
|
153
|
+
else if (failure === 'failed')
|
|
154
|
+
report.failed++;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import type { SqlStorage } from '../memory/continuation.ts';
|
|
2
|
+
import type { CompletionOutcome, FailureOutcome, TaskState, TaskValue } from './tasks.ts';
|
|
3
|
+
import { TaskTable } from './tasks.ts';
|
|
4
|
+
/** A task a lane claimed. */
|
|
5
|
+
export interface LaneTask {
|
|
6
|
+
/** The task id. */
|
|
7
|
+
id: string;
|
|
8
|
+
/** The registry key to run. */
|
|
9
|
+
name: string;
|
|
10
|
+
/** The arguments as submitted, text or bytes. */
|
|
11
|
+
args: TaskValue;
|
|
12
|
+
/** The claim number of this task; a replay gets the next one. */
|
|
13
|
+
attempt: number;
|
|
14
|
+
/** The lease the claim granted, in milliseconds. */
|
|
15
|
+
leaseMs: number;
|
|
16
|
+
}
|
|
17
|
+
/** A claimed task named by id and attempt. */
|
|
18
|
+
export interface LaneHold {
|
|
19
|
+
/** The task id. */
|
|
20
|
+
id: string;
|
|
21
|
+
/** The claim number the lane holds. */
|
|
22
|
+
attempt: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* What a lane calls on the coordinator. `LanePool` implements it, and a Durable Object stub that
|
|
26
|
+
* forwards the four methods to a pool satisfies it.
|
|
27
|
+
*/
|
|
28
|
+
export interface LaneCoordinator {
|
|
29
|
+
/** Claims up to `claimBatch` tasks, or none when nothing is ready. */
|
|
30
|
+
claim(): Promise<LaneTask[]>;
|
|
31
|
+
/** Writes a result. The first completion of an id wins. */
|
|
32
|
+
complete(id: string, attempt: number, result: TaskValue): Promise<CompletionOutcome>;
|
|
33
|
+
/** Records an error from an attempt. */
|
|
34
|
+
fail(id: string, attempt: number, error: string): Promise<FailureOutcome>;
|
|
35
|
+
/** Extends the leases of tasks the lane still holds; false marks a task that is no longer its own. */
|
|
36
|
+
renew(holds: readonly LaneHold[]): Promise<boolean[]>;
|
|
37
|
+
}
|
|
38
|
+
/** Runs one named task. Return the result, or a promise of it; a throw fails the attempt. */
|
|
39
|
+
export type TaskFunction = (args: TaskValue, task: LaneTask) => TaskValue | Promise<TaskValue>;
|
|
40
|
+
/** The tasks a lane can run, by name. */
|
|
41
|
+
export type TaskRegistry = Record<string, TaskFunction>;
|
|
42
|
+
/** What one `work` call did. */
|
|
43
|
+
export interface LaneWorked {
|
|
44
|
+
/** Tasks the lane claimed. */
|
|
45
|
+
claimed: number;
|
|
46
|
+
/** Tasks it finished and reported done. */
|
|
47
|
+
completed: number;
|
|
48
|
+
/** Tasks it reported as failed. */
|
|
49
|
+
failed: number;
|
|
50
|
+
}
|
|
51
|
+
/** How the coordinator reaches a lane. */
|
|
52
|
+
export interface LaneTransport {
|
|
53
|
+
/**
|
|
54
|
+
* Asks lane `lane` (0 up to `width - 1`) to work the queue. Resolves when the lane's claim
|
|
55
|
+
* comes back empty. Reject, or time out, when the lane stops answering: a call that never
|
|
56
|
+
* settles keeps its lane busy for the life of the pool.
|
|
57
|
+
*/
|
|
58
|
+
work(lane: number): Promise<unknown>;
|
|
59
|
+
/** Releases the lanes' connections or objects. */
|
|
60
|
+
close?(): Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
/** Time for the pool. `sleep` resolves after `ms`, or as soon as the signal aborts. */
|
|
63
|
+
export interface LaneClock {
|
|
64
|
+
/** Milliseconds on any clock the pool and its lanes agree on. */
|
|
65
|
+
now(): number;
|
|
66
|
+
/** Resolves after `ms`, or when `signal` aborts. */
|
|
67
|
+
sleep(ms: number, signal?: AbortSignal): Promise<void>;
|
|
68
|
+
}
|
|
69
|
+
/** A task to submit. Pass `args` or `argsJson`, not both. */
|
|
70
|
+
export interface TaskSpec {
|
|
71
|
+
/** Unique id. Results come back in the byte order of the id. */
|
|
72
|
+
id: string;
|
|
73
|
+
/** Key into the lane's registry. */
|
|
74
|
+
name: string;
|
|
75
|
+
/** The arguments, text or bytes. */
|
|
76
|
+
args?: TaskValue;
|
|
77
|
+
/** Serialized with `JSON.stringify` into `args`. */
|
|
78
|
+
argsJson?: unknown;
|
|
79
|
+
}
|
|
80
|
+
/** One task's outcome. */
|
|
81
|
+
export interface LaneResult {
|
|
82
|
+
/** The task id. */
|
|
83
|
+
id: string;
|
|
84
|
+
/** The registry key that ran. */
|
|
85
|
+
name: string;
|
|
86
|
+
/** Where the task ended up. */
|
|
87
|
+
state: TaskState;
|
|
88
|
+
/** Claims the task took. */
|
|
89
|
+
attempt: number;
|
|
90
|
+
/** The raw result, once the task is done. */
|
|
91
|
+
value?: TaskValue;
|
|
92
|
+
/** The last error, for a failed task. */
|
|
93
|
+
error?: string;
|
|
94
|
+
/** The result as text. Throws unless the task is done. */
|
|
95
|
+
text(): string;
|
|
96
|
+
/** The result parsed as JSON. Throws unless the task is done. */
|
|
97
|
+
json<T = unknown>(): T;
|
|
98
|
+
}
|
|
99
|
+
/** The state of the pool after a `run` or a `resume`. */
|
|
100
|
+
export interface LaneReport {
|
|
101
|
+
/** Tasks waiting to be claimed. */
|
|
102
|
+
queued: number;
|
|
103
|
+
/** Tasks claimed and not yet reported. */
|
|
104
|
+
running: number;
|
|
105
|
+
/** Tasks with a result. */
|
|
106
|
+
done: number;
|
|
107
|
+
/** Tasks that ran out of attempts. */
|
|
108
|
+
failed: number;
|
|
109
|
+
/** Lane calls made since the pool was built. */
|
|
110
|
+
kicks: number;
|
|
111
|
+
/** Lane calls that rejected. */
|
|
112
|
+
laneErrors: number;
|
|
113
|
+
/** When to call `resume` again, in clock time, at least the 5 s alarm floor ahead. Unset when nothing is open. */
|
|
114
|
+
wake?: number;
|
|
115
|
+
}
|
|
116
|
+
/** Options for `LanePool`. */
|
|
117
|
+
export interface LanePoolOptions {
|
|
118
|
+
/** How lanes are called. */
|
|
119
|
+
transport: LaneTransport;
|
|
120
|
+
/** Lanes to use at once. */
|
|
121
|
+
width: number;
|
|
122
|
+
/**
|
|
123
|
+
* Lease granted to a claim, in milliseconds. Default 15,000, minimum 5,000. The alarm that
|
|
124
|
+
* calls `resume` cannot be set closer than 5 s, so a shorter lease could not be enforced
|
|
125
|
+
* sooner than that anyway. Only a task that awaits renews its lease; a synchronous task has to
|
|
126
|
+
* finish inside it.
|
|
127
|
+
*/
|
|
128
|
+
leaseMs?: number;
|
|
129
|
+
/** Executions a task may start before it fails. Default 3. */
|
|
130
|
+
maxAttempts?: number;
|
|
131
|
+
/** Tasks a lane claims per call. Default 1. */
|
|
132
|
+
claimBatch?: number;
|
|
133
|
+
/** Time source. Defaults to `Date.now` and timers. */
|
|
134
|
+
clock?: LaneClock;
|
|
135
|
+
/** SQL identifier of the task table. Default `folio_tasks`. */
|
|
136
|
+
table?: string;
|
|
137
|
+
/**
|
|
138
|
+
* Resolves once every earlier write survives a reset; pass `() => ctx.storage.sync()` inside a
|
|
139
|
+
* Durable Object. The pool awaits it after `submit`, after a claim before the tasks reach the
|
|
140
|
+
* lane, and after a completion before it is acknowledged. Without it the pool trusts the
|
|
141
|
+
* storage to be durable at each await.
|
|
142
|
+
*/
|
|
143
|
+
flush?: () => Promise<void>;
|
|
144
|
+
}
|
|
145
|
+
/** A pool that cannot finish. `code` is `failed` (a task failed), `unfinished` or `stalled` (no lane claims). */
|
|
146
|
+
export declare class LanePoolError extends Error {
|
|
147
|
+
/** Why the pool could not finish. */
|
|
148
|
+
readonly code: 'failed' | 'unfinished' | 'stalled';
|
|
149
|
+
constructor(code: 'failed' | 'unfinished' | 'stalled', detail: string, cause?: unknown);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The coordinator side of a durable lane pool. Tasks are rows in the object's own SQLite, lanes
|
|
153
|
+
* on other objects claim them by RPC, and a lane that resets loses only the tasks it was
|
|
154
|
+
* running: their leases end and the next claim replays them. A coordinator that resets loses
|
|
155
|
+
* only the transitions since its last flush; build a new pool over the same storage and call
|
|
156
|
+
* `run` or `resume`.
|
|
157
|
+
*
|
|
158
|
+
* A write is durable once an await or a flush has passed it, so the pool flushes after the three
|
|
159
|
+
* transitions that must survive (enqueue, claim, complete) and before anything depends on them.
|
|
160
|
+
* A failure report, a lease renewal and the expiry of a lease are not flushed: losing one only
|
|
161
|
+
* brings the same replay that a lane reset brings.
|
|
162
|
+
*
|
|
163
|
+
* Each id's result is written once. A task body runs at least once, so the result is exactly
|
|
164
|
+
* once in the table and effectively once for a task whose body is deterministic or idempotent.
|
|
165
|
+
*/
|
|
166
|
+
export declare class LanePool implements LaneCoordinator {
|
|
167
|
+
#private;
|
|
168
|
+
/** The task table, for callers that read rows directly. */
|
|
169
|
+
readonly table: TaskTable;
|
|
170
|
+
constructor(sql: SqlStorage, options: LanePoolOptions);
|
|
171
|
+
/**
|
|
172
|
+
* Adds tasks and returns how many were new, once they are flushed. An id that exists is
|
|
173
|
+
* ignored, so repeating a submit that failed is safe.
|
|
174
|
+
*/
|
|
175
|
+
submit(tasks: readonly TaskSpec[]): Promise<number>;
|
|
176
|
+
/**
|
|
177
|
+
* Claims up to `claimBatch` tasks for a lane and flushes the claim before it returns, so a
|
|
178
|
+
* lane never runs a task whose claim a reset could still take back. Settles poison tasks first.
|
|
179
|
+
*/
|
|
180
|
+
claim(): Promise<LaneTask[]>;
|
|
181
|
+
/** Writes a task's result unless the task is already final, and flushes before it answers. */
|
|
182
|
+
complete(id: string, attempt: number, result: TaskValue): Promise<CompletionOutcome>;
|
|
183
|
+
/** Records an error from an attempt; the task retries until `maxAttempts`. */
|
|
184
|
+
fail(id: string, attempt: number, error: string): Promise<FailureOutcome>;
|
|
185
|
+
/** Extends the lease of each hold that is still the task's current attempt. */
|
|
186
|
+
renew(holds: readonly LaneHold[]): Promise<boolean[]>;
|
|
187
|
+
/**
|
|
188
|
+
* Calls lanes until every task is `done` or `failed`. Lanes that reset or return late are
|
|
189
|
+
* replayed after their leases end, so this can wait a lease length. Throws `stalled` when
|
|
190
|
+
* lanes keep returning without claiming work that is ready. Failed tasks do not throw here;
|
|
191
|
+
* read `failed` in the report, or let `fold` throw.
|
|
192
|
+
*/
|
|
193
|
+
run(): Promise<LaneReport>;
|
|
194
|
+
/**
|
|
195
|
+
* One pass for an alarm: settles poison tasks, calls lanes for the work that is ready, waits
|
|
196
|
+
* for those calls and reports. `wake` says when to call again.
|
|
197
|
+
*/
|
|
198
|
+
resume(): Promise<LaneReport>;
|
|
199
|
+
/** Every task in id order, whatever its state. */
|
|
200
|
+
results(): LaneResult[];
|
|
201
|
+
/**
|
|
202
|
+
* Folds the results in id order, whatever order the tasks finished in. Throws `unfinished`
|
|
203
|
+
* while a task is open and `failed` when one failed.
|
|
204
|
+
*/
|
|
205
|
+
fold<T>(combine: (acc: T, result: LaneResult, index: number) => T, init: T): T;
|
|
206
|
+
/** Closes the transport. */
|
|
207
|
+
close(): Promise<void>;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* The lane side. Returns the methods of a lane object: `work(coordinator)` claims tasks from the
|
|
211
|
+
* coordinator, runs `registry[name](args)` for each and reports the result, until a claim comes
|
|
212
|
+
* back empty. A task that returns a promise has its lease renewed while it runs; between the tasks
|
|
213
|
+
* of one claimed batch the lane renews the ones it still holds and skips any that are no longer
|
|
214
|
+
* its own. A task that throws, or names nothing in the registry, is reported as failed, and the
|
|
215
|
+
* pool retries it up to `maxAttempts`. A lane that resets mid-task reports nothing, and the lease
|
|
216
|
+
* ends the claim.
|
|
217
|
+
*/
|
|
218
|
+
export declare function serveLane(registry: TaskRegistry): {
|
|
219
|
+
/** Works the queue through `coordinator` until a claim comes back empty. */
|
|
220
|
+
work(coordinator: LaneCoordinator): Promise<LaneWorked>;
|
|
221
|
+
};
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { TaskTable } from "./tasks.js";
|
|
2
|
+
/** A pool that cannot finish. `code` is `failed` (a task failed), `unfinished` or `stalled` (no lane claims). */
|
|
3
|
+
export class LanePoolError extends Error {
|
|
4
|
+
/** Why the pool could not finish. */
|
|
5
|
+
code;
|
|
6
|
+
constructor(code, detail, cause) {
|
|
7
|
+
super(`lane pool ${code}: ${detail}`, cause === undefined ? undefined : { cause });
|
|
8
|
+
this.name = 'LanePoolError';
|
|
9
|
+
this.code = code;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const minLeaseMs = 5000;
|
|
13
|
+
// lane calls in a row that claim nothing while work is ready
|
|
14
|
+
const stallLimit = 3;
|
|
15
|
+
const systemClock = {
|
|
16
|
+
now: () => Date.now(),
|
|
17
|
+
sleep: (ms, signal) => new Promise((resolve) => {
|
|
18
|
+
const timer = setTimeout(resolve, ms);
|
|
19
|
+
signal?.addEventListener('abort', () => {
|
|
20
|
+
clearTimeout(timer);
|
|
21
|
+
resolve();
|
|
22
|
+
}, { once: true });
|
|
23
|
+
})
|
|
24
|
+
};
|
|
25
|
+
const isValue = (value) => typeof value === 'string' || value instanceof Uint8Array;
|
|
26
|
+
const decode = (value) => typeof value === 'string' ? value : new TextDecoder().decode(value);
|
|
27
|
+
function resultOf(row) {
|
|
28
|
+
const finished = () => {
|
|
29
|
+
if (row.state !== 'done' || row.result === null)
|
|
30
|
+
throw new LanePoolError('failed', `task ${row.id} is ${row.state}: ${row.error ?? ''}`);
|
|
31
|
+
return decode(row.result);
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
id: row.id,
|
|
35
|
+
name: row.name,
|
|
36
|
+
state: row.state,
|
|
37
|
+
attempt: row.attempt,
|
|
38
|
+
...(row.result === null ? {} : { value: row.result }),
|
|
39
|
+
...(row.error === null ? {} : { error: row.error }),
|
|
40
|
+
text: finished,
|
|
41
|
+
json: () => JSON.parse(finished())
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The coordinator side of a durable lane pool. Tasks are rows in the object's own SQLite, lanes
|
|
46
|
+
* on other objects claim them by RPC, and a lane that resets loses only the tasks it was
|
|
47
|
+
* running: their leases end and the next claim replays them. A coordinator that resets loses
|
|
48
|
+
* only the transitions since its last flush; build a new pool over the same storage and call
|
|
49
|
+
* `run` or `resume`.
|
|
50
|
+
*
|
|
51
|
+
* A write is durable once an await or a flush has passed it, so the pool flushes after the three
|
|
52
|
+
* transitions that must survive (enqueue, claim, complete) and before anything depends on them.
|
|
53
|
+
* A failure report, a lease renewal and the expiry of a lease are not flushed: losing one only
|
|
54
|
+
* brings the same replay that a lane reset brings.
|
|
55
|
+
*
|
|
56
|
+
* Each id's result is written once. A task body runs at least once, so the result is exactly
|
|
57
|
+
* once in the table and effectively once for a task whose body is deterministic or idempotent.
|
|
58
|
+
*/
|
|
59
|
+
export class LanePool {
|
|
60
|
+
/** The task table, for callers that read rows directly. */
|
|
61
|
+
table;
|
|
62
|
+
#transport;
|
|
63
|
+
#width;
|
|
64
|
+
#leaseMs;
|
|
65
|
+
#batch;
|
|
66
|
+
#clock;
|
|
67
|
+
#flush;
|
|
68
|
+
#claims = 0;
|
|
69
|
+
#kicks = 0;
|
|
70
|
+
#laneErrors = 0;
|
|
71
|
+
#lastError;
|
|
72
|
+
constructor(sql, options) {
|
|
73
|
+
const { width, leaseMs = 15000, claimBatch = 1 } = options;
|
|
74
|
+
if (!Number.isInteger(width) || width < 1)
|
|
75
|
+
throw new RangeError('width must be a positive integer');
|
|
76
|
+
if (!Number.isInteger(leaseMs) || leaseMs < minLeaseMs)
|
|
77
|
+
throw new RangeError(`leaseMs must be an integer of at least ${minLeaseMs}`);
|
|
78
|
+
if (!Number.isInteger(claimBatch) || claimBatch < 1)
|
|
79
|
+
throw new RangeError('claimBatch must be a positive integer');
|
|
80
|
+
this.table = new TaskTable(sql, { table: options.table, maxAttempts: options.maxAttempts });
|
|
81
|
+
this.#transport = options.transport;
|
|
82
|
+
this.#width = width;
|
|
83
|
+
this.#leaseMs = leaseMs;
|
|
84
|
+
this.#batch = claimBatch;
|
|
85
|
+
this.#clock = options.clock ?? systemClock;
|
|
86
|
+
this.#flush = options.flush ?? (async () => { });
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Adds tasks and returns how many were new, once they are flushed. An id that exists is
|
|
90
|
+
* ignored, so repeating a submit that failed is safe.
|
|
91
|
+
*/
|
|
92
|
+
async submit(tasks) {
|
|
93
|
+
let added = 0;
|
|
94
|
+
for (const task of tasks) {
|
|
95
|
+
if (typeof task.id !== 'string' || !task.id)
|
|
96
|
+
throw new TypeError('a task needs an id');
|
|
97
|
+
if (typeof task.name !== 'string' || !task.name)
|
|
98
|
+
throw new TypeError(`task ${task.id} needs a name`);
|
|
99
|
+
if (task.args !== undefined && task.argsJson !== undefined)
|
|
100
|
+
throw new TypeError('pass args or argsJson, not both');
|
|
101
|
+
const args = task.argsJson === undefined ? (task.args ?? '') : JSON.stringify(task.argsJson);
|
|
102
|
+
if (!isValue(args))
|
|
103
|
+
throw new TypeError(`args of task ${task.id} must be a string or bytes`);
|
|
104
|
+
if (this.table.enqueue(task.id, task.name, args))
|
|
105
|
+
added++;
|
|
106
|
+
}
|
|
107
|
+
await this.#flush();
|
|
108
|
+
return added;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Claims up to `claimBatch` tasks for a lane and flushes the claim before it returns, so a
|
|
112
|
+
* lane never runs a task whose claim a reset could still take back. Settles poison tasks first.
|
|
113
|
+
*/
|
|
114
|
+
async claim() {
|
|
115
|
+
const rows = this.table.claim(this.#clock.now(), this.#leaseMs, this.#batch);
|
|
116
|
+
await this.#flush();
|
|
117
|
+
if (rows.length)
|
|
118
|
+
this.#claims++;
|
|
119
|
+
return rows.map((row) => ({
|
|
120
|
+
id: row.id,
|
|
121
|
+
name: row.name,
|
|
122
|
+
args: row.args,
|
|
123
|
+
attempt: row.attempt,
|
|
124
|
+
leaseMs: this.#leaseMs
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
/** Writes a task's result unless the task is already final, and flushes before it answers. */
|
|
128
|
+
async complete(id, attempt, result) {
|
|
129
|
+
if (!isValue(result))
|
|
130
|
+
throw new TypeError('a task result must be a string or bytes');
|
|
131
|
+
const outcome = this.table.complete(id, attempt, result);
|
|
132
|
+
await this.#flush();
|
|
133
|
+
return outcome;
|
|
134
|
+
}
|
|
135
|
+
/** Records an error from an attempt; the task retries until `maxAttempts`. */
|
|
136
|
+
async fail(id, attempt, error) {
|
|
137
|
+
return this.table.fail(id, attempt, String(error));
|
|
138
|
+
}
|
|
139
|
+
/** Extends the lease of each hold that is still the task's current attempt. */
|
|
140
|
+
async renew(holds) {
|
|
141
|
+
const now = this.#clock.now();
|
|
142
|
+
return holds.map((hold) => this.table.renew(hold.id, hold.attempt, now, this.#leaseMs));
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Calls lanes until every task is `done` or `failed`. Lanes that reset or return late are
|
|
146
|
+
* replayed after their leases end, so this can wait a lease length. Throws `stalled` when
|
|
147
|
+
* lanes keep returning without claiming work that is ready. Failed tasks do not throw here;
|
|
148
|
+
* read `failed` in the report, or let `fold` throw.
|
|
149
|
+
*/
|
|
150
|
+
async run() {
|
|
151
|
+
const busy = new Map();
|
|
152
|
+
let fruitless = 0;
|
|
153
|
+
for (;;) {
|
|
154
|
+
const now = this.#clock.now();
|
|
155
|
+
this.table.expire(now);
|
|
156
|
+
const open = this.table.pending(now);
|
|
157
|
+
if (open.open === 0)
|
|
158
|
+
return this.#report(now);
|
|
159
|
+
if (fruitless >= stallLimit)
|
|
160
|
+
throw new LanePoolError('stalled', `${stallLimit} lane calls in a row claimed nothing while ${open.claimable} tasks were ready`, this.#lastError);
|
|
161
|
+
let wanted = Math.min(this.#width - busy.size, Math.ceil(open.claimable / this.#batch));
|
|
162
|
+
for (let lane = 0; wanted > 0 && lane < this.#width; lane++) {
|
|
163
|
+
if (busy.has(lane))
|
|
164
|
+
continue;
|
|
165
|
+
wanted--;
|
|
166
|
+
const before = this.#claims;
|
|
167
|
+
busy.set(lane, this.#kick(lane).then(() => {
|
|
168
|
+
fruitless = this.#claims === before ? fruitless + 1 : 0;
|
|
169
|
+
busy.delete(lane);
|
|
170
|
+
}));
|
|
171
|
+
}
|
|
172
|
+
const wake = new AbortController();
|
|
173
|
+
const waits = [...busy.values()];
|
|
174
|
+
if (open.nextExpiry !== undefined)
|
|
175
|
+
waits.push(this.#clock.sleep(open.nextExpiry - now, wake.signal));
|
|
176
|
+
if (!waits.length)
|
|
177
|
+
throw new LanePoolError('stalled', 'no lane is working and no lease is pending');
|
|
178
|
+
await Promise.race(waits);
|
|
179
|
+
wake.abort();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* One pass for an alarm: settles poison tasks, calls lanes for the work that is ready, waits
|
|
184
|
+
* for those calls and reports. `wake` says when to call again.
|
|
185
|
+
*/
|
|
186
|
+
async resume() {
|
|
187
|
+
const now = this.#clock.now();
|
|
188
|
+
this.table.expire(now);
|
|
189
|
+
const open = this.table.pending(now);
|
|
190
|
+
const lanes = Math.min(this.#width, Math.ceil(open.claimable / this.#batch));
|
|
191
|
+
await Promise.all(Array.from({ length: lanes }, (_, lane) => this.#kick(lane)));
|
|
192
|
+
const after = this.#clock.now();
|
|
193
|
+
this.table.expire(after);
|
|
194
|
+
return this.#report(after);
|
|
195
|
+
}
|
|
196
|
+
/** Every task in id order, whatever its state. */
|
|
197
|
+
results() {
|
|
198
|
+
return this.table.snapshot().map(resultOf);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Folds the results in id order, whatever order the tasks finished in. Throws `unfinished`
|
|
202
|
+
* while a task is open and `failed` when one failed.
|
|
203
|
+
*/
|
|
204
|
+
fold(combine, init) {
|
|
205
|
+
const all = this.results();
|
|
206
|
+
const failed = all.filter((result) => result.state === 'failed');
|
|
207
|
+
if (failed.length)
|
|
208
|
+
throw new LanePoolError('failed', `${failed.length} tasks failed, first ${failed[0].id}: ${failed[0].error ?? ''}`);
|
|
209
|
+
const open = all.filter((result) => result.state !== 'done');
|
|
210
|
+
if (open.length)
|
|
211
|
+
throw new LanePoolError('unfinished', `${open.length} tasks are not done`);
|
|
212
|
+
return all.reduce((acc, result, index) => combine(acc, result, index), init);
|
|
213
|
+
}
|
|
214
|
+
/** Closes the transport. */
|
|
215
|
+
close() {
|
|
216
|
+
return Promise.resolve(this.#transport.close?.());
|
|
217
|
+
}
|
|
218
|
+
async #kick(lane) {
|
|
219
|
+
this.#kicks++;
|
|
220
|
+
try {
|
|
221
|
+
await this.#transport.work(lane);
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
this.#laneErrors++;
|
|
225
|
+
this.#lastError = error;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
#report(now) {
|
|
229
|
+
const counts = this.table.counts();
|
|
230
|
+
const wake = counts.queued + counts.running === 0
|
|
231
|
+
? undefined
|
|
232
|
+
: Math.max(this.table.pending(now).nextExpiry ?? 0, now + minLeaseMs);
|
|
233
|
+
return {
|
|
234
|
+
...counts,
|
|
235
|
+
kicks: this.#kicks,
|
|
236
|
+
laneErrors: this.#laneErrors,
|
|
237
|
+
...(wake === undefined ? {} : { wake })
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
const message = (error) => (error instanceof Error ? error.message : String(error)).slice(0, 1000);
|
|
242
|
+
/**
|
|
243
|
+
* The lane side. Returns the methods of a lane object: `work(coordinator)` claims tasks from the
|
|
244
|
+
* coordinator, runs `registry[name](args)` for each and reports the result, until a claim comes
|
|
245
|
+
* back empty. A task that returns a promise has its lease renewed while it runs; between the tasks
|
|
246
|
+
* of one claimed batch the lane renews the ones it still holds and skips any that are no longer
|
|
247
|
+
* its own. A task that throws, or names nothing in the registry, is reported as failed, and the
|
|
248
|
+
* pool retries it up to `maxAttempts`. A lane that resets mid-task reports nothing, and the lease
|
|
249
|
+
* ends the claim.
|
|
250
|
+
*/
|
|
251
|
+
export function serveLane(registry) {
|
|
252
|
+
return {
|
|
253
|
+
async work(coordinator) {
|
|
254
|
+
const worked = { claimed: 0, completed: 0, failed: 0 };
|
|
255
|
+
for (;;) {
|
|
256
|
+
const batch = await coordinator.claim();
|
|
257
|
+
if (!batch.length)
|
|
258
|
+
return worked;
|
|
259
|
+
worked.claimed += batch.length;
|
|
260
|
+
const held = new Map(batch.map((task) => [task.id, task]));
|
|
261
|
+
const holds = () => [...held.values()].map(({ id, attempt }) => ({ id, attempt }));
|
|
262
|
+
for (const [index, task] of batch.entries()) {
|
|
263
|
+
if (index > 0 && held.size) {
|
|
264
|
+
const before = holds();
|
|
265
|
+
const kept = await coordinator.renew(before);
|
|
266
|
+
before.forEach((hold, at) => {
|
|
267
|
+
if (!kept[at])
|
|
268
|
+
held.delete(hold.id);
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
if (!held.has(task.id))
|
|
272
|
+
continue;
|
|
273
|
+
let timer;
|
|
274
|
+
let outcome;
|
|
275
|
+
try {
|
|
276
|
+
const fn = Object.hasOwn(registry, task.name)
|
|
277
|
+
? registry[task.name]
|
|
278
|
+
: undefined;
|
|
279
|
+
if (!fn)
|
|
280
|
+
throw new Error(`no task named ${task.name}`);
|
|
281
|
+
const pending = fn(task.args, task);
|
|
282
|
+
let value = pending;
|
|
283
|
+
if (typeof pending?.then === 'function') {
|
|
284
|
+
timer = setInterval(() => void coordinator.renew(holds()).catch(() => { }), Math.max(1000, Math.floor(task.leaseMs / 3)));
|
|
285
|
+
value = await pending;
|
|
286
|
+
}
|
|
287
|
+
if (!isValue(value))
|
|
288
|
+
throw new TypeError(`task ${task.name} returned neither a string nor bytes`);
|
|
289
|
+
outcome = { value };
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
outcome = { error: message(error) };
|
|
293
|
+
}
|
|
294
|
+
finally {
|
|
295
|
+
clearInterval(timer);
|
|
296
|
+
}
|
|
297
|
+
held.delete(task.id);
|
|
298
|
+
if ('value' in outcome) {
|
|
299
|
+
await coordinator.complete(task.id, task.attempt, outcome.value);
|
|
300
|
+
worked.completed++;
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
await coordinator.fail(task.id, task.attempt, outcome.error);
|
|
304
|
+
worked.failed++;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
}
|