Skip to content

Commit f5e19c2

Browse files
committed
remove dependency on django-tasks
1 parent 0725a14 commit f5e19c2

11 files changed

Lines changed: 32 additions & 60 deletions

File tree

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Steady Queue can be used with SQL databases such as MySQL, PostgreSQL or SQLite,
1313

1414
## Installation
1515

16-
1. **Install the `steady_queue` package.** Since Steady Queue depends on interfaces defined by DEP 0014 which has not become part of Django yet, it will add django-tasks (the reference implementation) as a dependency.
17-
2. **Add `steady_queue` and `django_tasks` to your `INSTALLED_APPS`** in `settings.py`.
16+
1. **Install the `steady_queue` package.**
17+
2. **Add `steady_queue` to your `INSTALLED_APPS`** in `settings.py`.
1818
3. **Configure Steady Queue as a task backend.** In `settings.py`, add the Steady Queue backend:
1919
```python
2020
TASKS = {
@@ -36,11 +36,10 @@ For small projects, you can run Steady Queue on the same machine as your webserv
3636

3737
Steady Queue works like any other DEP 0014-compatible task backend.
3838

39-
Tasks are functions decorated with the `@task` decorator from `django_tasks`
40-
(which will become `django.tasks` once integrated into Django):
39+
Tasks are functions decorated with the `@task` decorator from `django.tasks`:
4140

4241
```python
43-
from django_tasks import task
42+
from django.task import task
4443

4544
@task()
4645
def greet(name: str, times: int = 1):
@@ -392,7 +391,7 @@ Steady Queue extends Django Tasks with concurrency controls, that allows you to
392391

393392

