Skip to content
Browse files
Broken implementation of rebuilds
Signed-off-by: Chris Warrick <>
  • Loading branch information
Kwpolska committed Jan 12, 2015
1 parent 03b0fe7 commit dff1f997156fd41e296312b0e4d0e7bce91b36ce
Showing 2 changed files with 48 additions and 10 deletions.
@@ -51,6 +51,8 @@ def parse_redis(url):
: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',
@@ -140,7 +142,7 @@ def reload_site(self):

self.revision = rev
self.logger.error("Site updated to revision {0}.".format(rev))"Site updated to revision {0}.".format(rev))
elif rev == self.revision and self.db.exists('site:rev'):
@@ -159,11 +161,11 @@ def _write_indexlist(self, name):
def scan_posts(self, really=True, ignore_quit=False, quiet=True):
"""Rescan the site."""
while self.db.exists('site:lock') and int(self.db.get('site:lock')) != 0:
self.logger.error("Waiting for DB lock...")"Waiting for DB lock...")
self.logger.error("Lock acquired.")
self.logger.error("Scanning site...")"Lock acquired.")"Scanning site...")

self._site.scan_posts(really, ignore_quit, quiet)

@@ -181,8 +183,8 @@ def scan_posts(self, really=True, ignore_quit=False, quiet=True):

self.logger.error("Lock released.")
self.logger.error("Site scanned.")"Lock released.")"Site scanned.")

@@ -28,11 +28,14 @@
from __future__ import print_function, unicode_literals
import json
import os
import sys
import io
import pkg_resources
import nikola.__main__
import logbook
import redis
import rq
import comet.tasks
from nikola.utils import (unicode_str, get_logger, ColorfulStderrHandler,
write_metadata, TranslatableSetting)
import nikola.plugins.command.new_post
@@ -42,11 +45,14 @@
from flask.ext.bcrypt import Bcrypt
from comet.utils import USER_FIELDS, PERMISSIONS, parse_redis, SiteProxy

_site = None
site = None
app = None
db = None

q = None
build_job = None
orphans_job = None

def scan_site():
"""Rescan the site."""
@@ -64,7 +70,7 @@ def configure_url(url):

def configure_site():
"""Configure the site for Comet."""
global _site, site, db
global _site, site, db, q

nikola.__main__._RETURN_DOITNIKOLA = True
_dn = nikola.__main__.main([])
@@ -115,6 +121,7 @@ def configure_site():
# Redis configuration
redis_conn = parse_redis(app.config['REDIS_URL'])
db = redis.StrictRedis(**redis_conn)
q = rq.Queue(connection=db)


@@ -606,12 +613,41 @@ def delete():
return redirect('/')

def api_rebuild():
"""Rebuild the site (internally)."""

#e = {'out': '', 'milestone': 0, 'total': 1, 'return': None , 'status': None}

build_job = q.fetch_job('build')
orphans_job = q.fetch_job('orphans')

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

if 'status' in build_job.meta and build_job.meta['status'] is True and 'status' in orphans_job.meta and orphans_job.meta['status'] is True:
build_job = None
orphans_job = None

return o

def rebuild():
"""Rebuild the site."""
return "<h1>Not implemented.</h1>", 500
"""Rebuild the site with a nice UI."""

executable = sys.executable
if executable.endswith('uwsgi'):
import uwsgi
executable = os.path.join(uwsgi.opt['virtualenv'], 'bin', 'python')

if not q.fetch_job('build') and not q.fetch_job('orphans'):
b = q.enqueue(, executable, job_id='build')
o = q.enqueue(comet.tasks.orphans, executable, job_id='orphans', depends_on=b)

return render('comet_rebuild.tmpl',
{'title': 'Rebuild', 'permalink': '/rebuild'})

def serve_bower_components(path):

0 comments on commit dff1f99

Please sign in to comment.