An API Example project with basic asynchronous workers. The basic scripts make use of Heroku's tool belt, but there's no reason that it can't be deployed differently.
You should make (and use) a virtualenv
. If you don't have
virtualenvwrapper
installed, I recommend doing that.
Once virtualenvwrapper
is installed, you can simply:
mkvirtualenv apex
You need 4 things to run locally:
- A working virtualenv
- The Heroku tool belt (this isn't strictly necessary, it's just convenient)
- A running Celery-compatible broker of some kind, with the URL exported to
CELERY_BROKER_URL
- A running Celery-compatible task backend, with the URL exported to
CELERY_RESULT_BACKEND
For example, the broker (RabbitMQ) & backend (Redis) could be spun up using docker:
docker run -P -d --name apex-rabbit rabbitmq
docker run -P -d --name apex-redis redis redis-server
Then you simply:
./scripts/run-local
To setup a Heroku deployment for experimental purposes, simply:
./scripts/initialize-heroku
This service has one endpoint at /sums
. You can post a list of numbers
there, and it will create a background job to add them. You can check on the
status of the job, and retrieve the result of the addition from the URL given
in the location header of the POST response.