Skip to content

Commit

Permalink
Configure Celery to run with Vagrant
Browse files Browse the repository at this point in the history
Also, fix failure to start
  • Loading branch information
cnorthwood committed Dec 29, 2012
1 parent a0b90b3 commit 89a4b07
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
11 changes: 11 additions & 0 deletions cookbooks/molly/recipes/develop.rb
Expand Up @@ -16,6 +16,12 @@
action :create
end

%w(protobuf-compiler rabbitmq-server).each do | pkg |
package pkg do
action :install
end
end

bash "Setup Molly" do
cwd '/tmp'
user molly_user
Expand All @@ -26,6 +32,11 @@
EOH
end

service "rabbitmq" do
service_name "rabbitmq-server"
action :start
end

bash "Run Molly" do
cwd '/vagrant'
user 'root'
Expand Down
10 changes: 5 additions & 5 deletions molly/command.py
Expand Up @@ -39,15 +39,15 @@ def ui_main():
def run_supervisord(config):
from supervisor.supervisord import main
main([
'-c', os.path.abspath(os.path.join(os.path.dirname(__file__), config)),
'-i', 'mollyd'
] + argv[1:])
'-c', os.path.abspath(os.path.join(os.path.dirname(__file__), config)),
'-i', 'mollyd'
] + argv[1:])

def run_supervisorctl(config):
from supervisor.supervisorctl import main
main([
'-c', os.path.abspath(os.path.join(os.path.dirname(__file__), config)),
] + argv[1:])
'-c', os.path.abspath(os.path.join(os.path.dirname(__file__), config)),
] + argv[1:])

def mollyd():
run_supervisord('supervisor.cfg')
Expand Down
8 changes: 3 additions & 5 deletions molly/services/tasks.py
@@ -1,24 +1,23 @@
import celery
import celery.apps.beat
import celery.beat

class Service(celery.Celery):

def __init__(self):
super(Service, self).__init__()
super(Service, self).__init__(__package__, loader='default')
self.periodic_tasks = []

def init_cli_commands(self, manager):

@manager.command
def taskbeat():
beat = celery.apps.beat.Beat(app=self)
beat = self.Beat()
beat.scheduler_cls=Scheduler
beat.run()

@manager.command
def taskworker():
self.Worker().run_worker()
self.Worker().run()

def periodic_task(self, *args, **kwargs):
crontab = kwargs.pop('crontab')
Expand All @@ -31,5 +30,4 @@ class Scheduler(celery.beat.PersistentScheduler):

def setup_schedule(self):
super(Scheduler, self).setup_schedule()
print self._store
self.merge_inplace(self.app.periodic_tasks)
18 changes: 17 additions & 1 deletion molly/supervisor-debug.cfg
Expand Up @@ -11,7 +11,7 @@ user=molly
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/lib/molly/supervisor.sock
serverurl=unix:///var/lib/molly/supervisord.sock

[program:mollyrest]
directory=/opt/molly/
Expand All @@ -27,4 +27,20 @@ command=/opt/molly/bin/mollyui start_debug -a 0.0.0.0
autostart=true
autorestart=true
redirect_stderr=true
user=molly

[program:mollytaskbeat]
directory=/opt/molly/
command=/opt/molly/bin/mollyrest taskbeat
autostart=true
autorestart=true
redirect_stderr=true
user=molly

[program:mollytaskworker]
directory=/opt/molly/
command=/opt/molly/bin/mollyrest taskworker
autostart=true
autorestart=true
redirect_stderr=true
user=molly
2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -8,4 +8,4 @@ Flask-Script
supervisor
imposm.parser
Shapely
celery
celery

0 comments on commit 89a4b07

Please sign in to comment.