'Celery with Server MongoDB
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|