Skip to content

Instantly share code, notes, and snippets.

@shurane
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shurane/fd64c4cf31528e019723 to your computer and use it in GitHub Desktop.
Save shurane/fd64c4cf31528e019723 to your computer and use it in GitHub Desktop.

Celery doesn't always restart. Try to make a reproducible test case for celery related code.

Run:

vagrant up
ssh-copy-id vagrant@localhost -p 2222
ansible -m ping all
ansible-playbook setup.yml

after SSH-ing into the machine:

#shell 1
celery -A tasks worker --loglevel=info
#shell 2
ipython -i /vagrant/run.py
[defaults]
hostfile=hosts.ini
remote_user=vagrant
[machine]
localhost ansible_ssh_port=2222 ansible_ssh_user=vagrant
# http://celery.readthedocs.org/en/latest/getting-started/first-steps-with-celery.html#id12
import tasks
result = tasks.add.delay(4, 4)
print(result.ready())
print(result.get(timeout=1))
---
- hosts: machine
sudo: True
tasks:
- apt: name=supervisor
- apt: name=python-pip
- apt: name=rabbitmq-server
- pip: name=celery
- pip: name=ipython
from celery import Celery
app = Celery('tasks', broker='amqp://guest@localhost//', backend='amqp')
@app.task
def add(x, y):
return x + y
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "hashicorp/precise64"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "256"]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment