Skip to content

Commit

Permalink
enh(models): Add unique_job_executions to ensure uniqueness of `Dja…
Browse files Browse the repository at this point in the history
…ngoJobExecution`s.
  • Loading branch information
jcass77 committed Nov 17, 2021
1 parent bdac27c commit f49c883
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions django_apscheduler/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import timedelta, datetime

from django.db import models, transaction
from django.db.models import UniqueConstraint
from django.utils import timezone
from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -213,3 +214,8 @@ def __str__(self):

class Meta:
ordering = ("-run_time",)
constraints = [
UniqueConstraint(
fields=["job_id", "run_time"], name="unique_job_executions"
)
]
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ This changelog is used to track all major changes to django-apscheduler.
**Fixes**

- Also handle `db.InterfaceError` when retrying database-related operations (thanks @zmmfsj-z).
- Add `unique_job_executions` constraint to ensure that only one `DjangoJobExecution` can be created for
each `DjangoJob`
for a specific run time.

## v0.6.0 (2021-06-17)

Expand Down

0 comments on commit f49c883

Please sign in to comment.