1515from app .infrastructure .worker .tasks .simple_task import heartbeat_task
1616from app .logger import logger
1717
18- # `saq` import its own settings and hides our module
19- from app .settings import settings as app_settings
18+ from app .settings import settings
2019
2120SaqCtx = Dict [str , Any ]
2221
2322
23+ # queue = Queue(aioredis.from_url(settings.REDIS_DSN), name="bot_template")
24+ queue = Queue .from_url (settings .REDIS_DSN , name = "bot_template_worker" )
2425
25- queue = Queue (aioredis .from_url (app_settings .REDIS_DSN ), name = "bot_refactor" )
2626
2727@inject
2828async def _startup_with_injection (
@@ -45,11 +45,7 @@ async def _shutdown_with_injection(
4545async def startup (ctx : SaqCtx ) -> None :
4646 worker_startup_container = WorkerStartupContainer ()
4747
48- queue .add_cron_job (
49- CronJob (function = heartbeat_task , cron = "*/5 * * * * *" , unique = True )
50- )
5148 worker_startup_container .wire (modules = [__name__ , "app.infrastructure.worker.tasks" ])
52-
5349 await _startup_with_injection ()
5450
5551 logger .info ("Worker started" )
@@ -60,21 +56,18 @@ async def shutdown(ctx: SaqCtx) -> None:
6056 logger .info ("Worker stopped" )
6157
6258
63- settings = {
59+ saq_settings = {
6460 "queue" : queue ,
6561 "functions" : [],
66- # "cron_jobs": [
67- # CronJob(
68- # function=heartbeat_task,
69- # cron="*/5 * * * * *",
70- # unique=True,
71- # # timeout=app_settings.PERIODIC_TASKS_DEFAULT_TIMEOUT,
72- # # heartbeat=app_settings.PERIODIC_TASKS_DEFAULT_HEARTBEAT,
73- # # retries=app_settings.PERIODIC_TASKS_DEFAULT_RETRIES,
74- # # ttl=app_settings.PERIODIC_TASKS_DEFAULT_TTL,
75- # ),
76- # ],
77- "concurrency" : 8 ,
62+ "cron_jobs" : [
63+ CronJob (
64+ function = heartbeat_task ,
65+ cron = "* * * * * */5" ,
66+ unique = False ,
67+ timeout = 15 ,
68+ ),
69+ ],
70+ "concurrency" : settings .WORKER_CONCURRENCY ,
7871 "startup" : startup ,
7972 "shutdown" : shutdown ,
8073}
0 commit comments