/** Abandoned browser-task cleanup under supervision. */
import { resolveBrowserTaskIdleMs } from '../device-config.js';
import { BasePeriodicService } from './service.js';
const BROWSER_TASK_REAP_TICK_MS = 5 * 60_000;
const BROWSER_TASK_REAP_DEADLINE_MS = 2 * 60_000;
export class BrowserTaskReapService extends BasePeriodicService {
    browserService;
    id = 'browser-task-reap';
    intervalMs = BROWSER_TASK_REAP_TICK_MS;
    deadlineMs = BROWSER_TASK_REAP_DEADLINE_MS;
    constructor(browserService) {
        super();
        this.browserService = browserService;
    }
    async onStart(_ctx) { }
    async onStop() { }
    async onTick(ctx) {
        const result = await this.browserService.reapAbandoned({ idleMs: await resolveBrowserTaskIdleMs() });
        if (result.closed.length > 0) {
            ctx.log('INFO', `Browser-task reaper: closed ${result.closed.length} task(s)`);
            for (const closed of result.closed) {
                ctx.log('INFO', `  ${closed.task} (${closed.reason}, profile ${closed.profile})`);
            }
        }
    }
}
