import { BaseCommand, flags } from '@adonisjs/core/ace' import type { CommandOptions } from '@adonisjs/core/types/ace' import { SpotInspector } from '#services/spot_inspector' /** The spot inspector (REBUILD.md, spots): each spot's NZB read, its files listed and matched to releases. */ export default class SpotsInspect extends BaseCommand { static commandName = 'spots:inspect' static description = "Reads each listed spot's NZB, lists its files and links them to the releases they match" static options: CommandOptions = { startApp: true, staysAlive: true } @flags.boolean({ description: 'One round, then exit' }) declare once: boolean async run() { const inspector = new SpotInspector() if (this.once) { const round = await inspector.round() this.logger.info(`${round.inspected} spots inspected, ${round.matched} matched releases, ${round.standalone} of their own.`) inspector.stop() await this.terminate() return } let done: () => void const finished = new Promise((resolve) => (done = resolve)) this.app.terminating(async () => { inspector.stop() await finished }) await inspector.run() this.logger.info('Spot inspector stopped.') done!() } }