Skip to content

Instantly share code, notes, and snippets.

; ==================================
; celery worker supervisor
; ==================================
[program:celery]
command=/path/to/home/.virtualenvs/celery_env/bin/celery worker -A app.celery --loglevel=INFO
directory=/path/to/home/celery-scheduler
user=root
numprocs=1
; ================================
; celery beat supervisor
; ================================
[program:celerybeat]
command=/path/to/home/.virtualenvs/celery_env/bin/celery beat -A app.celery --schedule=/tmp/celerybeat-schedule --loglevel=INFO --pidfile=/tmp/celerybeat.pid
directory=/path/to/home/celery-scheduler
user=root
numprocs=1
; ================================
; redis supervisor
; ================================
[program:redis]
command=/path/to/celery-scheduler/redis-3.2.1/src/redis-server
directory=/path/to/celery-scheduler/redis-3.2.1
user=root
numprocs=1
; ==================================
; supervisor config file
; ==================================
[unix_http_server]
file=/var/run/supervisor.sock ; (the path to the socket file)
[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
@channeng
channeng / install_redis.sh
Created October 22, 2017 16:28
Script to build redis-server
#!/bin/bash
# This script downloads redis-server
# if redis has not already been downloaded
if [ ! -d redis-3.2.1/src ]; then
wget http://download.redis.io/releases/redis-3.2.1.tar.gz
tar xzf redis-3.2.1.tar.gz
rm redis-3.2.1.tar.gz
cd redis-3.2.1
make
else
@channeng
channeng / __init__.py
Created October 22, 2017 16:24
Celery Flask setup -- final app.py
from flask import Flask
from celery import Celery
import celeryconfig
app = Flask(__name__)
app.config.from_object('config')
def make_celery(app):
@channeng
channeng / celeryconfig.py
Created October 22, 2017 16:21
Celery Flask setup - celeryconfig and celerybeat schedule
from celery.schedules import crontab
CELERY_IMPORTS = ('app.tasks.test')
CELERY_TASK_RESULT_EXPIRES = 30
CELERY_TIMEZONE = 'UTC'
CELERY_ACCEPT_CONTENT = ['json', 'msgpack', 'yaml']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
@channeng
channeng / task.py
Created October 22, 2017 16:18
Celery Flask setup -- example task
import celery
@celery.task()
def print_hello():
logger = print_hello.get_logger()
logger.info("Hello")
@channeng
channeng / config.py
Created October 22, 2017 16:10
Celery Flask setup -- config
from os import environ
REDIS_HOST = "0.0.0.0"
REDIS_PORT = 6379
BROKER_URL = environ.get('REDIS_URL', "redis://{host}:{port}/0".format(
host=REDIS_HOST, port=str(REDIS_PORT)))
CELERY_RESULT_BACKEND = BROKER_URL
@channeng
channeng / app.py
Created October 22, 2017 16:07
Celery Flask setup - second step
from flask import Flask
from celery import Celery
app = Flask(__name__)
app.config.from_object('config')
def make_celery(app):
# create context tasks in celery