Skip to content

Commit da79a12

Browse files
committedJan 13, 2015
remove kombu
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
1 parent dd80f1d commit da79a12

File tree

5 files changed

+61
-45
lines changed

5 files changed

+61
-45
lines changed
 

‎comet/tasks.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
from redis import StrictRedis
3333

3434

35-
def build(dbdata, sitedir):
35+
def build(dburl, sitedir):
3636
"""Build a site."""
3737
oldcwd = os.getcwd()
3838
os.chdir(sitedir)
39-
db = StrictRedis(**dbdata)
39+
db = StrictRedis.from_url(dburl)
4040
job = get_current_job(db)
4141
job.meta.update({'out': '', 'milestone': 0, 'total': 1, 'return': None,
4242
'status': None})
@@ -76,11 +76,11 @@ def build(dbdata, sitedir):
7676
return p.returncode
7777

7878

79-
def orphans(dbdata, sitedir):
79+
def orphans(dburl, sitedir):
8080
"""Remove all orphans in the site."""
8181
oldcwd = os.getcwd()
8282
os.chdir(sitedir)
83-
db = StrictRedis(**dbdata)
83+
db = StrictRedis.from_url(dburl)
8484
job = get_current_job(db)
8585
job.meta.update({'out': '', 'return': None, 'status': None})
8686
job.save()

‎comet/utils.py

+2-25
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@
2727

2828
from __future__ import unicode_literals
2929
from nikola.post import Post
30-
import kombu
3130
import sys
3231
import json
3332
import time
3433

3534

36-
__all__ = ['PERMISSIONS', 'USER_FIELDS', 'USER_ALL', 'parse_redis', 'ask',
37-
'ask_yesno', 'SiteProxy']
35+
__all__ = ['PERMISSIONS', 'USER_FIELDS', 'USER_ALL', 'ask', 'ask_yesno',
36+
'SiteProxy']
3837

3938
USER_FIELDS = ['username', 'realname', 'password', 'email']
4039
PERMISSIONS = ['active', 'is_admin', 'can_edit_all_posts', 'wants_all_posts',
@@ -43,28 +42,6 @@
4342
USER_ALL = USER_FIELDS + PERMISSIONS
4443

4544

46-
def parse_redis(url):
47-
"""Parse Redis URL.
48-
49-
:param str url: Redis URL
50-
:return: data for connection
51-
:rtype: dict
52-
:raises ValueError: invalid URL
53-
"""
54-
55-
# TODO get rid of kombu and roll our own
56-
redis_raw = kombu.parse_url(url)
57-
if redis_raw['transport'] == 'redis':
58-
return {'host': redis_raw['hostname'] or 'localhost',
59-
'port': redis_raw['port'] or 6379,
60-
'db': int(redis_raw['virtual_host'] or 0),
61-
'password': redis_raw['password']}
62-
elif redis_raw['transport'] == 'redis+socket':
63-
return {'unix_socket_path`': redis_raw['virtual_host']}
64-
else:
65-
raise ValueError("invalid Redis URL")
66-
67-
6845
# The following two functions come from Nikola.
6946
def ask(query, default=None):
7047
"""Ask a question."""

‎comet/web.py

+18-14
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,14 @@
4242
from flask.ext.login import (LoginManager, login_required, login_user,
4343
logout_user, current_user, make_secure_token)
4444
from flask.ext.bcrypt import Bcrypt
45-
from comet.utils import USER_FIELDS, PERMISSIONS, parse_redis, SiteProxy
45+
from comet.utils import USER_FIELDS, PERMISSIONS, SiteProxy
4646

4747

4848
_site = None
4949
site = None
5050
app = None
5151
db = None
5252
q = None
53-
build_job = None
54-
orphans_job = None
5553

5654

5755
def scan_site():
@@ -117,10 +115,8 @@ def configure_site():
117115

118116
app.secret_key = _site.config.get('COMET_SECRET_KEY')
119117
app.config['COMET_URL'] = _site.config.get('COMET_URL')
120-
app.config['REDIS_URL'] = _site.config.get('COMET_REDIS_URL', 'redis://')
121-
# Redis configuration
122-
app.config['REDIS_CONN'] = parse_redis(app.config['REDIS_URL'])
123-
db = redis.StrictRedis(**app.config['REDIS_CONN'])
118+
app.config['REDIS_URL'] = _site.config.get('COMET_REDIS_URL', 'redis://localhost:6379/0')
119+
db = redis.StrictRedis.from_url(app.config['REDIS_URL'])
124120
q = rq.Queue(connection=db)
125121

126122
_site.template_hooks['menu_alt'].append(generate_menu_alt)
@@ -130,7 +126,7 @@ def configure_site():
130126
'en': (
131127
(app.config['NIKOLA_URL'],
132128
'<i class="fa fa-globe"></i> Back to website'),
133-
('/rebuild', '<i class="fa fa-cog rebuild"></i> Rebuild'),
129+
('/rebuild', '<i class="fa fa-cog rebuild build-status-icon"></i> Rebuild'),
134130
)
135131
}
136132
_site.GLOBAL_CONTEXT['navigation_links'] = _site.config['NAVIGATION_LINKS']
@@ -178,8 +174,6 @@ def configure_site():
178174
site = SiteProxy(db, _site, app.logger)
179175
configure_url(app.config['COMET_URL'])
180176

