Skip to content

Commit ed1f422

Browse files
author
Anze
committed
Remove jobs when they are no longer enabled
1 parent d03800e commit ed1f422

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

collector.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ def fetch_job_configs(self, protocol):
249249
yield entity_info
250250

251251
def refresh_jobs(self):
252+
wanted_jobs = set()
252253
for job_id, intervals, job_func, job_data in self.jobs():
254+
wanted_jobs.add(job_id)
253255
# if the existing job's configuration is the same, leave it alone, otherwise the trigger will be reset:
254256
if self.known_jobs.get(job_id) == job_data:
255257
continue
@@ -259,6 +261,13 @@ def refresh_jobs(self):
259261
logging.info(f"Adding job: {job_id}")
260262
self.scheduler.add_job(job_func, id=job_id, trigger=trigger, executor='iaexecutor', kwargs=job_data, replace_existing=True)
261263

264+
# remove any jobs that are currently running but are no longer wanted:
265+
existing_jobs = set(self.known_jobs.keys())
266+
to_be_removed = existing_jobs - wanted_jobs
267+
for job_id in to_be_removed:
268+
del self.known_jobs[job_id]
269+
self.scheduler.remove_job(job_id)
270+
262271
def execute(self):
263272
"""
264273
Calls self.jobs() to get the list of the jobs, and executes them by using

0 commit comments

Comments
 (0)