Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
be5a8fe
Update manifest.yml
zzpwelkin Dec 26, 2013
a07b99e
Update manifest.yml
zzpwelkin Dec 26, 2013
5146c04
Update manifest.yml
zzpwelkin Dec 26, 2013
ce63dc4
Update manifest.yml
zzpwelkin Dec 26, 2013
9b46c8f
Update setup
zzpwelkin Dec 26, 2013
125d9ae
Create scrapy.py
zzpwelkin Dec 26, 2013
9fc07f6
Update manifest.yml
zzpwelkin Dec 26, 2013
5582666
Update manifest.yml
zzpwelkin Dec 26, 2013
f08e9ef
PYTHONPATH fixed
zzpwelkin Dec 27, 2013
7acaaa7
Update setup
zzpwelkin Dec 27, 2013
e35e46c
Update setup
zzpwelkin Dec 27, 2013
f8966c1
add absolute path in control
zzpwelkin Dec 27, 2013
2794cb9
add template dir
zzpwelkin Dec 27, 2013
ac02592
set python env
zzpwelkin Dec 27, 2013
6fe90ba
refact and change the app name
zzpwelkin Dec 27, 2013
6ad9eeb
Update celeryconfig.py.erb
zzpwelkin Dec 27, 2013
2159132
Update setup
zzpwelkin Dec 27, 2013
9c65b51
Update celeryconfig.py.erb
zzpwelkin Dec 27, 2013
99ff34a
Update celeryconfig.py.erb
zzpwelkin Dec 27, 2013
516ac5c
Update celeryconfig.py.erb
zzpwelkin Dec 27, 2013
7b55b22
Update celeryconfig.py.erb
zzpwelkin Dec 27, 2013
9533d9a
Update celeryconfig.py.erb
zzpwelkin Dec 27, 2013
fc717dd
add env
zzpwelkin Dec 27, 2013
eae61b8
change erb file
zzpwelkin Dec 27, 2013
29a14b9
fix
zzpwelkin Dec 27, 2013
8b0ea90
fix
zzpwelkin Dec 27, 2013
a713eda
configure file
zzpwelkin Dec 27, 2013
381a916
clear
zzpwelkin Dec 27, 2013
e05c600
fix
zzpwelkin Dec 27, 2013
9415e8b
fix error
zzpwelkin Dec 27, 2013
f1b72f8
Update celeryconfig.py
zzpwelkin Dec 27, 2013
7e04c17
merge
zzpwelkin Dec 27, 2013
9b55ad1
fix stop error of this script
zzpwelkin Dec 27, 2013
44cd908
celery imports fixed
zzpwelkin Dec 27, 2013
0848e25
[FIX] reset env and start error
zzpwelkin Jan 1, 2014
a4cc138
[ref] reactor import modules
zzpwelkin Jan 1, 2014
e656718
[fix] fixed cmd with logfile tag
zzpwelkin Feb 10, 2014
5e1da22
customized some stuff - hopefully it works
cozezien May 23, 2014
c714989
modified manifest
cozezien May 23, 2014
3d5a5e0
changed the way that control started
cozezien May 23, 2014
d949978
removed celeryconfig since it just causes problems
cozezien May 23, 2014
80778ec
trying to get this working
cozezien May 23, 2014
84569dd
blarg
cozezien May 23, 2014
1c525bd
removed some stuff
cozezien May 23, 2014
d06afab
test
cozezien May 23, 2014
b0fd137
blarg
cozezien May 23, 2014
198f0e0
remove python 2.7 and see what happens
cozezien May 26, 2014
3d06ac8
saving the fact we don't need the setup and also requiring python 2.7
cozezien May 26, 2014
2b35e3a
Removed celery version numbers
edmcdonagh Dec 13, 2014
3bfcc6d
Removed celery version numbers
edmcdonagh Dec 13, 2014
2503877
Removed celery version numbers
edmcdonagh Dec 13, 2014
5a00c5c
Removed celery version numbers
edmcdonagh Dec 13, 2014
8953f4a
Removed celery version numbers
edmcdonagh Dec 13, 2014
0925b95
trying to get it working on updated openshift
wassname Apr 10, 2015
04c10f0
trying to get it working on updated openshift
wassname Apr 10, 2015
b8f920a
updated readme
wassname Apr 10, 2015
25c2722
Updating
wassname Apr 10, 2015
8606dce
Update
wassname Apr 10, 2015
e4f1b01
Update
wassname Apr 10, 2015
24125ee
Update
wassname Apr 10, 2015
9117984
Update
wassname Apr 10, 2015
0d25c4d
Update
wassname Apr 10, 2015
ca5624c
Update
wassname Apr 10, 2015
d914107
Update
wassname Apr 10, 2015
e6c9f78
Update
wassname Apr 10, 2015
5e96f86
Update
wassname Apr 10, 2015
5a7f692
Update
wassname Apr 10, 2015
ca09418
Update
wassname Apr 10, 2015
5952af3
Update
wassname Apr 10, 2015
c7320d0
Update
wassname Apr 10, 2015
ce587bf
Update
wassname Apr 10, 2015
09b2b59
Scaling
wassname Apr 11, 2015
0401248
Scaling
wassname Apr 11, 2015
879a45e
finishing
wassname Apr 11, 2015
2cd0c80
finishing
wassname Apr 11, 2015
8b408d4
1
wassname Apr 13, 2015
96278f9
1
wassname Apr 13, 2015
afe22e8
2
wassname Apr 13, 2015
d032b71
2
wassname Apr 13, 2015
3f27c8b
2
wassname Apr 13, 2015
d702eec
3
wassname Apr 13, 2015
f65a44c
3
wassname Apr 13, 2015
37b15a9
3
wassname Apr 13, 2015
e5dcb57
Bugfix
wassname Apr 20, 2015
5659011
Bugfixes
wassname Apr 20, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
env
logs
38 changes: 28 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
openshift-celery-cartridge
==========================

