queues-py3-grpc/storage/mongo/__init__.py
2024-12-07 23:18:37 +03:00

22 lines
585 B
Python

import os
import motor
import motor.motor_asyncio
import pymongo
MONGO_HOST = os.getenv('MONGO_HOST', 'localhost')
MONGO_PASSWORD = os.getenv('MONGO_PASSWORD', 'password')
CONNECTION_STRING = f'mongodb://mongo:{MONGO_PASSWORD}@{MONGO_HOST}:27017/'
database: 'motor.MotorDatabase' = motor.motor_asyncio.AsyncIOMotorClient(CONNECTION_STRING).queues
def create_indexes():
client = pymongo.MongoClient(CONNECTION_STRING)
database = client.get_database('queues')
database.get_collection('tasks').create_index([
('queue', 1),
('available_from', 1),
])