Skip to content

Commit 7d9ee0e

Browse files
committed
Fix sandbox.
1 parent a8cc4b4 commit 7d9ee0e

File tree

11 files changed

+57
-30
lines changed

11 files changed

+57
-30
lines changed

Vagrantfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# vi: set ft=ruby :
33

44
Vagrant::Config.run do |config|
5-
config.vm.box = "ubuntu/trusty64"
5+
config.vm.box = "ubuntu/focal64"
66
config.vm.forward_port 8000, 8080
7-
config.vm.provision "shell", path: "sandbox/provision.sh"
7+
config.vm.provision "shell", path: "sandbox/provision.sh", privileged: false
88
end

docs/contributing.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,31 @@ Finally, you can also use tox to run tests against
3333
all supported Django and Python versions::
3434

3535
$ tox
36+
37+
38+
Sandbox VM
39+
==========
40+
41+
There is a ``VagrantFile`` for setting up a sandbox VM where you can play around
42+
with the functionality. Bring up the Vagrant box::
43+
44+
$ vagrant up
45+
46+
This may take a while but will set up a Ubuntu Precise64 VM with RabbitMQ
47+
installed. You can then SSH into the machine::
48+
49+
$ vagrant ssh
50+
$ cd /vagrant/sandbox
51+
52+
You can now decide to run the Celery implementation::
53+
54+
$ honcho -f Procfile.celery start
55+
56+
Or you can run the RQ implementation::
57+
58+
$ honcho -f Procfile.rq start
59+
60+
The above commands will start a Django runserver and the selected task worker.
61+
The dummy site will be available at ``http://localhost:8080`` on your host
62+
machine. There are some sample views in ``sandbox/dummyapp/views.py`` that
63+
exercise django-cacheback.

sandbox/Procfile.celery

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
web: env PYTHONUNBUFFERED=true python manage.py runserver 0.0.0.0:8000
2-
worker: env PYTHONUNBUFFERED=true celery -A sandbox worker --loglevel=INFO
1+
web: env QUEUE=celery poetry run python manage.py runserver 0.0.0.0:8000
2+
worker: env QUEUE=celery poetry run celery -A sandbox worker --loglevel=INFO

sandbox/Procfile.rq

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
web: env PYTHONUNBUFFERED=true QUEUE=rq python manage.py runserver 0.0.0.0:8000
2-
worker: env PYTHONUNBUFFERED=true QUEUE=rq python manage.py rqworker
1+
web: env QUEUE=rq poetry run python manage.py runserver 0.0.0.0:8000
2+
worker: env QUEUE=rq poetry run python manage.py rqworker

sandbox/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
from .celeryconfig import *
1+
from .celeryconfig import app as celery_app
2+
3+
__all__ = ('celery_app',)

sandbox/celeryconfig.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
from __future__ import absolute_import
21
import os
32

43
from celery import Celery
54

6-
# set the default Django settings module for the 'celery' program.
75
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
86

97
from django.conf import settings # noqa
108

119
app = Celery('sandbox')
1210

13-
# Using a string here means the worker will not have to
14-
# pickle the object when using Windows.
15-
app.config_from_object('django.conf:settings')
16-
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
11+
app.config_from_object('django.conf:settings', namespace='CELERY')
12+
app.autodiscover_tasks()

sandbox/dummyapp/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.shortcuts import render
22

3-
from cacheback.queryset import QuerySetFilterJob
4-
from cacheback.function import FunctionJob
3+
from cacheback.jobs import QuerySetFilterJob
4+
from cacheback.jobs import FunctionJob
55
from cacheback.decorators import cacheback
66

77
from dummyapp import jobs

sandbox/provision.sh

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#!/bin/bash
22

3-
apt-get update
4-
apt-get install -y rabbitmq-server redis-server memcached python-pip git
3+
sudo apt-get update
4+
sudo apt-get install -y redis-server memcached python3-pip git
5+
sudo pip3 install -U pip poetry honcho
56

6-
pip install -U pip honcho
77
cd /vagrant
8-
pip install -e .[celery]
9-
pip install -e .[rq]
10-
`which pip` install -r requirements.txt -r sandbox/requirements.txt
8+
poetry install
9+
poetry run pip install -r sandbox/requirements.txt
1110

12-
# Create database
11+
# Create and fill database
1312
cd /vagrant/sandbox
14-
./manage.py migrate
15-
./manage.py loaddata fixture.json
13+
poetry run python manage.py migrate
14+
poetry run python manage.py loaddata fixture.json

sandbox/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
python-memcached==1.53
1+
python-memcached>=1.59

sandbox/settings.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
},
9696
]
9797

98-
MIDDLEWARE_CLASSES = (
98+
MIDDLEWARE = (
9999
'django.middleware.common.CommonMiddleware',
100100
'django.contrib.sessions.middleware.SessionMiddleware',
101101
'django.middleware.csrf.CsrfViewMiddleware',
@@ -115,6 +115,7 @@
115115
'django.contrib.sites',
116116
'django.contrib.messages',
117117
'django.contrib.staticfiles',
118+
'sandbox',
118119
'dummyapp',
119120
'django_rq',
120121
'cacheback',
@@ -162,8 +163,8 @@
162163

163164
# CACHEBACK SETTINGS
164165

165-
BROKER_URL = 'amqp://guest:guest@localhost/'
166-
CELERY_RESULT_BACKEND = 'amqp://'
166+
CELERY_BROKER_URL = 'redis://localhost:6379/0'
167+
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
167168
CELERY_TASK_SERIALIZER = 'json'
168169

169170
RQ_QUEUES = {

0 commit comments

Comments
 (0)