Rebuild: settling quiet releases
Hourly in coordinator:run: a release unchanged for 6 hours is settled, complete when every file its [i/N] counter announced was found, unknown without a counter (phase 2 reads par2 sets for those). Partial index on unsettled releases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fde1e6cc90
commit
80c920f678
4 files changed
+64
-2
No files matched your search
@@ -0,0 +1,28 @@
|
||||
import db from '@adonisjs/lucid/services/db'
|
||||
|
||||
/** Releases unchanged for this long are settled (ranges are read in order; the merger adds within minutes). */
|
||||
const QUIET_HOURS = 6
|
||||
const BATCH = 50_000
|
||||
|
||||
/**
|
||||
* Settles releases (REBUILD.md, part 8): once nothing has been added for
|
||||
* QUIET_HOURS, its completeness is decided: complete when every file the
|
||||
* [i/N] counter announced was found, unknown without a counter (phase 2
|
||||
* reads par2 sets for those). Phase 2 picks its work from settled releases.
|
||||
*/
|
||||
class Settler {
|
||||
async run(): Promise<number> {
|
||||
let settled = 0
|
||||
while (true) {
|
||||
const { rowCount } = await db.rawQuery(
|
||||
`UPDATE releases SET settled_at = now(), complete = CASE WHEN file_total IS NULL THEN NULL ELSE files >= file_total END
|
||||
WHERE id IN (SELECT id FROM releases WHERE settled_at IS NULL AND last_seen_at < now() - make_interval(hours => ?) LIMIT ?)`,
|
||||
[QUIET_HOURS, BATCH]
|
||||
)
|
||||
settled += rowCount ?? 0
|
||||
if ((rowCount ?? 0) < BATCH) return settled
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new Settler()
|
||||
Reference in new issue
Block a user