fix: component start invocation runs heartbeat immediately

This commit is contained in:
FoxxMD 2026-08-13 20:26:29 +00:00
parent 52117cb1d0
commit 06fbdccd14
2 changed files with 16 additions and 2 deletions

View file

@ -228,6 +228,7 @@ export default abstract class AbstractScrobbleClient extends AbstractComponent i
[Symbol.dispose]() {
this.scheduler.stop();
for(const job of this.scheduler.getAllJobs()) {
job.stop();
this.scheduler.removeById(job.id);
}
}
@ -259,7 +260,9 @@ export default abstract class AbstractScrobbleClient extends AbstractComponent i
}
), {id: 'heartbeat'}));
} else {
this.logger.verbose('Heartbeat task is already added to scheduler.');
this.logger.verbose('Heartbeat task is already added to scheduler, running immediately instead');
const j = this.scheduler.getById('heartbeat') as SimpleIntervalJob;
j.start();
}
this.initializeNowPlayingSchedule();
@ -352,6 +355,7 @@ export default abstract class AbstractScrobbleClient extends AbstractComponent i
try {
this.scheduler.stop();
for (const job of this.scheduler.getAllJobs()) {
job.stop();
this.scheduler.removeById(job.id);
}
await this.tryStopScrobbling(opts.reason);

View file

@ -137,6 +137,13 @@ export default abstract class AbstractSource extends AbstractComponent implement
}
[Symbol.dispose]() {
this.scheduler.stop();
for(const job of this.scheduler.getAllJobs()) {
job.stop();
this.scheduler.removeById(job.id);
}
}
async [Symbol.asyncDispose]() {
try {
await this.stop({ reason: 'Instance is being destroyed' });
@ -165,7 +172,9 @@ export default abstract class AbstractSource extends AbstractComponent implement
}
), {id: 'heartbeat'}));
} else {
this.logger.warn('Heartbeat task is already added to scheduler.');
this.logger.verbose('Heartbeat task is already added to scheduler, running immediately instead');
const j = this.scheduler.getById('heartbeat') as SimpleIntervalJob;
j.start();
}
}
@ -236,6 +245,7 @@ export default abstract class AbstractSource extends AbstractComponent implement
}
this.scheduler.stop();
for (const job of this.scheduler.getAllJobs()) {
job.stop();
this.scheduler.removeById(job.id);
}
this.setStatus('Stopped');