Skip to content

Commit cf41181

Browse files
committed
Remove support for timedelta for run_after
It's not obvious when the delta is evaluated, so could be a foot-gun
1 parent ce43889 commit cf41181

File tree

3 files changed

+3
-11
lines changed

3 files changed

+3
-11
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ These attributes (besides `enqueue_on_commit`) can also be modified at run-time
7575
modified_task = calculate_meaning_of_life.using(priority=10)
7676
```
7777

78-
In addition to the above attributes, `run_after` can be passed to specify a specific time the task should run. Both a timezone-aware `datetime` or `timedelta` may be passed.
78+
In addition to the above attributes, `run_after` can be passed to specify a specific time the task should run.
7979

8080
### Enqueueing tasks
8181

django_tasks/task.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
from asgiref.sync import async_to_sync, sync_to_async
1919
from django.db.models.enums import TextChoices
20-
from django.utils import timezone
2120
from django.utils.translation import gettext_lazy as _
2221
from typing_extensions import ParamSpec, Self
2322

@@ -110,10 +109,7 @@ def using(
110109
if queue_name is not None:
111110
changes["queue_name"] = queue_name
112111
if run_after is not None:
113-
if isinstance(run_after, timedelta):
114-
changes["run_after"] = timezone.now() + run_after
115-
else:
116-
changes["run_after"] = run_after
112+
changes["run_after"] = run_after
117113
if backend is not None:
118114
changes["backend"] = backend
119115

tests/tests/test_tasks.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import dataclasses
2-
from datetime import datetime, timedelta
2+
from datetime import datetime
33

44
from django.test import SimpleTestCase, override_settings
55
from django.utils import timezone
@@ -97,10 +97,6 @@ def test_using_run_after(self) -> None:
9797

9898
self.assertIsNone(test_tasks.noop_task.run_after)
9999
self.assertEqual(test_tasks.noop_task.using(run_after=now).run_after, now)
100-
self.assertIsInstance(
101-
test_tasks.noop_task.using(run_after=timedelta(hours=1)).run_after,
102-
datetime,
103-
)
104100
self.assertIsNone(test_tasks.noop_task.run_after)
105101

106102
def test_using_unknown_backend(self) -> None:

0 commit comments

Comments
 (0)