Skip to content

Commit

Permalink
unlink the scheduler from the previous .yaml file
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijeetSaroha committed Dec 23, 2024
1 parent 05d81d4 commit bcbb319
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/makim/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,38 @@ def __init__(self, makim_instance: Any):
self._setup_directories()
self._initialize_scheduler()
self.job_history: Dict[str, list[Dict[str, Any]]] = self._load_history()
self._sync_jobs_with_config(makim_instance.global_data.get('scheduler', {}))

def _sync_jobs_with_config(self, config_jobs: Dict[str, Any]) -> None:
"""Synchronize scheduler jobs with current config file."""
if not self.scheduler:
return

# Remove jobs not in current config
current_jobs = set(self.scheduler.get_jobs())
config_job_ids = set(config_jobs.keys())

for job in current_jobs:
if job.id not in config_job_ids:
self.scheduler.remove_job(job.id)

# Clear history for removed jobs
self.job_history = {
name: history
for name, history in self.job_history.items()
if name in config_job_ids
}
self._save_history()

def _setup_directories(self) -> None:
"""Create necessary directories for job storage."""
self.job_store_path.parent.mkdir(parents=True, exist_ok=True)

def _initialize_scheduler(self) -> None:
"""Initialize the APScheduler with SQLite backend."""
if Path(self.job_store_path).exists():
Path(self.job_store_path).unlink()

jobstores = {
'default': SQLAlchemyJobStore(url=f'sqlite:///{self.job_store_path}')
}
Expand Down

0 comments on commit bcbb319

Please sign in to comment.