import { BaseCommand, flags } from '@adonisjs/core/ace' import type { CommandOptions } from '@adonisjs/core/types/ace' import { Spotter } from '#services/spotter' /** The spotter (REBUILD.md, spots): Spotnet's spots from free.pt's headers into `spots`, on one connection. */ export default class SpotsRead extends BaseCommand { static commandName = 'spots:read' static description = "Reads Spotnet's spots (free.pt) into the spots table, verified, every few minutes" static options: CommandOptions = { startApp: true, staysAlive: true } @flags.boolean({ description: 'One round, then exit' }) declare once: boolean async run() { const spotter = new Spotter() if (this.once) { const round = await spotter.round() this.logger.info(`${round.read} articles read: ${round.listed} spots listed, ${round.unverified} unverified, ${round.moderation} moderation.`) spotter.stop() await this.terminate() return } let done: () => void const finished = new Promise((resolve) => (done = resolve)) this.app.terminating(async () => { spotter.stop() await finished }) await spotter.run() this.logger.info('Spotter stopped.') done!() } }