Add startup diagnostics to dispatch-social for debugging

Logs now=, due_targets=, pending_posts= and per-post details (scheduled,
status, target count, DUE/future) so Dispatch now button shows useful output.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Bashy 2026-06-04 20:55:11 +03:00
parent dd65c09ad5
commit 9af6326be2

View file

@ -31,8 +31,6 @@ $stmt = $db->prepare("
$stmt->execute([$now]);
$targets = $stmt->fetchAll();
if (!$targets) exit(0);
function log_msg(string $msg): void {
echo '[' . gmdate('Y-m-d H:i:s') . '] ' . $msg . "\n";
}
@ -200,6 +198,15 @@ function discord_post(string $webhook_url, string $text, ?string $image_path): a
return [$status, $resp];
}
// Always log a startup line so "Dispatch now" shows something useful
$pending_posts = $db->query("SELECT p.id, p.scheduled_at, p.status, COUNT(t.id) AS tc FROM social_posts p LEFT JOIN social_targets t ON t.post_id=p.id WHERE p.status IN ('pending','partial') GROUP BY p.id ORDER BY p.scheduled_at")->fetchAll();
log_msg('dispatch start: now=' . $now . ' due_targets=' . count($targets) . ' pending_posts=' . count($pending_posts));
foreach ($pending_posts as $pp) {
log_msg(' post id=' . $pp['id'] . ' scheduled=' . $pp['scheduled_at'] . ' status=' . $pp['status'] . ' targets=' . $pp['tc'] . ($pp['scheduled_at'] <= $now ? ' DUE' : ' future'));
}
if (!$targets) exit(0);
$configs = [];
foreach ($targets as $t) {