Skip to content

Commit

Permalink
Fixed problem with duplicate job_id. Instead of raising error now wri…
Browse files Browse the repository at this point in the history
…te to log and refresh job
  • Loading branch information
Stanislav Kaledin committed May 8, 2018
1 parent ea6ebb2 commit 803dbf6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 11 additions & 8 deletions django_apscheduler/jobstores.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 803dbf6

Please sign in to comment.