28
28
from __future__ import print_function , unicode_literals
29
29
import json
30
30
import os
31
+ import sys
31
32
import io
32
33
import pkg_resources
33
34
import nikola .__main__
34
35
import logbook
35
36
import redis
37
+ import rq
38
+ import comet .tasks
36
39
from nikola .utils import (unicode_str , get_logger , ColorfulStderrHandler ,
37
40
write_metadata , TranslatableSetting )
38
41
import nikola .plugins .command .new_post
42
45
from flask .ext .bcrypt import Bcrypt
43
46
from comet .utils import USER_FIELDS , PERMISSIONS , parse_redis , SiteProxy
44
47
48
+
45
49
_site = None
46
50
site = None
47
51
app = None
48
52
db = None
49
-
53
+ q = None
54
+ build_job = None
55
+ orphans_job = None
50
56
51
57
def scan_site ():
52
58
"""Rescan the site."""
@@ -64,7 +70,7 @@ def configure_url(url):
64
70
65
71
def configure_site ():
66
72
"""Configure the site for Comet."""
67
- global _site , site , db
73
+ global _site , site , db , q
68
74
69
75
nikola .__main__ ._RETURN_DOITNIKOLA = True
70
76
_dn = nikola .__main__ .main ([])
@@ -115,6 +121,7 @@ def configure_site():
115
121
# Redis configuration
116
122
redis_conn = parse_redis (app .config ['REDIS_URL' ])
117
123
db = redis .StrictRedis (** redis_conn )
124
+ q = rq .Queue (connection = db )
118
125
119
126
_site .template_hooks ['menu_alt' ].append (generate_menu_alt )
120
127
@@ -606,12 +613,41 @@ def delete():
606
613
return redirect ('/' )
607
614
608
615
616
+ @app .route ('/api/rebuild' )
617
+ @login_required
618
+ def api_rebuild ():
619
+ """Rebuild the site (internally)."""
620
+
621
+ #e = {'out': '', 'milestone': 0, 'total': 1, 'return': None , 'status': None}
622
+
623
+ build_job = q .fetch_job ('build' )
624
+ orphans_job = q .fetch_job ('orphans' )
625
+
626
+ o = json .dumps ({'build' : build_job .meta , 'orphans' : orphans_job .meta })
627
+
628
+ 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 :
629
+ build_job = None
630
+ orphans_job = None
631
+
632
+ return o
633
+
634
+
609
635
@app .route ('/rebuild' )
610
636
@login_required
611
637
def rebuild ():
612
- """Rebuild the site."""
613
- return "<h1>Not implemented.</h1>" , 500
638
+ """Rebuild the site with a nice UI."""
639
+
640
+ executable = sys .executable
641
+ if executable .endswith ('uwsgi' ):
642
+ import uwsgi
643
+ executable = os .path .join (uwsgi .opt ['virtualenv' ], 'bin' , 'python' )
644
+
645
+ if not q .fetch_job ('build' ) and not q .fetch_job ('orphans' ):
646
+ b = q .enqueue (comet .tasks .build , executable , job_id = 'build' )
647
+ o = q .enqueue (comet .tasks .orphans , executable , job_id = 'orphans' , depends_on = b )
614
648
649
+ return render ('comet_rebuild.tmpl' ,
650
+ {'title' : 'Rebuild' , 'permalink' : '/rebuild' })
615
651
616
652
@app .route ('/bower_components/<path:path>' )
617
653
def serve_bower_components (path ):
0 commit comments