@@ -146,15 +146,18 @@ export class SuperSimpleQueue implements ISuperSimpleQueue {
146146
147147 deleteJob = async ( monitor : Monitor ) => {
148148 this . scheduler . removeJob ( monitor . id ) ;
149- this . scheduler . removeJob ( `${ monitor . id } -geo` ) ;
149+ const geoJob = await this . scheduler . getJob ( `${ monitor . id } -geo` ) ;
150+ if ( geoJob ) await this . scheduler . removeJob ( `${ monitor . id } -geo` ) ;
150151 } ;
151152
152153 pauseJob = async ( monitor : Monitor ) => {
153154 const result = await this . scheduler . pauseJob ( monitor . id ) ;
154155 if ( result === false ) {
155156 throw new Error ( "Failed to pause monitor" ) ;
156157 }
157- await this . scheduler . pauseJob ( `${ monitor . id } -geo` ) ;
158+ const geoJob = await this . scheduler . getJob ( `${ monitor . id } -geo` ) ;
159+ if ( geoJob ) await this . scheduler . removeJob ( `${ monitor . id } -geo` ) ;
160+
158161 this . logger . debug ( {
159162 message : `Paused monitor ${ monitor . id } ` ,
160163 service : SERVICE_NAME ,
@@ -177,31 +180,35 @@ export class SuperSimpleQueue implements ISuperSimpleQueue {
177180 } ) ;
178181 } ;
179182
180- updateJob = async ( monitor : Monitor ) => {
181- this . scheduler . updateJob ( monitor . id , { repeat : monitor . interval , data : monitor } ) ;
182-
183- // Handle geo check job lifecycle
183+ private syncGeoJob = async ( monitor : Monitor ) => {
184184 const geoJobId = `${ monitor . id } -geo` ;
185- if ( monitor . geoCheckEnabled && supportsGeoCheck ( monitor . type ) ) {
186- // Check if geo job exists
187- const existingGeoJob = await this . scheduler . getJob ( geoJobId ) ;
188- if ( existingGeoJob ) {
189- // Update existing geo job
190- this . scheduler . updateJob ( geoJobId , { repeat : monitor . geoCheckInterval , active : monitor . isActive , data : monitor } ) ;
191- } else {
192- // Create new geo job
193- this . scheduler . addJob ( {
194- id : geoJobId ,
195- template : "geo-check-job" ,
196- repeat : monitor . geoCheckInterval ,
197- active : monitor . isActive ,
198- data : monitor ,
199- } ) ;
200- }
201- } else {
202- // Remove geo job if disabled or monitor type changed
203- this . scheduler . removeJob ( geoJobId ) ;
185+ const existingGeoJob = await this . scheduler . getJob ( geoJobId ) ;
186+
187+ // If geoChecks have been disabled, or the monitor type doesn't support them, remove
188+ if ( ! monitor . geoCheckEnabled || ! supportsGeoCheck ( monitor . type ) ) {
189+ if ( existingGeoJob ) this . scheduler . removeJob ( geoJobId ) ;
190+ return ;
191+ }
192+
193+ // If the job exists, update it
194+ if ( existingGeoJob ) {
195+ this . scheduler . updateJob ( geoJobId , { repeat : monitor . geoCheckInterval , active : monitor . isActive , data : monitor } ) ;
196+ return ;
204197 }
198+
199+ // Otherwise, create it
200+ this . scheduler . addJob ( {
201+ id : geoJobId ,
202+ template : "geo-check-job" ,
203+ repeat : monitor . geoCheckInterval ,
204+ active : monitor . isActive ,
205+ data : monitor ,
206+ } ) ;
207+ } ;
208+
209+ updateJob = async ( monitor : Monitor ) => {
210+ this . scheduler . updateJob ( monitor . id , { repeat : monitor . interval , data : monitor } ) ;
211+ await this . syncGeoJob ( monitor ) ;
205212 } ;
206213
207214 shutdown = async ( ) => {
0 commit comments