Skip to content

Commit 8050f19

Browse files
committed
PersistentTimer: add copious logging to ticking
#647
1 parent a184b6b commit 8050f19

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/timer/PersistentTimer.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ export class PersistentTimer {
3232
protected interval?: NodeJS.Timeout;
3333

3434
/// This constructor has side effects as it immediately starts the timer!
35-
protected constructor(protected entity: Countdown, protected discord: PersistentTimerDiscordDelegate) {
35+
protected constructor(
36+
protected entity: Countdown,
37+
protected discord: PersistentTimerDiscordDelegate
38+
) {
3639
this.interval = setInterval(() => this.tick(), 1000);
3740
}
3841

@@ -123,23 +126,31 @@ export class PersistentTimer {
123126
protected async tick(): Promise<void> {
124127
const end = this.entity.end;
125128
const now = new Date();
129+
const iso = now.toISOString();
130+
logger.verbose(`tick: ${this.entity.id} now(${iso}) end(${end.toISOString()})`);
126131
if (end <= now) {
132+
logger.verbose(`tick: ${this.entity.id} now(${iso}) aborting`);
127133
await this.abort();
128134
try {
135+
logger.verbose(`tick: ${this.entity.id} now(${iso}) sending message`);
129136
await this.discord.sendMessage(this.entity.channelId, this.entity.finalMessage);
137+
logger.verbose(`tick: ${this.entity.id} now(${iso}) finished`);
130138
} catch (error) {
131139
logger.warn(error);
132140
}
133141
}
134142
const secondsRemaining = Math.ceil((now.getTime() - end.getTime()) / 1000);
135-
if (secondsRemaining % this.entity.cronIntervalSeconds == 0) {
143+
logger.verbose(`tick: ${this.entity.id} now(${iso}) secondsRemaining(${secondsRemaining})`);
144+
if (secondsRemaining % this.entity.cronIntervalSeconds === 0) {
136145
const left = PersistentTimer.formatTime(end.getTime() - Date.now());
146+
logger.verbose(`tick: ${this.entity.id} now(${iso}) left(${left})`);
137147
try {
138148
await this.discord.editMessage(
139149
this.entity.channelId,
140150
this.entity.messageId,
141151
`Time left in the round: \`${left}\`. Ends ${time(end)} (${time(end, "R")}).`
142152
);
153+
logger.verbose(`tick: ${this.entity.id} now(${iso}) edited`);
143154
} catch (error) {
144155
logger.warn(`tick: could not edit ${this.entity.channelId} ${this.entity.messageId}`);
145156
logger.warn(error);

0 commit comments

Comments
 (0)