- groups:add / ranges:plan / nodes:create / coordinator:run commands - the node API: lease, the range's chunks as one framed stream from the spool, batches, heartbeat, finish, release (node guard, token per node) - edge:node: needs COORDINATOR_URL and NODE_TOKEN only (placeholders for the rest), posts a batch every 10 chunks, gives its range back on SIGTERM - releases are gathered per batch: 1.04 chunk rows per release at 10 chunks per batch (1.35 when built per XOVER chunk) - partitions are checked per batch instead of remembered Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
37 lines
1.5 KiB
TypeScript
37 lines
1.5 KiB
TypeScript
import db from '@adonisjs/lucid/services/db'
|
|
import { DEFAULT_RULES, type Rules } from '#lib/rules/index'
|
|
|
|
type StoredRules = Omit<Rules, 'version' | 'priorities'>
|
|
|
|
/**
|
|
* The rule set workers get with a lease (REBUILD.md, rules and recovery):
|
|
* the newest version, plus the indexed groups' priorities (owner rule).
|
|
* Version 1 (DEFAULT_RULES, no dropped signatures) is created when there is none.
|
|
*/
|
|
class RuleSets {
|
|
async current(): Promise<Rules> {
|
|
let row = await db.from('rule_sets').orderBy('version', 'desc').first()
|
|
if (!row) {
|
|
const { version: _v, ...rules } = DEFAULT_RULES
|
|
await db.table('rule_sets').insert({ version: 1, rules: JSON.stringify({ ...rules, droppedSignatures: [] }), note: 'default' }).onConflict('version').ignore()
|
|
row = await db.from('rule_sets').orderBy('version', 'desc').first()
|
|
}
|
|
const groups = await db.from('groups').where('active', true).select('name', 'priority')
|
|
return {
|
|
...(row.rules as StoredRules),
|
|
version: Number(row.version),
|
|
priorities: Object.fromEntries(groups.map((g) => [g.name, Number(g.priority)])),
|
|
}
|
|
}
|
|
|
|
/** A new version: what changes is recorded on the ranges that run with it. */
|
|
async publish(rules: StoredRules, note?: string): Promise<number> {
|
|
const latest = await db.from('rule_sets').max('version as v').first()
|
|
const version = Number(latest?.v ?? 0) + 1
|
|
await db.table('rule_sets').insert({ version, rules: JSON.stringify(rules), note: note ?? null })
|
|
return version
|
|
}
|
|
}
|
|
|
|
export default new RuleSets()
|