I have a celery task that is scheduled to run at a specific time of the day.
The problem is this task is getting executed multiple times, so I am receiving the same email at least 2 to 3 times.
@periodic_task(run_every=crontab(hour=7, minute=10))
def send_reminder_email_at_7():
obj = Service()
obj.send_email()
return
On server, I have setup the project using gunicorn and the supervisor
Following is the configuration of celery and celery beat
[program:proj_worker]
command=/home/ubuntu/venv/bin/celery -A baseproj worker -l debug
directory=/home/ubuntu/proj/
user=ubuntu
numprocs=1
stdout_logfile=/home/ubuntu/logs/celerylogs/proj_worker.log
stderr_logfile=/home/ubuntu/logs/celerylogs/proj_worker_err.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs = 600
killasgroup=true
priority=998
[program:proj_beat]
command=/home/ubuntu/venv/bin/celery -A baseproj beat -l debug --scheduler django_celery_beat.schedulers:DatabaseScheduler
directory=/home/ubuntu/proj/
user=ubuntu
numprocs=1
stdout_logfile=/home/ubuntu/logs/celerylogs/proj_beat.log
stderr_logfile=/home/ubuntu/logs/celerylogs/proj_beat_err.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs = 600
killasgroup=true
priority=998
Following is gunicorn configuration
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/home/ubuntu/proj
ExecStart=/home/ubuntu/venv/bin/gunicorn --access-logfile /home/ubuntu/logs/gunicorn/gunicorn-access.log --error-logfile /home/ubuntu/logs/gunicorn/gunicorn-error.log --workers 3 --bind unix:/home/ubuntu/proj/proj.sock baseproj.wsgi
[Install]
WantedBy=multi-user.target
question from:
https://stackoverflow.com/questions/65868518/celery-periodic-task-getting-executed-multiple-times 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…