Skip to content

Commit

Permalink
Broken implementation of rebuilds
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jan 12, 2015
1 parent 03b0fe7 commit dff1f99
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
14 changes: 8 additions & 6 deletions comet/utils.py
Expand Up @@ -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',
Expand Down Expand Up @@ -140,7 +142,7 @@ def reload_site(self):
self._read_indexlist('pages')

self.revision = rev
self.logger.error("Site updated to revision {0}.".format(rev))
self.logger.info("Site updated to revision {0}.".format(rev))
elif rev == self.revision and self.db.exists('site:rev'):
pass
else:
Expand All @@ -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...")
self.logger.info("Waiting for DB lock...")
time.sleep(0.5)
self.db.incr('site:lock')
self.logger.error("Lock acquired.")
self.logger.error("Scanning site...")
self.logger.info("Lock acquired.")
self.logger.info("Scanning site...")

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

Expand All @@ -181,8 +183,8 @@ def scan_posts(self, really=True, ignore_quit=False, quiet=True):
self.db.incr('site:rev')

self.db.decr('site:lock')
self.logger.error("Lock released.")
self.logger.error("Site scanned.")
self.logger.info("Lock released.")
self.logger.info("Site scanned.")
self.reload_site()

@property
Expand Down
44 changes: 40 additions & 4 deletions comet/web.py
Expand Up @@ -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
Expand All @@ -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."""
Expand All @@ -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([])
Expand Down Expand Up @@ -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)

_site.template_hooks['menu_alt'].append(generate_menu_alt)

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


@app.route('/api/rebuild')
@login_required
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


@app.route('/rebuild')
@login_required
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(comet.tasks.build, 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'})

@app.route('/bower_components/<path:path>')
def serve_bower_components(path):
Expand Down

0 comments on commit dff1f99

Please sign in to comment.