Skip to content

Commit 521c7c9

Browse files
committed
Improve typing
1 parent 0dbc71f commit 521c7c9

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

src/task_processor/managers.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,16 @@
33
from django.db.models import Manager
44

55
if typing.TYPE_CHECKING:
6+
from django.db.models.query import RawQuerySet
7+
68
from task_processor.models import RecurringTask, Task
79

810

911
class TaskManager(Manager["Task"]):
10-
def get_tasks_to_process(self, num_tasks: int) -> typing.List["Task"]:
11-
return list(
12-
self.raw(
13-
"SELECT * FROM get_tasks_to_process(%s)",
14-
[num_tasks],
15-
),
16-
)
12+
def get_tasks_to_process(self, num_tasks: int) -> "RawQuerySet[Task]":
13+
return self.raw("SELECT * FROM get_tasks_to_process(%s)", [num_tasks])
1714

1815

1916
class RecurringTaskManager(Manager["RecurringTask"]):
20-
def get_tasks_to_process(self) -> typing.List["RecurringTask"]:
21-
return list(
22-
self.raw("SELECT * FROM get_recurringtasks_to_process()"),
23-
)
17+
def get_tasks_to_process(self) -> "RawQuerySet[RecurringTask]":
18+
return self.raw("SELECT * FROM get_recurringtasks_to_process()")

src/task_processor/processor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from django.utils import timezone
1010

1111
from task_processor import metrics
12-
from task_processor.managers import TaskManager
12+
from task_processor.managers import RecurringTaskManager, TaskManager
1313
from task_processor.models import (
1414
AbstractBaseTask,
1515
RecurringTask,
@@ -68,7 +68,8 @@ def run_recurring_tasks(database: str) -> list[RecurringTaskRun]:
6868
# NOTE: We will probably see a lot of delay in the execution of recurring tasks
6969
# if the tasks take longer then `run_every` to execute. This is not
7070
# a problem for now, but we should be mindful of this limitation
71-
tasks = RecurringTask.objects.db_manager(database).get_tasks_to_process()
71+
task_manager: RecurringTaskManager = RecurringTask.objects.db_manager(database)
72+
tasks = task_manager.get_tasks_to_process()
7273
if tasks:
7374
logger.debug(f"Running {len(tasks)} recurring task(s)")
7475

0 commit comments

Comments
 (0)