I’ve got this config for celery app:
from __future__ import absolute_import, unicode_literals
from datetime import timedelta
from celery import Celery
from celery.schedules import crontab
from django.conf import settings
settings.configure()
app = Celery('core', include=['core.tasks'])
app.config_from_object('django.conf:settings', namespace='CELERY')
# Load task modules from all registered Django app configs.
app.autodiscover_tasks()
app.conf.beat_schedule = {
'add-every-30-seconds': {
'task': 'core.tasks.send_not_connected',
'schedule': timedelta(seconds=30),
},
}
And I run this command to start celery
celery -A core --config=settings.dev worker -l info
I want to pass parameter from settings to task
import pika
from celery import shared_task
from core.celery import app
from django.conf import settings
@shared_task()
def send_message_to_discord(message):
url = settings.RABBITMQ_URL
connection = pika.BlockingConnection(pika.URLParameters(url))
channel = connection.channel()
channel.queue_declare(queue='discord_message_to_channel')
channel.basic_publish(exchange='', routing_key='discord_message_to_channel', body=message)
connection.close()
And I’ve got an error
AttributeError: module 'django.conf.global_settings' has no attribute 'RABBITMQ_URL'
I tried different approaches and didn’t find any working solution. I need this config because I have different setup for DEV
and PROD
, have separate files in settings
directory.