Yelp / elastalert

Easy & Flexible Alerting With ElasticSearch
https://elastalert.readthedocs.org
Apache License 2.0
7.99k stars 1.74k forks source link

apscheduler.jobstores.base.ConflictingIdError: 'Job identifier (rule1) conflicts with an existing job' #3209

Open ragh77 opened 3 years ago

ragh77 commented 3 years ago

Issue Description:

version: elastalert 0.2.4

If we delete and add a rule after the rule gets added to disabled rules list( for example: disabled due to uncaught exception), we see an ConflictingIdError.

ERROR apscheduler.executors.default Job "ElastAlerter.handle_config_change (trigger: interval[0:00:10], next run at: 2021-09-03 22:27:54 UTC)" raised an exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/apscheduler/executors/base.py", line 125, in run_job
    retval = job.func(*job.args, **job.kwargs)
  File "/usr/local/lib/python3.6/dist-packages/elastalert/elastalert.py", line 1235, in handle_config_change
    self.load_rule_changes()
  File "/usr/local/lib/python3.6/dist-packages/elastalert/elastalert.py", line 1133, in load_rule_changes
    if self.init_rule(new_rule):
  File "/usr/local/lib/python3.6/dist-packages/elastalert/elastalert.py", line 1036, in init_rule
    jitter=5)
  File "/usr/local/lib/python3.6/dist-packages/apscheduler/schedulers/base.py", line 443, in add_job
    self._real_add_job(job, jobstore, replace_existing)
  File "/usr/local/lib/python3.6/dist-packages/apscheduler/schedulers/base.py", line 867, in _real_add_job
    store.add_job(job)
  File "/usr/local/lib/python3.6/dist-packages/apscheduler/jobstores/memory.py", line 41, in add_job
    raise ConflictingIdError(job.id)
apscheduler.jobstores.base.ConflictingIdError: 'Job identifier (rule1) conflicts with an existing job'

Its causing major impact(stops processing/loading other rules) when the disabled rule processed first after all the elastalert rules were removed and added back. It impacts until we restart the elastalert. It would be nice to clear the rule from disabled rules list when we remove the rule without restarting elastalert.

wuyazibest commented 2 years ago

you used apscheduler ,in function add_job add options replace_existing=True,You can run it again without this error like this:

scheduler.add_job(task1, id="job_1", replace_existing=True, trigger="cron", hour=4, minute=4)
hari17691a0447 commented 2 years ago

we can store the job but we can't fetch the job from the db please help me to how to fetch the job from db and run at particular time and date