Cartridge to Expose Celery as a Daemon on OpenShift
Cartridge to Expose Celery as a Daemon on OpenShift.

Environment Variables
Status
---------------------
This work on unscaled applications but only as a plugin cartridge on scaled applications. This means that it's can't scale independently of your main gear. At this point having a celery cartridge is no better than just starting celery in your app.y or action hooks. Further development can combine this with a python cartridge so it can operate in it's own gears.

Instead of using this I recommend starting celery in your action hooks or as part of you app.py instead. This will give more flexibility, and example is here https://github.com/appsembler/appsembler-launch-openshift

Configuration
---------------------

* <code>OPENSHIFT_CELERY_CONFIG</code>
This is the name of your config file, which by default is `$OPENSHIFT_CELERY_DIR/conf.d/celeryconfig.py` but you can copy this to `$OPENSHIFT_DATA_DIR/config/celeryconfig.py` and edit your own copy.

To install
---------------------

rhc cartridge-add https://raw.github.com/wassname/openshift-celery-cartridge/master/metadata/manifest.yml -a "appname"

Any log output will be generated to `${OPENSHIFT_HOMEDIR}logs/celery_log.txt` and will be viewable with the rhc tail "appname" command

This was tested using:

celery==3.1.11
redis==2.10.3

To manage
---------------------

$ rhc cartridge-status celeryd -a "yourapp"

- OPENSHIFT_CELERY_BROKER_TRANS : Defines the broker type that celery will use. Current available options are:
-- mongodb : DEFAULT
-- amqp
-- redis
- OPENSHIFT_CELERY_BROKER_URL : The connection URL for the broker, omitting the transport. For example, an amqp value may look like: guest:guest@localhost:5672//
-
- OPENSHIFT_CELERY_IMPORTS : Defines the modules that celery should import. Currently only supports 1 module import path

Currently only supports MongoDB as backend for queues, but in progress to support more environment variables to allow vairous backends and configurations.
52 changes: 44 additions & 8 deletions bin/control
Original file line number Diff line number Diff line change
@@ -1,32 +1,68 @@
#!/bin/bash -e

PATH=/bin/:/usr/bin:$PATH

#source $OPENSHIFT_CARTRIDGE_SDK_BASH
source $OPENSHIFT_CARTRIDGE_SDK_BASH

