Skip to content
Permalink
Browse files

remove kombu

Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jan 13, 2015
1 parent dd80f1d commit da79a12b163b38ad8eef076f8262e7a2bd1596ad
Showing with 61 additions and 45 deletions.
  1. +4 −4 comet/tasks.py
  2. +2 −25 comet/utils.py
  3. +18 −14 comet/web.py
  4. +37 −1 docs/admin/setup.rst
  5. +0 −1 requirements.txt
@@ -32,11 +32,11 @@
from redis import StrictRedis


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


def orphans(dbdata, sitedir):
def orphans(dburl, sitedir):
"""Remove all orphans in the site."""
oldcwd = os.getcwd()
os.chdir(sitedir)
db = StrictRedis(**dbdata)
db = StrictRedis.from_url(dburl)
job = get_current_job(db)
job.meta.update({'out': '', 'return': None, 'status': None})
job.save()
@@ -27,14 +27,13 @@

from __future__ import unicode_literals
from nikola.post import Post
import kombu
import sys
import json
import time


__all__ = ['PERMISSIONS', 'USER_FIELDS', 'USER_ALL', 'parse_redis', 'ask',
'ask_yesno', 'SiteProxy']
__all__ = ['PERMISSIONS', 'USER_FIELDS', 'USER_ALL', 'ask', 'ask_yesno',
'SiteProxy']

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


def parse_redis(url):
"""Parse Redis URL.
:param str url: Redis URL
:return: data for connection
:rtype: dict
:raises ValueError: invalid URL
"""

# TODO get rid of kombu and roll our own
redis_raw = kombu.parse_url(url)
if redis_raw['transport'] == 'redis':
return {'host': redis_raw['hostname'] or 'localhost',
'port': redis_raw['port'] or 6379,
'db': int(redis_raw['virtual_host'] or 0),
'password': redis_raw['password']}
elif redis_raw['transport'] == 'redis+socket':
return {'unix_socket_path`': redis_raw['virtual_host']}
else:
raise ValueError("invalid Redis URL")


# The following two functions come from Nikola.
def ask(query, default=None):
"""Ask a question."""
@@ -42,16 +42,14 @@
from flask.ext.login import (LoginManager, login_required, login_user,
logout_user, current_user, make_secure_token)
from flask.ext.bcrypt import Bcrypt
from comet.utils import USER_FIELDS, PERMISSIONS, parse_redis, SiteProxy
from comet.utils import USER_FIELDS, PERMISSIONS, SiteProxy


_site = None
site = None
app = None
db = None
q = None
build_job = None
orphans_job = None


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

app.secret_key = _site.config.get('COMET_SECRET_KEY')
app.config['COMET_URL'] = _site.config.get('COMET_URL')
app.config['REDIS_URL'] = _site.config.get('COMET_REDIS_URL', 'redis://')
# Redis configuration
app.config['REDIS_CONN'] = parse_redis(app.config['REDIS_URL'])
db = redis.StrictRedis(**app.config['REDIS_CONN'])
app.config['REDIS_URL'] = _site.config.get('COMET_REDIS_URL', 'redis://localhost:6379/0')
db = redis.StrictRedis.from_url(app.config['REDIS_URL'])
q = rq.Queue(connection=db)

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

scan_site()


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

o = json.dumps({'build': build_job.meta, 'orphans': orphans_job.meta})
if not build_job and not orphans_job:
build_job = q.enqueue_call(func=comet.tasks.build,
args=(app.config['REDIS_URL'],
app.config['NIKOLA_ROOT']),
job_id='build')
orphans_job = q.enqueue_call(func=comet.tasks.orphans,
args=(app.config['REDIS_URL'],
app.config['NIKOLA_ROOT']),
job_id='orphans', depends_on=build_job)

d = json.dumps({'build': build_job.meta, 'orphans': orphans_job.meta})

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

return o
return d


@app.route('/rebuild')
@@ -640,10 +644,10 @@ def rebuild():
scan_site() # for good measure
if not q.fetch_job('build') and not q.fetch_job('orphans'):
b = q.enqueue_call(func=comet.tasks.build,
args=(app.config['REDIS_CONN'],
args=(app.config['REDIS_URL'],
app.config['NIKOLA_ROOT']), job_id='build')
q.enqueue_call(func=comet.tasks.orphans,
args=(app.config['REDIS_CONN'],
args=(app.config['REDIS_URL'],
app.config['NIKOLA_ROOT']), job_id='orphans',
depends_on=b)

@@ -33,6 +33,28 @@ Redis
You need to set up a `Redis <http://redis.io/>`_ server. Make sure it starts
at boot.

RQ
==

You need to set up a `RQ <http://python-rq.org>`_ worker. Make sure it starts
at boot, after Redis. Here is a sample ``.service`` file for systemd:

.. code-block:: ini

[Unit]
Description=RQWorker Service
After=redis.service

[Service]
Type=simple
ExecStart=/var/comet/bin/rqworker
User=nobody
Group=nobody

[Install]
WantedBy=multi-user.target


Nikola and ``conf.py``
======================

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

Redis URL syntax
----------------

* ``redis://[:password]@localhost:6379/0`` (TCP)
* ``rediss://[:password]@localhost:6379/0`` (TCP over SSL)
* ``unix://[:password]@/path/to/socket.sock?db=0`` (Unix socket)

The default URL is ``redis://localhost:6379/0``.

CSS for the site
----------------

Finally, you must add `some CSS`__ for wysihtml5. The easiest way to do this
is by downloading the raw ``.css`` file as ``files/assets/css/custom.css``.

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

Make sure to fix permissions if you fool around the site directory!

Server
======

@@ -1,6 +1,5 @@
git+https://github.com/getnikola/nikola#egg=Nikola
git+https://github.com/nvie/rq.git#egg=rq
kombu==3.0.24
blinker==1.3
docopt==0.6.1
docutils==0.12

0 comments on commit da79a12

Please sign in to comment.
You can’t perform that action at this time.