Hi,
I have an issue with celery and celery beats that the tasks are being duplicated.
I’ve been running Celery for about 2 months without any problems, then all of a sudden im getting duplicated entries in the database for the celery tasks.
I’m using redis as my backend/broker.
I’m finding it hard to debug the issue, i’ve checked how many workers are running on the backend and its showing only 1.
import os
from celery import Celery
from celery.schedules import crontab
# Set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app_backend.settings')
app = Celery('app_backend',
broker='redis://:#######ows.net:6379/__redisinstance__',
include=['backend.tasks'])
app.conf.timezone = 'UTC'
app.conf.beat_schedule = {
'CalculateMetrics-everyday-at-3-am': {
'task': 'backend.tasks.CalculateMetrics',
'schedule': crontab(hour=3, minute=0, day_of_week='*')
},
'CalculateMetrics-everyday-at-4-am': {
'task': 'backend.tasks.CalculateWeeklyMetrics',
'schedule': crontab(hour=4, minute=0, day_of_week='*')
},
'CalculateDailyProjectMetrics-everyday-at-2-am': {
'task': 'backend.tasks.CalculateDailyProjectMetrics',
'schedule': crontab(hour=1, minute=0, day_of_week='*')
},
'CalculateWeeklyProjectMetrics-everyday-at-2-am': {
'task': 'backend.tasks.CalculateWeeklyProjectMetrics',
'schedule': crontab(hour=2, minute=0, day_of_week='*')
}
}
app.conf.broker_transport_options = {'visibility_timeout': 3600}
#app.conf.result_backend = 'redis://:#############.net:6379'
# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')
# Load task modules from all registered Django apps.
app.autodiscover_tasks()
@app.task(bind=True, ignore_result=True)
def debug_task(self):
print(f'Request: {self.request!r}')
Nothing has changed on these settings so I’m unsure why this has just started.
I’ve also written the tasks which are using projectkeymetrics, created = DailyProjectKeyMetric.objects.get_or_create(project=project, capture_date=yesterday)
But im getting two records created which i didn’t think was possible with get_or_create