function start {
export PYTHONPATH=$OPENSHIFT_REPO_DIR/.openshift:$OPENSHIFT_REPO_DIR/wsgi::$OPENSHIFT_CELERY_DIR/conf.d:$OPENSHIFT_REPO_DIR:$PYTHONPATH
usr/celeryd-multi start --cmd=celeryd --pidfile=etc/celeryd.pid --hostname=$OPENSHIFT_INTERNAL_IP --loglevel=DEBUG
LOGPIPE=${OPENSHIFT_HOMEDIR}/app-root/runtime/logshifter-python
rm -f $LOGPIPE && mkfifo $LOGPIPE
/usr/bin/logshifter -tag python < $LOGPIPE &

PYTHONPATH=$OPENSHIFT_DATA_DIR:$OPENSHIFT_DATA_DIR/config/:$OPENSHIFT_REPO_DIR/.openshift:$OPENSHIFT_REPO_DIR/config:$OPENSHIFT_REPO_DIR/EXT:$OPENSHIFT_REPO_DIR/wsgi::$OPENSHIFT_CELERY_DIR/conf.d:$OPENSHIFT_REPO_DIR:$PYTHONPATH

echo "Starting Celery"
#echo "nohup nice -n 10 ${OPENSHIFT_CELERY_DIR}usr/celery multi start worker --config=${OPENSHIFT_CELERY_CONFIG=celeryconfig} --loglevel=DEBUG --hostname=$OPENSHIFT_APP_DNS --pidfile=${OPENSHIFT_CELERY_DIR}etc/celeryd.pid --logfile=${OPENSHIFT_HOMEDIR}app-root/logs/celery_log.txt &> $LOGPIPE &" > ${OPENSHIFT_LOG_DIR}celery_log.txt
nohup nice -n 10 ${OPENSHIFT_CELERY_DIR}usr/celery multi start worker --config=${OPENSHIFT_CELERY_CONFIG=celeryconfig} --loglevel=DEBUG --hostname=$OPENSHIFT_APP_DNS --pidfile=${OPENSHIFT_CELERY_DIR}etc/celeryd.pid --logfile=${OPENSHIFT_LOG_DIR}celery_log.txt &> $LOGPIPE &
if ps -p `cat ${OPENSHIFT_CELERY_DIR}etc/celeryd.pid` > /dev/null;
then
echo "Starting celery worked"
else
echo "Starting celery failed"
fi
}

function stop {
if ps -p `cat etc/celeryd.pid` > /dev/null 2>$1
celery multi stop worker --pidfile=${OPENSHIFT_CELERY_DIR}etc/celeryd.pid
if ps -p `cat ${OPENSHIFT_CELERY_DIR}etc/celeryd.pid` > /dev/null;
then
kill -9 `cat etc/celeryd.pid`
kill -9 `cat ${OPENSHIFT_CELERY_DIR}etc/celeryd.pid`
rm -f ${OPENSHIFT_CELERY_DIR}etc/celeryd.pid
else
echo "nothing to kill"
fi
echo "stopped"
}

function restart {
echo "restarted"
celery multi restart worker --config=${OPENSHIFT_CELERY_CONFIG=celeryconfig} --loglevel=DEBUG --hostname=$OPENSHIFT_APP_DNS --pidfile=${OPENSHIFT_CELERY_DIR}etc/celeryd.pid --logfile=${OPENSHIFT_LOG_DIR}celery_log.txt
echo "Restarted celery"

}

function status() {
pid=`cat ${OPENSHIFT_CELERY_DIR}etc/celeryd.pid`
PROCESS_COUNT=$(ps -ef | grep "${PROCESS_NAME}" | grep -v "grep" | wc -l)
client_result $pwd
if [ -f $pid ] && ( kill -0 $(cat $pid) ); then
client_result "Celery is running at pid:${pid}, $PROCESS_COUNT instances of celery"
else
client_result "Celery is not running"
fi
}


function catchall {
echo "not yet implemented"
}

# Ensure arguments.
if ! [ $# -gt 0 ]; then
echo "Usage: $0 [start|restart|stop|status]"
exit 1
fi

# Source utility functions.
source $OPENSHIFT_CARTRIDGE_SDK_BASH

case "$1" in
start) start ;;
stop) stop ;;
Expand Down
14 changes: 0 additions & 14 deletions bin/mock_server.rb

This file was deleted.

8 changes: 8 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
#!/bin/bash -e

source $OPENSHIFT_CARTRIDGE_SDK_BASH

for dir in logs pid tmp env; do
mkdir -p $dir
done

mkdir -p $OPENSHIFT_DATA_DIR/.celery
20 changes: 20 additions & 0 deletions conf.d/celeryconfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Modify this file to configure celery.
# You can move it to your data directory and reference it in enviromental variable $OPENSHIFT_CELERY_CONFIG.
# You could also insert variables at build using an acton hook.
# config options here http://docs.celeryproject.org/en/2.5/configuration.html#worker-celeryd

import os
import sys

sys.path.append('.')

