File tree Expand file tree Collapse file tree 2 files changed +9
-13
lines changed Expand file tree Collapse file tree 2 files changed +9
-13
lines changed Original file line number Diff line number Diff line change 33from django .db .models import Manager
44
55if typing .TYPE_CHECKING :
6+ from django .db .models .query import RawQuerySet
7+
68 from task_processor .models import RecurringTask , Task
79
810
911class 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
1916class 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()" )
Original file line number Diff line number Diff line change 99from django .utils import timezone
1010
1111from task_processor import metrics
12- from task_processor .managers import TaskManager
12+ from task_processor .managers import RecurringTaskManager , TaskManager
1313from 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
You can’t perform that action at this time.
0 commit comments