181-
scan_site()
182-
183177

184178
def password_hash(password):
185179
"""Hash the password, using bcrypt.
@@ -621,7 +615,17 @@ def api_rebuild():
621615
build_job = q.fetch_job('build')
622616
orphans_job = q.fetch_job('orphans')
623617

624-
o = json.dumps({'build': build_job.meta, 'orphans': orphans_job.meta})
618+
if not build_job and not orphans_job:
619+
build_job = q.enqueue_call(func=comet.tasks.build,
620+
args=(app.config['REDIS_URL'],
621+
app.config['NIKOLA_ROOT']),
622+
job_id='build')
623+
orphans_job = q.enqueue_call(func=comet.tasks.orphans,
624+
args=(app.config['REDIS_URL'],
625+
app.config['NIKOLA_ROOT']),
626+
job_id='orphans', depends_on=build_job)
627+
628+
d = json.dumps({'build': build_job.meta, 'orphans': orphans_job.meta})
625629

626630
if ('status' in build_job.meta and
627631
build_job.meta['status'] is not None
@@ -630,7 +634,7 @@ def api_rebuild():
630634
rq.cancel_job('build', db)
631635
rq.cancel_job('orphans', db)
632636

633-
return o
637+
return d
634638

635639

636640
@app.route('/rebuild')
@@ -640,10 +644,10 @@ def rebuild():
640644
scan_site() # for good measure
641645
if not q.fetch_job('build') and not q.fetch_job('orphans'):
642646
b = q.enqueue_call(func=comet.tasks.build,
643-
args=(app.config['REDIS_CONN'],
647+
args=(app.config['REDIS_URL'],
644648
app.config['NIKOLA_ROOT']), job_id='build')
645649
q.enqueue_call(func=comet.tasks.orphans,
646-
args=(app.config['REDIS_CONN'],
650+
args=(app.config['REDIS_URL'],
647651
app.config['NIKOLA_ROOT']), job_id='orphans',
648652
depends_on=b)
649653

‎docs/admin/setup.rst

+37-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,28 @@ Redis
3333
You need to set up a `Redis <http://redis.io/>`_ server. Make sure it starts
3434
at boot.
3535

36+
RQ
37+
==
38+
39+
You need to set up a `RQ <http://python-rq.org>`_ worker. Make sure it starts
40+
at boot, after Redis. Here is a sample ``.service`` file for systemd:
41+
42+
.. code-block:: ini
43+
44+
[Unit]
45+
Description=RQWorker Service
46+
After=redis.service
47+
48+
[Service]
49+
Type=simple
50+
ExecStart=/var/comet/bin/rqworker
51+
User=nobody
52+
Group=nobody
53+
54+
[Install]
55+
WantedBy=multi-user.target
56+
57+
3658
Nikola and ``conf.py``
3759
======================
3860

@@ -57,9 +79,21 @@ Then, you must make some changes to the config:
5779
**Store it in a safe place** — git is not one! You can use
5880
``os.urandom(24)`` to generate something good.
5981
* ``COMET_URL`` — the URL under which Comet can be accessed.
60-
* ``REDIS_URL`` — the URL of your Redis database. Syntax is `Celery’s <http://docs.celeryproject.org/en/latest/getting-started/brokers/redis.html#configuration>`_.
82+
* ``REDIS_URL`` — the URL of your Redis database.
6183
* Modify ``POSTS`` and ``PAGES``, replacing ``.txt`` by ``.html``.
6284

85+
Redis URL syntax
86+
----------------
87+
88+
* ``redis://[:password]@localhost:6379/0`` (TCP)
89+
* ``rediss://[:password]@localhost:6379/0`` (TCP over SSL)
90+
* ``unix://[:password]@/path/to/socket.sock?db=0`` (Unix socket)
91+
92+
The default URL is ``redis://localhost:6379/0``.
93+
94+
CSS for the site
95+
----------------
96+
6397
Finally, you must add `some CSS`__ for wysihtml5. The easiest way to do this
6498
is by downloading the raw ``.css`` file as ``files/assets/css/custom.css``.
6599

@@ -100,6 +134,8 @@ Permissions
100134
Chown ``my_comet_site`` *recursively* to ``nobody``, or whatever
101135
user Comet will run as. Comet must be able to write to this directory.
102136

137+
Make sure to fix permissions if you fool around the site directory!
138+
103139
Server
104140
======
105141

‎requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
git+https://github.com/getnikola/nikola#egg=Nikola
22
git+https://github.com/nvie/rq.git#egg=rq
3-
kombu==3.0.24
43
blinker==1.3
54
docopt==0.6.1
65
docutils==0.12

0 commit comments

Comments
 (0)
Please sign in to comment.