celery-singleton icon indicating copy to clipboard operation
celery-singleton copied to clipboard

Include parse-url support for rabbitmq (amqp://) scheme

Open itstimotei opened this issue 3 years ago • 4 comments

Problem: Singleton base are not supported if rabbitmq broker are used to assimilate the tasks. Error: Redis URL must specify one of the following schemes (redis://, rediss://, unix://)

If there is another way to use singleton with the rabbitmq broker, I would be very grateful to know. Thanks!

recap: the problem is that when I use rabbitmq as a broker, I can't use Singleton property inside of decorator as a base, because parse_url method doesn't support the rabbitmq system

env.config file:

CELERY_BROKER_HOST=redis://127.0.0.1:6379

tasks.py file:

@app.task(base=Singleton, name="create_or_update_user")
def create_or_update(user_id: str):
    data = async_to_sync(update_or_create_user)(user_id=user_id)

    return data

create_user.py file:

data = create_or_update.apply_async(
       args=[user_id],
       countdown=CELERY_TASKS_COUNTDOWN, 
)

itstimotei avatar Aug 08 '22 16:08 itstimotei

Singleton requires redis for the locking backend, but redis does not need to be your broker.

Set CELERY_SINGLETON_BACKEND_URL to a valid redis url. You can then use rabbitmq as a broker.

steinitzu avatar Sep 01 '22 00:09 steinitzu

@steinitzu same. This doesn't work!

itstimotei avatar Sep 06 '22 17:09 itstimotei

@steinitzu Do you have another proposal? 😃

itstimotei avatar Sep 06 '22 17:09 itstimotei

Had the same error. This worked for me (Django example, using old Celery 4.3.1):

app.config_from_object('django.conf:settings', namespace='CELERY')
app.conf.singleton_backend_url = settings.CELERY_SINGLETON_BACKEND_URL

jdavid avatar Feb 15 '23 17:02 jdavid