* Celery deployment configs

This commit is contained in:
Phil Zhitnikov 2023-12-07 06:23:11 +04:00
parent 46ff6b9d8b
commit a2b92ab029
9 changed files with 86 additions and 26 deletions

28
_deploy/celery Normal file
View File

@ -0,0 +1,28 @@
# Name of nodes to start
# here we have a single node
CELERYD_NODES="w1"
# or we could have three nodes:
#CELERYD_NODES="w1 w2 w3"
# Absolute or relative path to the 'celery' command:
CELERY_BIN="/var/www/phzhik-poizonstore/env/bin/celery"
# App instance to use
CELERY_APP="poizonstore"
# How to call manage.py
CELERYD_MULTI="multi"
# Extra command-line arguments to the worker
CELERYD_OPTS=""
# - %n will be replaced with the first part of the nodename.
# - %I will be replaced with the current child process index
# and is important when using the prefork pool to avoid race conditions.
CELERYD_PID_FILE="/var/run/celery/%n.pid"
CELERYD_LOG_FILE="/var/log/celery/%n%I.log"
CELERYD_LOG_LEVEL="INFO"
# you may wish to add these options for Celery Beat
CELERYBEAT_PID_FILE="/var/run/celery/beat.pid"
CELERYBEAT_LOG_FILE="/var/log/celery/beat.log"

24
_deploy/celery.service Normal file
View File

@ -0,0 +1,24 @@
[Unit]
Description=Celery Service
After=network.target
Requires=redis.service
[Service]
Type=forking
User=celery
Group=celery
EnvironmentFile=/etc/default/celery
WorkingDirectory=/var/www/phzhik-poizonstore
ExecStart=/bin/sh -c '${CELERY_BIN} -A $CELERY_APP multi start $CELERYD_NODES \
--pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} \
--loglevel="${CELERYD_LOG_LEVEL}" $CELERYD_OPTS'
ExecStop=/bin/sh -c '${CELERY_BIN} multi stopwait $CELERYD_NODES \
--pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} \
--loglevel="${CELERYD_LOG_LEVEL}"'
ExecReload=/bin/sh -c '${CELERY_BIN} -A $CELERY_APP multi restart $CELERYD_NODES \
--pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} \
--loglevel="${CELERYD_LOG_LEVEL}" $CELERYD_OPTS'
Restart=always
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,17 @@
[Unit]
Description=Celery Beat Service
After=network.target
[Service]
Type=simple
User=celery
Group=celery
EnvironmentFile=/etc/default/celery
WorkingDirectory=/var/www/phzhik-poizonstore
ExecStart=/bin/sh -c '${CELERY_BIN} -A ${CELERY_APP} beat \
--pidfile=${CELERYBEAT_PID_FILE} \
--logfile=${CELERYBEAT_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL}'
Restart=always
[Install]
WantedBy=multi-user.target

View File

@ -40,4 +40,8 @@ server {
include /etc/nginx/uwsgi_params;
include /etc/nginx/proxy_params;
}
location /flower/ {
proxy_pass http://localhost:5555/flower/;
}
}

13
_deploy/run_celery_flower.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
WORK_DIR="/var/www/phzhik-poizonstore/env/bin"
PROJECT_NAME="poizonstore"
# Wait for worker to start
until timeout 10s $WORK_DIR/celery -A $PROJECT_NAME inspect ping; do
>&2 echo "Celery workers not available"
done
# Run flower for Celery management
echo 'Starting Celery flower'
$WORK_DIR/celery -A $PROJECT_NAME flower --port=5555 --url_prefix=/flower --basic-auth=admin:meowmeow

View File

@ -25,7 +25,5 @@ chmod-socket = 664
# clear environment on exit
vacuum = true
smart-attach-daemon = /tmp/celery-main.pid /var/www/phzhik-poizonstore/run_celery.sh
env = LANG=C.UTF-8
enable-threads = true

View File

View File

@ -1,21 +0,0 @@
#!/bin/sh
WORK_DIR="/var/www/phzhik-poizonstore/env/bin"
PROJECT_NAME="poizonstore"
# Run Celery worker
echo 'Starting Celery worker'
$WORK_DIR/celery -A $PROJECT_NAME worker -l INFO --pidfile=/tmp/celery.pid &
# Wait for worker to start
until timeout 10s $WORK_DIR/celery -A $PROJECT_NAME inspect ping; do
>&2 echo "Celery workers not available"
done
# Run flower for Celery management
echo 'Starting Celery flower'
$WORK_DIR/celery -A $PROJECT_NAME flower --pidfile=/tmp/celery-flower.pid &
# Run celery beat for periodic tasks
echo 'Starting Celery beat'
$WORK_DIR/celery -A $PROJECT_NAME beat -l INFO --pidfile=/tmp/celery-beat.pid &

View File

@ -1,3 +0,0 @@
#!/bin/sh
killall celery