BROKER_HOST = "localhost"
BROKER_PORT = 5672
BROKER_USER = "celeryuser"
BROKER_PASSWORD = "celery"
BROKER_VHOST = "celeryvhost"
CELERYD_OPTS="--autoscale=3,1 --time-limit=300 --concurrency=2 "
CELERY_RESULT_BACKEND = "amqp"

# Here we check the env vars first, otherwise go with "tasks"
CELERY_IMPORTS = ( os.getenv("OPENSHIFT_CELERY_IMPORTS","tasks") ,)
66 changes: 0 additions & 66 deletions conf.d/celeryconfig.py.erb

This file was deleted.

5 changes: 5 additions & 0 deletions hooks/publish-celery-connection-info
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

echo "S_CELERY_MASTER=$CELERY_MASTER"
echo "S_CELERY_HOST=$OPENSHIFT_GEAR_DNS"
echo "S_CELERY_PORT=$OPENSHIFT_GEAR_PORT"
4 changes: 4 additions & 0 deletions hooks/publish-db-connection-info
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

echo "OPENSHIFT_CELERY_HOST=$OPENSHIFT_GEAR_DNS"
echo "OPENSHIFT_CELERY_PORT=$OPENSHIFT_GEAR_PORT"
87 changes: 87 additions & 0 deletions hooks/set-celery-connection-info
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/ruby

def gear_info(tokens, gear_id, &block)
gears = {}
if tokens.length == 1
gears[gear_id] = tokens.first
else
while not tokens.empty?
gear, delim, data = tokens.shift(3)
data = yield data if block_given?
raise "Invalid data" unless delim == '='
gears[gear] = data
tokens.shift if tokens.first == ' '
end
end
gears
end

def tokenize(s)
tokens = []
a = ""
state = :start
s.scan(/([ \t]+)|(\\')|(')|([^ \t']+)/) do |args|
space, escaped_delim, delim, text = args
case state
when :start
case
when space then " "
when escaped_delim then raise "Unexpected delimiter"
when delim then state = :within_delim
when text then tokens << text
else raise "error"
end
when :within_delim
case
when space then a << space
when escaped_delim then a << '"'
when delim then tokens << a; a = ""; state = :start
when text then a << text
end
end
end
tokens << a if a.length > 0
tokens
end

gear_id = ARGV.shift
domain = ARGV.shift
tokens = tokenize(ARGV.shift)

# better if this is in creation order (oldest first)
gears = gear_info(tokens, gear_id) do |d|
d.split(' ').map{ |s| s.scan(/\A(.+?)=(.*?);?\Z/).first }.inject({}){ |h, (k,v)| h[k] = v if v != ''; h }
end
gears.each_pair{ |k,v| puts "Found gear #{k}#{k == gear_id ? '* ' : ''} with data #{v.inspect}" }
gear_ids = gears.keys.sort.uniq

puts "-------"

was_master = ENV['CELERY_MASTER'] == '1'
masters = gears.map{ |k,v| v['S_CELERY_MASTER'] == '1' ? k : nil }.compact.uniq.sort

mode =
case ENV['CELERY_MODE']
when 'read_replica'
if masters.length > 1
masters = masters[0,1]
elsif masters.length == 0
masters = gears.keys.uniq.sort[0,1]
end
puts "Running in read replica mode with master #{masters}"
:read_replica
else
masters = gears.keys.uniq.sort
puts "Running sharded with masters #{masters.inspect}"
:sharded
end

# An array of all of the host:port pairs for the cluster
hosts = gears.map{ |k,v| "#{v['S_CELERY_HOST']}:#{v['S_CELERY_PORT']}" }.compact.uniq.sort
# A list of key value pairs in <gear id> => <host:port pair> for the cluster
members = gears.map{ |k,v| "#{k}=#{v['S_CELERY_HOST']}:#{v['S_CELERY_PORT']}" }.compact.uniq.sort

File.open('env/CELERY_CLUSTER_MEMBERS', 'w'){ |f| f.puts members.join("\n") }
File.open('env/CELERY_CLUSTER', 'w'){ |f| f.puts hosts.join(",") }
File.open('env/CELERY_CLUSTER_MASTERS', 'w'){ |f| f.puts masters.join(",") }
File.open('env/CELERY_MASTER', 'w'){ |f| f.puts masters.include?(gear_id) ? "1" : "0" }
2 changes: 0 additions & 2 deletions metadata/managed_files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ locked_files:
- env/
- env/*
- conf.d/*
processed_templates:
- '**/*.erb'
Loading