394393
```python
395-
from django_tasks import task
394+
from django.tasks import task
396395

397396
from steady_queue.concurrency import limits_concurrency
398397

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ classifiers = [
2020
dependencies = [
2121
"crontab>=1.0.5",
2222
"django>=6.0,<7",
23-
"django-tasks>=0.8.1,<0.9.0",
2423
]
2524

2625
[project.urls]

steady_queue/backend.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from django_tasks import ResultStatus, Task, TaskResult
2-
from django_tasks.backends.base import BaseTaskBackend
3-
from django_tasks.task import P, T
1+
from django.tasks import Task, TaskResult, TaskResultStatus
2+
from django.tasks.backends.base import BaseTaskBackend
43

54
from steady_queue.task import SteadyQueueTask
65

@@ -18,9 +17,7 @@ def validate_task(self, task: Task) -> None:
1817
# TODO: do we need to do anything here?
1918
super().validate_task(task)
2019

21-
def enqueue(
22-
self, task: Task[P, T], args: P.args, kwargs: P.kwargs
23-
) -> TaskResult[T]:
20+
def enqueue(self, task, args, kwargs) -> TaskResult:
2421
from steady_queue.models import Job
2522

2623
if not isinstance(task, SteadyQueueTask):
@@ -40,7 +37,7 @@ def _to_task_result(self, task: SteadyQueueTask, job) -> TaskResult:
4037
return TaskResult(
4138
task=task,
4239
id=str(job.id),
43-
status=ResultStatus("READY"),
40+
status=TaskResultStatus.READY,
4441
enqueued_at=job.created_at,
4542
started_at=None,
4643
finished_at=job.finished_at,

steady_queue/concurrency.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from dataclasses import replace
12
from datetime import timedelta
23
from typing import Optional
34

@@ -12,13 +13,13 @@ def limits_concurrency(
1213
group: Optional[str] = None,
1314
):
1415
def wrapper(task: SteadyQueueTask):
15-
task.concurrency_key = key
16-
task.concurrency_limit = to
17-
task.concurrency_duration = (
18-
duration or steady_queue.default_concurrency_control_period
16+
return replace(
17+
task,
18+
concurrency_key=key,
19+
concurrency_limit=to,
20+
concurrency_duration=duration
21+
or steady_queue.default_concurrency_control_period,
22+
concurrency_group=group or task.module_path,
1923
)
20-
task.concurrency_group = group or task.module_path
21-
22-
return task
2324

2425
return wrapper

steady_queue/models/recurring_execution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from django.db import models
2-
from django_tasks import TaskResult
2+
from django.tasks import TaskResult
33

44
from .execution import Execution, ExecutionQuerySet
55

steady_queue/recurring_task.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
from dataclasses import replace
23
from typing import Optional
34

45
from steady_queue.configuration import Configuration
@@ -36,8 +37,6 @@ def wrapper(task: SteadyQueueTask):
3637
"The given task does not look to be a Django task. Did you forget to decorate it with @task()?"
3738
)
3839

39-
task.args = args
40-
task.kwargs = kwargs
4140
configuration = Configuration.RecurringTask(
4241
key=key,
4342
class_name=class_name,
@@ -49,6 +48,6 @@ def wrapper(task: SteadyQueueTask):
4948
)
5049
configurations.append(configuration)
5150

52-
return task
51+
return replace(task, args=args, kwargs=kwargs)
5352

5453
return wrapper

steady_queue/task.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import datetime
22
import uuid
3+
from dataclasses import dataclass, replace
34
from typing import Any, Optional
45

6+
from django.tasks import Task, TaskResult
57
from django.utils import timezone, translation
68
from django.utils.module_loading import import_string
7-
from django_tasks import Task
8-
from django_tasks.task import P, T, TaskResult
99

1010
from steady_queue.arguments import Arguments
1111

@@ -14,18 +14,18 @@ class UnknownTaskClassError(Exception):
1414
pass
1515

1616

17-
class SteadyQueueTask(Task[P, T]):
18-
args: P.args
19-
kwargs: P.kwargs
17+
@dataclass(frozen=True, slots=True, kw_only=True)
18+
class SteadyQueueTask(Task):
19+
args: Optional[list[Any]] = None
20+
kwargs: Optional[dict[str, Any]] = None
2021

2122
concurrency_key: Optional[str] = None
2223
concurrency_limit: Optional[int] = None
2324
concurrency_duration: Optional[timezone.timedelta] = None
2425
concurrency_group: Optional[str] = None
2526

2627
def __post_init__(self):
27-
super().__post_init__()
28-
self.arguments = {}
28+
self.get_backend().validate_task(self)
2929

3030
@property
3131
def id(self) -> str:
@@ -49,12 +49,9 @@ def using(
4949
backend=backend,
5050
)
5151

52-
def enqueue(self, *args: P.args, **kwargs: P.kwargs) -> "TaskResult[T]":
52+
def enqueue(self, *args: Any, **kwargs: Any) -> TaskResult:
5353
return self.get_backend().enqueue(self, args, kwargs)
5454

55-
def set_arguments(self, arguments: dict[str, Any]):
56-
self.arguments = arguments
57-
5855
def serialize(self):
5956
return {
6057
"class_name": self.module_path,
@@ -87,8 +84,5 @@ def deserialize(cls, job_data: dict[str, Any]):
8784
run_after=job_data["scheduled_at"],
8885
backend=job_data["backend"],
8986
)
90-
91-
task.args, task.kwargs = Arguments.deserialize_args_and_kwargs(
92-
job_data["arguments"]
93-
)
94-
return task
87+
args, kwargs = Arguments.deserialize_args_and_kwargs(job_data["arguments"])
88+
return replace(task, args=args, kwargs=kwargs)

tests/dummy/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import time
22

3-
from django_tasks import task
3+
from django.tasks import task
44

55
from steady_queue.concurrency import limits_concurrency
66
from steady_queue.recurring_task import recurring

tests/settings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
SECRET_KEY = "fake-key"
1313

1414
INSTALLED_APPS = [
15-
"django_tasks",
1615
"django.contrib.admin",
1716
"django.contrib.auth",
1817
"django.contrib.contenttypes",

tests/test_recurring_task.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
from django.tasks import task
12
from django.test import SimpleTestCase
2-
from django_tasks import task
33

44
from steady_queue.recurring_task import configurations, recurring
55

0 commit comments

Comments
 (0)