1313
1414if TYPE_CHECKING :
1515 from collections .abc import Collection
16- from signal import Signals
1716
1817 from redis .asyncio .client import Redis
19- from saq .types import DumpType , Function , LoadType , PartialTimersDict , ReceivesContext
18+ from saq .types import DumpType as SaqDumpType
19+ from saq .types import Function , LoadType , PartialTimersDict , ReceivesContext
20+
21+ from litestar_saq .config import DumpType
2022
2123
2224@dataclass
@@ -64,7 +66,7 @@ def __init__(
6466 queue_namespace : str | None = None ,
6567 ) -> None :
6668 self ._namespace = queue_namespace if queue_namespace is not None else "saq"
67- super ().__init__ (redis , name , dump , load , max_concurrent_ops )
69+ super ().__init__ (redis , name , cast ( "SaqDumpType" , dump ) , load , max_concurrent_ops )
6870
6971 def namespace (self , key : str ) -> str :
7072 """Make the namespace unique per app."""
@@ -85,8 +87,10 @@ def job_id(self, job_key: str) -> str:
8587class Worker (SaqWorker ):
8688 """Worker."""
8789
90+ """
8891 # same issue: https://github.com/samuelcolvin/arq/issues/182
8992 SIGNALS: list[Signals] = []
93+ """
9094
9195 def __init__ (
9296 self ,
@@ -101,7 +105,9 @@ def __init__(
101105 after_process : ReceivesContext | None = None ,
102106 timers : PartialTimersDict | None = None ,
103107 dequeue_timeout : float = 0 ,
108+ separate_process : bool = True ,
104109 ) -> None :
110+ self .separate_process = separate_process
105111 super ().__init__ (
106112 cast ("SaqQueue" , queue ),
107113 functions ,
@@ -117,5 +123,13 @@ def __init__(
117123
118124 async def on_app_startup (self ) -> None :
119125 """Attach the worker to the running event loop."""
120- loop = asyncio .get_running_loop ()
121- _ = loop .create_task (self .start ())
126+ if not self .separate_process :
127+ self .SIGNALS = []
128+ loop = asyncio .get_running_loop ()
129+ _ = loop .create_task (self .start ())
130+
131+ async def on_app_shutdown (self ) -> None :
132+ """Attach the worker to the running event loop."""
133+ if not self .separate_process :
134+ loop = asyncio .get_running_loop ()
135+ _ = loop .create_task (self .stop ())
0 commit comments