Files
Ник (Claude) d8a901131c feat: auto-retry SVG covers every 30 min
coverRetry.js: сканирует articles с cover < 30KB (SVG-заглушки),
перегенерирует через covers.generateCover(). При недоступности
провайдера (timeout/502) прерывает цикл до следующего запуска.
Первый запуск через 5 мин после старта engine, далее каждые 30 мин.
2026-06-10 08:53:39 +03:00

33 lines
1.1 KiB
JavaScript

require('dotenv').config({ path: '/var/www/zeropost-engine/.env' });
process.chdir('/var/www/zeropost-engine');
const covers = require('./src/services/covers');
const config = require('./src/config');
const { query } = require('./src/config/db');
const DELAY_MS = 20000;
const sleep = ms => new Promise(r => setTimeout(r, ms));
(async () => {
await config.reloadAi();
const { rows } = await query('SELECT id, title, tags FROM articles WHERE cover_url IS NOT NULL ORDER BY id');
console.log(`Total articles: ${rows.length}`);
let ok = 0, fail = 0;
for (const a of rows) {
try {
console.log(`\n[${ok+fail+1}/${rows.length}] article=${a.id}: ${a.title.slice(0,60)}`);
const url = await covers.generateCover({ articleId: a.id, title: a.title, tags: a.tags||[], channelId: 1 });
console.log(`${url}`);
ok++;
} catch(e) {
console.log(` ✗ FAIL: ${e.message.slice(0,100)}`);
fail++;
}
if (ok + fail < rows.length) await sleep(DELAY_MS);
}
console.log(`\nDone: ${ok} OK, ${fail} failed`);
process.exit(0);
})().catch(e => { console.error(e); process.exit(1); });