import { BaseCommand, flags } from '@adonisjs/core/ace' import type { CommandOptions } from '@adonisjs/core/types/ace' import Planner from '#services/planner' import NntpPool from '#services/nntp_pool' /** Cuts new groups' history into ranges, or (--tail) plans one round of the live tail. */ export default class RangesPlan extends BaseCommand { static commandName = 'ranges:plan' static description = "Plans ranges for new groups' history, or one round of the live tail" static options: CommandOptions = { startApp: true } @flags.boolean({ description: 'Plan the live tail once (what coordinator:run does every few minutes)' }) declare tail: boolean async run() { try { if (this.tail) { const { groups, ranges, extended } = await Planner.planTail() this.logger.info(`Tail: ${ranges} ranges added, ${extended} grown, over ${groups} groups.`) } else { const { groups, ranges } = await Planner.planAll() this.logger.info(`${ranges} ranges planned over ${groups} groups.`) } } finally { await NntpPool.close() } } }