'use strict'; const fs=require('node:fs'),path=require('node:path'); const root=process.env.PT_ROOT || 'C:\\pt-worker', state=path.join(root,'state'); // The supervisor owns graceful shutdown; only stop after all processing jobs exit. fs.writeFileSync(path.join(state,'supervisor-stop'), 'requested'); const timer=setInterval(()=>{ try {const r=JSON.parse(fs.readFileSync(path.join(state,'runner.json'),'utf8'));if(!r.running){clearInterval(timer);process.exit(0);}}catch{} },1000);