Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/features/scheduled-announcements/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ export function createScheduledAnnouncementsService(
let entries: ScheduledAnnouncementEntry[] = [];
let timer: NodeJS.Timeout | null = null;
let stopped = false;
// The idle re-check runs every 60s; log only the transition into idle so a
// quiet schedule does not flood the log (~1440 lines/day) and evict useful
// history from retention.
let idleNotified = false;

function resolveChannel(channelId: string): Promise<SendableTextChannel | null> {
if (options.resolveChannel) {
Expand Down Expand Up @@ -158,14 +162,19 @@ export function createScheduledAnnouncementsService(
const next = pickNextFires(entries, now, 1)[0] ?? null;

if (!next) {
logger.info("No enabled entries left to schedule; entering idle loop.");
if (!idleNotified) {
logger.info("No enabled entries left to schedule; entering idle loop.");
idleNotified = true;
}
// Re-check periodically so config edits followed by a restart can be
// picked up; also handles a future case where entries get re-enabled
// via edit-and-restart.
timer = setTimeout(scheduleNext, 60_000);
return;
}

idleNotified = false;

const rawDelayMs = next.fireAt.getTime() - now.getTime();
const delayMs = Math.max(0, rawDelayMs);
const safeDelayMs = Math.min(delayMs, MAX_SET_TIMEOUT_DELAY_MS);
Expand Down
Loading
Loading