cameronmaske / celery-once

Celery Once allows you to prevent multiple execution and queuing of celery tasks.
https://pypi.python.org/pypi/celery_once/
BSD 2-Clause "Simplified" License
661 stars 90 forks source link

Django #77

Closed basitiyidir closed 5 years ago

basitiyidir commented 6 years ago

It does not work in Django applications. Are you aware?

basitiyidir commented 6 years ago

celery.py

from __future__ import absolute_import

import os

import django
from celery import Celery
from decouple import config
from django.conf import settings

from celery_once import QueueOnce
from time import sleep

app = Celery('myapp')

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myapp.settings')
app.conf.ONCE = settings.CELERY_ONCE
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

settings.py

CELERY_ONCE = {
      'backend': 'celery_once.backends.Redis',
      'settings': {
        'url': 'redis://127.0.0.1:6379/0',
        'default_timeout': 60 * 60
      }
}
Arti3DPlayer commented 5 years ago

the same

mizhgun commented 5 years ago

You shouldn't assign app.conf.ONCE before loading settings with app.config_from_object because the latter overwrites the whole app.conf.

cameronmaske commented 5 years ago

@basitiyidir as @mizhgun (thanks for chiming in!) the order of app.conf.ONCE really matters here. Did that resolve the issue? I'm closing this one out, but can re-open it if that is not the case.