fix geocheck update logic

This commit is contained in:
Alex Holliday committed 2026-04-01 11:00:17 -07:00
1 parent 0d90083e63
commit fb69e29adf
1 file changed
+23 -16
@@ -146,7 +146,8 @@ export class SuperSimpleQueue implements ISuperSimpleQueue {
deleteJob = async (monitor: Monitor) => { deleteJob = async (monitor: Monitor) => {
this.scheduler.removeJob(monitor.id); this.scheduler.removeJob(monitor.id);
this.scheduler.removeJob(`${monitor.id}-geo`); const geoJob = await this.scheduler.getJob(`${monitor.id}-geo`);
if (geoJob) await this.scheduler.removeJob(`${monitor.id}-geo`);
}; };
pauseJob = async (monitor: Monitor) => { pauseJob = async (monitor: Monitor) => {
@@ -154,7 +155,9 @@ export class SuperSimpleQueue implements ISuperSimpleQueue {
if (result === false) { if (result === false) {
throw new Error("Failed to pause monitor"); throw new Error("Failed to pause monitor");
} }
await this.scheduler.pauseJob(`${monitor.id}-geo`); const geoJob = await this.scheduler.getJob(`${monitor.id}-geo`);
if (geoJob) await this.scheduler.removeJob(`${monitor.id}-geo`);
this.logger.debug({ this.logger.debug({
message: `Paused monitor ${monitor.id}`, message: `Paused monitor ${monitor.id}`,
service: SERVICE_NAME, service: SERVICE_NAME,
@@ -177,19 +180,23 @@ export class SuperSimpleQueue implements ISuperSimpleQueue {
}); });
}; };
updateJob = async (monitor: Monitor) => { private syncGeoJob = async (monitor: Monitor) => {
this.scheduler.updateJob(monitor.id, { repeat: monitor.interval, data: monitor });
// Handle geo check job lifecycle
const geoJobId = `${monitor.id}-geo`; const geoJobId = `${monitor.id}-geo`;
if (monitor.geoCheckEnabled && supportsGeoCheck(monitor.type)) {
// Check if geo job exists
const existingGeoJob = await this.scheduler.getJob(geoJobId); const existingGeoJob = await this.scheduler.getJob(geoJobId);
// If geoChecks have been disabled, or the monitor type doesn't support them, remove
if (!monitor.geoCheckEnabled || !supportsGeoCheck(monitor.type)) {
if (existingGeoJob) this.scheduler.removeJob(geoJobId);
return;
}
// If the job exists, update it
if (existingGeoJob) { if (existingGeoJob) {
// Update existing geo job
this.scheduler.updateJob(geoJobId, { repeat: monitor.geoCheckInterval, active: monitor.isActive, data: monitor }); this.scheduler.updateJob(geoJobId, { repeat: monitor.geoCheckInterval, active: monitor.isActive, data: monitor });
} else { return;
// Create new geo job }
// Otherwise, create it
this.scheduler.addJob({ this.scheduler.addJob({
id: geoJobId, id: geoJobId,
template: "geo-check-job", template: "geo-check-job",
@@ -197,11 +204,11 @@ export class SuperSimpleQueue implements ISuperSimpleQueue {
active: monitor.isActive, active: monitor.isActive,
data: monitor, data: monitor,
}); });
} };
} else {
// Remove geo job if disabled or monitor type changed updateJob = async (monitor: Monitor) => {
this.scheduler.removeJob(geoJobId); this.scheduler.updateJob(monitor.id, { repeat: monitor.interval, data: monitor });
} await this.syncGeoJob(monitor);
}; };
shutdown = async () => { shutdown = async () => {