Home:ALL Converter>Celery with Server MongoDB

Celery with Server MongoDB

Ask Time:2022-05-06T20:04:24         Author:Jacek Dłubak

Json Formatter

Working on getting Celery setup with a mongodb as result_backend. Following the configuration guidelines set out in the official docs, my celeryconfig.py is setup as follows:

class CeleryConfig:
    # Celery Config Available fields listed here:
    # https://docs.celeryq.dev/en/stable/userguide/configuration.html
    imports = imports
    broker_url = broker_url
    result_backend = "mongodb+srv://admin:[email protected]/"
    accept_content = ["json"]
    result_serializer = "json"
    task_serializer = "json"
    mongodb_backend_settings = {
        "database": db_name,
        "taskmeta_collection": db_name,
    }

PYPROJECT.toml file

[tool.poetry.dependencies]
python = "^3.9"
boto3 = "^1.21.17"
celery = "^5.2.3"
mongoengine = "^0.24.1"
# Initialization of Celery APP
app = Celery(backend=CELERY_BACKEND_URL)
app.config_from_object(CeleryConfig)

celery worker log also states that url is changed from -> "mongodb+srv://admin:[email protected]/" to -> [config] results: mongodb://admin:[email protected]/

error I am getting executing any task ->

 pymongo.errors.ServerSelectionTimeoutError: testing.company.mongodb.net:27017: [Errno -2] Name or service not known, Timeout: 30s, Topology Description: <TopologyDescription id: 62750b2e5b92d32d7cf08a22, topology_type: Unknown, servers: [<
ServerDescription ('testing.company.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('testing.company.mongodb.net:27017: [Errno -2] Name or service not known')>]>

For some reason it it pushes the port into my url and mongodb+srv:// URL cannot have port number

Author:Jacek Dłubak,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/72141189/celery-with-server-mongodb
yy