feat: PM2 as canonical scheduler — SKILL.md updated, setup.mjs simplified, OpenClaw gateway cron removed

This commit is contained in:
2026-03-06 02:12:17 +00:00
parent aec603b72c
commit f9d7543611
2 changed files with 52 additions and 88 deletions

View File

@@ -4,7 +4,7 @@
* Verifies config, tests logins, registers cron jobs
* Run once after configuring: node setup.mjs
*/
import { existsSync, mkdirSync, writeFileSync } from 'fs';
import { existsSync, mkdirSync, writeFileSync, chmodSync } from 'fs';
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';
import { loadConfig } from './lib/queue.mjs';
@@ -94,70 +94,16 @@ async function main() {
await wfBrowser?.browser?.close().catch(() => {});
}
// Register cron jobs via OpenClaw gateway
const gatewayUrl = process.env.OPENCLAW_GATEWAY_URL || 'http://localhost:3000';
const gatewayToken = process.env.OPENCLAW_GATEWAY_TOKEN;
const telegramUserId = settings.notifications?.telegram_user_id;
const searchSchedule = settings.schedules?.search || '0 * * * *';
const applySchedule = settings.schedules?.apply || '0 */6 * * *';
// API keys are loaded from .env at runtime — never embedded in cron payloads
if (gatewayToken && telegramUserId) {
console.log('\nRegistering cron jobs...');
const headers = { 'Content-Type': 'application/json', Authorization: `Bearer ${gatewayToken}` };
const searchJob = {
name: 'claw-apply: job searcher',
schedule: { kind: 'cron', expr: searchSchedule, tz: settings.timezone || 'America/Los_Angeles' },
payload: {
kind: 'agentTurn',
message: `Launch the claw-apply job searcher as a detached background process: \`cd ${__dir} && nohup node job_searcher.mjs >> /tmp/claw-searcher.log 2>&1 & echo $!\`. Confirm the PID and that it started successfully.`,
timeoutSeconds: 30,
},
delivery: { mode: 'announce', to: telegramUserId },
sessionTarget: 'isolated',
enabled: true,
};
const applyJob = {
name: 'claw-apply: job applier',
schedule: { kind: 'cron', expr: applySchedule, tz: settings.timezone || 'America/Los_Angeles' },
payload: {
kind: 'agentTurn',
message: `Launch the claw-apply job applier as a detached background process: \`cd ${__dir} && nohup node job_applier.mjs >> /tmp/claw-applier.log 2>&1 & echo $!\`. Confirm the PID and that it started successfully.`,
timeoutSeconds: 30,
},
delivery: { mode: 'announce', to: telegramUserId },
sessionTarget: 'isolated',
enabled: false, // disabled by default — enable when ready
};
try {
const sRes = await fetch(`${gatewayUrl}/api/cron/jobs`, { method: 'POST', headers, body: JSON.stringify(searchJob) });
const sData = await sRes.json();
console.log(sRes.ok ? ` ✅ Searcher cron registered (ID: ${sData.id})` : ` ❌ Searcher cron failed: ${JSON.stringify(sData)}`);
} catch (e) {
console.log(` ❌ Searcher cron error: ${e.message}`);
}
try {
const aRes = await fetch(`${gatewayUrl}/api/cron/jobs`, { method: 'POST', headers, body: JSON.stringify(applyJob) });
const aData = await aRes.json();
console.log(aRes.ok ? ` ✅ Applier cron registered, disabled (ID: ${aData.id}) — enable when ready` : ` ❌ Applier cron failed: ${JSON.stringify(aData)}`);
} catch (e) {
console.log(` ❌ Applier cron error: ${e.message}`);
}
} else {
console.log('\n⚠ Skipping cron registration — set OPENCLAW_GATEWAY_URL and OPENCLAW_GATEWAY_TOKEN to auto-register.');
console.log(' Or register manually with these schedules:');
console.log(` Search: ${searchSchedule} (timeoutSeconds: 0)`);
console.log(` Apply: ${applySchedule} (timeoutSeconds: 0, start disabled)`);
}
console.log('\n🎉 Setup complete. claw-apply is ready.');
console.log('\nTo run manually:');
console.log(' node job_searcher.mjs — search now');
console.log(' node job_applier.mjs — apply now');
console.log('\nNext: start the scheduler with PM2:');
console.log(' npm install -g pm2');
console.log(' pm2 start ecosystem.config.cjs');
console.log(' pm2 stop claw-applier # keep off until ready to apply');
console.log(' pm2 save && pm2 startup # survive reboots');
console.log('\nRun manually:');
console.log(' node job_searcher.mjs — search now');
console.log(' node job_applier.mjs — apply now');
console.log(' node status.mjs — queue + run status');
}
main().catch(e => { console.error('Setup error:', e.message); process.exit(1); });