-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
340 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Tasks worker configuration.""" | ||
|
||
from typing import Any, Dict, Literal | ||
|
||
from pybotx import Bot | ||
from redis import asyncio as aioredis | ||
from saq import Queue | ||
|
||
from app.caching.callback_redis_repo import CallbackRedisRepo | ||
from app.logger import logger | ||
|
||
# `saq` import its own settings and hides our module | ||
from app.settings import settings as app_settings | ||
|
||
SaqCtx = Dict[str, Any] | ||
|
||
|
||
async def startup(ctx: SaqCtx) -> None: | ||
from app.bot.bot import get_bot # noqa: WPS433 | ||
|
||
callback_repo = CallbackRedisRepo(aioredis.from_url(app_settings.REDIS_DSN)) | ||
bot = get_bot(callback_repo) | ||
|
||
await bot.startup(fetch_tokens=False) | ||
|
||
ctx["bot"] = bot | ||
|
||
logger.info("Worker started") | ||
|
||
|
||
async def shutdown(ctx: SaqCtx) -> None: | ||
bot: Bot = ctx["bot"] | ||
await bot.shutdown() | ||
|
||
logger.info("Worker stopped") | ||
|
||
|
||
async def healthcheck(_: SaqCtx) -> Literal[True]: | ||
return True | ||
|
||
|
||
queue = Queue(aioredis.from_url(app_settings.REDIS_DSN), name="{{bot_project_name}}") | ||
|
||
settings = { | ||
"queue": queue, | ||
"functions": [healthcheck], | ||
"cron_jobs": [], | ||
"concurrency": 8, | ||
"startup": startup, | ||
"shutdown": shutdown, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.