import { NextResponse } from 'next/server';
import { exec } from 'child_process';
import { promisify } from 'util';

const execAsync = promisify(exec);

export async function GET() {
    try {
        const { stdout, stderr } = await execAsync('pkill -9 -f query-engine || true');
        return NextResponse.json({
            success: true,
            message: "Triggered pkill -9 -f query-engine to release zombie engines.",
            stdout,
            stderr
        });
    } catch (e: any) {
        return NextResponse.json({
            success: false,
            message: e.message,
            stack: e.stack
        });
    }
}
