diff --git a/django_apscheduler/jobstores.py b/django_apscheduler/jobstores.py index 8e59c2b..dbad7c8 100644 --- a/django_apscheduler/jobstores.py +++ b/django_apscheduler/jobstores.py @@ -88,17 +88,20 @@ def get_all_jobs(self): @ignore_database_error() def add_job(self, job): - if DjangoJob.objects.filter( - name=job.id - ).exists(): - raise ConflictingIdError(job.id) - - DjangoJob.objects.create( + dbJob, created = DjangoJob.objects.get_or_create( + defaults=dict( + next_run_time=serialize_dt(job.next_run_time), + job_state=pickle.dumps(job.__getstate__(), self.pickle_protocol) + ), name=job.id, - next_run_time=serialize_dt(job.next_run_time), - job_state=pickle.dumps(job.__getstate__(), self.pickle_protocol) ) + if not created: + LOGGER.warning("Job with id %s already in jobstore. I'll refresh it", job.id) + dbJob.next_run_time = serialize_dt(job.next_run_time) + dbJob.job_state=pickle.dumps(job.__getstate__(), self.pickle_protocol) + dbJob.save() + @ignore_database_error() def update_job(self, job): updated = DjangoJob.objects.filter(name=job.id).update( diff --git a/setup.py b/setup.py index 268083f..560ea69 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='django-apscheduler', - version='0.2.8', + version='0.2.9', description='APScheduler for Django', classifiers=[ "Development Status :: 4 - Beta",