29
29
from .exceptions import ProjectImportError
30
30
from .models import ImportedFile , Project , Domain
31
31
from .signals import before_vcs , after_vcs , before_build , after_build
32
- from readthedocs .api .client import api as api_v1
33
32
from readthedocs .builds .constants import (LATEST ,
34
33
BUILD_STATE_CLONING ,
35
34
BUILD_STATE_INSTALLING ,
@@ -224,6 +223,8 @@ def run_build(self, docker=False, record=True):
224
223
pdf = bool (outcomes ['pdf' ]),
225
224
epub = bool (outcomes ['epub' ]),
226
225
)
226
+ else :
227
+ log .warning ('No build ID, not syncing files' )
227
228
228
229
if self .build_env .failed :
229
230
self .send_notifications ()
@@ -280,11 +281,10 @@ def setup_vcs(self):
280
281
if commit :
281
282
self .build ['commit' ] = commit
282
283
except ProjectImportError as e :
283
- log .error (
284
+ log .exception (
284
285
LOG_TEMPLATE .format (project = self .project .slug ,
285
286
version = self .version .slug ,
286
- msg = str (e )),
287
- exc_info = True ,
287
+ msg = 'Failed to import Project: ' ),
288
288
)
289
289
raise BuildEnvironmentError ('Failed to import project: %s' % e ,
290
290
status_code = 404 )
@@ -346,35 +346,27 @@ def update_app_instances(self, html=False, localmedia=False, search=False,
346
346
'active' : True ,
347
347
'built' : True ,
348
348
})
349
- except HttpClientError as e :
350
- log .error ('Updating version failed, skipping file sync: version=%s' ,
351
- self .version .pk , exc_info = True )
352
- else :
353
- # Broadcast finalization steps to web application instances
354
- broadcast (
355
- type = 'app' ,
356
- task = sync_files ,
357
- args = [
358
- self .project .pk ,
359
- self .version .pk ,
360
- ],
361
- kwargs = dict (
362
- hostname = socket .gethostname (),
363
- html = html ,
364
- localmedia = localmedia ,
365
- search = search ,
366
- pdf = pdf ,
367
- epub = epub ,
368
- )
369
- )
370
-
371
- # Delayed tasks
372
- # TODO these should be chained on to the broadcast calls. The
373
- # broadcast calls could be lumped together into a promise, and on
374
- # task result, these next few tasks can be updated, also in a
375
- # chained fashion
376
- fileify .delay (self .version .pk , commit = self .build .get ('commit' ))
377
- update_search .delay (self .version .pk , commit = self .build .get ('commit' ))
349
+ except HttpClientError :
350
+ log .exception ('Updating version failed, skipping file sync: version=%s' % self .version )
351
+
352
+ # Broadcast finalization steps to web application instances
353
+ broadcast (
354
+ type = 'app' ,
355
+ task = sync_files ,
356
+ args = [
357
+ self .project .pk ,
358
+ self .version .pk ,
359
+ ],
360
+ kwargs = dict (
361
+ hostname = socket .gethostname (),
362
+ html = html ,
363
+ localmedia = localmedia ,
364
+ search = search ,
365
+ pdf = pdf ,
366
+ epub = epub ,
367
+ ),
368
+ callback = sync_callback .s (version_pk = self .version .pk , commit = self .build ['commit' ]),
369
+ )
378
370
379
371
def setup_environment (self ):
380
372
"""
@@ -442,8 +434,7 @@ def build_docs_html(self):
442
434
kwargs = dict (html = True )
443
435
)
444
436
except socket .error :
445
- # TODO do something here
446
- pass
437
+ log .exception ('move_files task has failed on socket error.' )
447
438
448
439
return success
449
440
@@ -550,8 +541,6 @@ def update_imported_docs(version_pk):
550
541
version_slug = LATEST
551
542
version_repo = project .vcs_repo (version_slug )
552
543
ret_dict ['checkout' ] = version_repo .update ()
553
- except Exception :
554
- raise
555
544
finally :
556
545
after_vcs .send (sender = version )
557
546
@@ -575,10 +564,10 @@ def update_imported_docs(version_pk):
575
564
576
565
try :
577
566
api_v2 .project (project .pk ).sync_versions .post (version_post_data )
578
- except HttpClientError as e :
579
- log .error ("Sync Versions Exception: %s" , e . content )
580
- except Exception as e :
581
- log .error ("Unknown Sync Versions Exception" , exc_info = True )
567
+ except HttpClientError :
568
+ log .exception ("Sync Versions Exception" )
569
+ except Exception :
570
+ log .exception ("Unknown Sync Versions Exception" )
582
571
return ret_dict
583
572
584
573
@@ -634,6 +623,8 @@ def move_files(version_pk, hostname, html=False, localmedia=False, search=False,
634
623
:type epub: bool
635
624
"""
636
625
version = Version .objects .get (pk = version_pk )
626
+ log .debug (LOG_TEMPLATE .format (project = version .project .slug , version = version .slug ,
627
+ msg = 'Moving files: {}' .format (locals ())))
637
628
638
629
if html :
639
630
from_path = version .project .artifact_path (
@@ -642,18 +633,18 @@ def move_files(version_pk, hostname, html=False, localmedia=False, search=False,
642
633
Syncer .copy (from_path , target , host = hostname )
643
634
644
635
if 'sphinx' in version .project .documentation_type :
645
- if localmedia :
636
+ if search :
646
637
from_path = version .project .artifact_path (
647
- version = version .slug , type_ = 'sphinx_localmedia ' )
638
+ version = version .slug , type_ = 'sphinx_search ' )
648
639
to_path = version .project .get_production_media_path (
649
- type_ = 'htmlzip ' , version_slug = version .slug , include_file = False )
640
+ type_ = 'json ' , version_slug = version .slug , include_file = False )
650
641
Syncer .copy (from_path , to_path , host = hostname )
651
642
652
- if search :
643
+ if localmedia :
653
644
from_path = version .project .artifact_path (
654
- version = version .slug , type_ = 'sphinx_search ' )
645
+ version = version .slug , type_ = 'sphinx_localmedia ' )
655
646
to_path = version .project .get_production_media_path (
656
- type_ = 'json ' , version_slug = version .slug , include_file = False )
647
+ type_ = 'htmlzip ' , version_slug = version .slug , include_file = False )
657
648
Syncer .copy (from_path , to_path , host = hostname )
658
649
659
650
# Always move PDF's because the return code lies.
@@ -984,3 +975,14 @@ def clear_html_artifacts(version):
984
975
if isinstance (version , int ):
985
976
version = Version .objects .get (pk = version )
986
977
remove_dir (version .project .rtd_build_path (version = version .slug ))
978
+
979
+
980
+ @task (queue = 'web' )
981
+ def sync_callback (_ , version_pk , commit , * args , ** kwargs ):
982
+ """
983
+ This will be called once the sync_files tasks are done.
984
+
985
+ The first argument is the result from previous tasks, which we discard.
986
+ """
987
+ fileify (version_pk , commit = commit )
988
+ update_search (version_pk , commit = commit )
0 commit comments