-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
a09c34d
commit 21cd663
Showing
26 changed files
with
892 additions
and
127 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
"""Main entry point.""" | ||
|
||
import asyncio | ||
import contextlib | ||
|
||
import uvicorn | ||
import uvloop | ||
|
||
from app import logger # noqa # ensure that logging is configured | ||
from app.config import settings | ||
from app.db.session import database_session_manager | ||
from app.queue.consumer.long_jobs import LongJobsQueueConsumer | ||
from app.queue.consumer.short_jobs import ShortJobsQueueConsumer | ||
from app.queue.consumer.storage import StorageQueueConsumer | ||
|
||
|
||
async def main(): | ||
"""Init and run all the async tasks.""" | ||
database_session_manager.initialize( | ||
url=settings.DB_URI, | ||
pool_size=settings.DB_POOL_SIZE, | ||
pool_pre_ping=settings.DB_POOL_PRE_PING, | ||
max_overflow=settings.DB_MAX_OVERFLOW, | ||
) | ||
server = uvicorn.Server( | ||
uvicorn.Config( | ||
"app.application:app", | ||
host="0.0.0.0", | ||
port=settings.UVICORN_PORT, | ||
proxy_headers=True, | ||
log_config=settings.LOGGING_CONFIG, | ||
) | ||
) | ||
storage_queue_consumer = StorageQueueConsumer( | ||
endpoint_url=settings.SQS_ENDPOINT_URL, | ||
queue_name=settings.SQS_QUEUES["storage"], | ||
initial_delay=1, | ||
) | ||
short_jobs_queue_consumer = ShortJobsQueueConsumer( | ||
endpoint_url=settings.SQS_ENDPOINT_URL, | ||
queue_name=settings.SQS_QUEUES["short-jobs"], | ||
initial_delay=2, | ||
) | ||
long_jobs_queue_consumer = LongJobsQueueConsumer( | ||
endpoint_url=settings.SQS_ENDPOINT_URL, | ||
queue_name=settings.SQS_QUEUES["long-jobs"], | ||
initial_delay=3, | ||
) | ||
try: | ||
async with asyncio.TaskGroup() as tg: | ||
tg.create_task(storage_queue_consumer.run_forever()) | ||
tg.create_task(short_jobs_queue_consumer.run_forever()) | ||
tg.create_task(long_jobs_queue_consumer.run_forever()) | ||
tg.create_task(server.serve()) | ||
finally: | ||
await database_session_manager.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
with contextlib.suppress(KeyboardInterrupt): | ||
uvloop.run(main()) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from enum import StrEnum | ||
|
||
|
||
class ServiceType(StrEnum): | ||
STORAGE = "storage" | ||
SHORT_JOBS = "short-jobs" | ||
LONG_JOBS = "long-jobs" | ||
|
||
|
||
class QueueMessageStatus(StrEnum): | ||
COMPLETED = "completed" | ||
FAILED = "failed" |
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
Oops, something went wrong.