@@ -610,6 +610,7 @@ def full_build(self):
610
610
def run (self , http : urllib3 .PoolManager ) -> bool :
611
611
"""Build and publish a Python doc, for a language, and a version."""
612
612
start_time = perf_counter ()
613
+ start_timestamp = dt .now (tz = timezone .utc ).replace (microsecond = 0 )
613
614
logging .info ("Running." )
614
615
try :
615
616
self .cpython_repo .switch (self .version .branch_or_tag )
@@ -619,7 +620,10 @@ def run(self, http: urllib3.PoolManager) -> bool:
619
620
self .build_venv ()
620
621
self .build ()
621
622
self .copy_build_to_webroot (http )
622
- self .save_state (build_duration = perf_counter () - start_time )
623
+ self .save_state (
624
+ build_start = start_timestamp ,
625
+ build_duration = perf_counter () - start_time ,
626
+ )
623
627
except Exception as err :
624
628
logging .exception ("Badly handled exception, human, please help." )
625
629
if sentry_sdk :
@@ -921,7 +925,7 @@ def load_state(self) -> dict:
921
925
except (KeyError , FileNotFoundError ):
922
926
return {}
923
927
924
- def save_state (self , build_duration : float ):
928
+ def save_state (self , build_start : dt , build_duration : float ):
925
929
"""Save current CPython sha1 and current translation sha1.
926
930
927
931
Using this we can deduce if a rebuild is needed or not.
@@ -932,17 +936,23 @@ def save_state(self, build_duration: float):
932
936
except FileNotFoundError :
933
937
states = tomlkit .document ()
934
938
935
- state = {}
936
- state ["cpython_sha" ] = self .cpython_repo .run ("rev-parse" , "HEAD" ).stdout .strip ()
939
+ key = f"/{ self .language .tag } /{ self .version .name } /"
940
+ state = {
941
+ "last_build_start" : build_start ,
942
+ "last_build_duration" : round (build_duration , 0 ),
943
+ "cpython_sha" : self .cpython_repo .run ("rev-parse" , "HEAD" ).stdout .strip (),
944
+ }
937
945
if self .language .tag != "en" :
938
946
state ["translation_sha" ] = self .translation_repo .run (
939
947
"rev-parse" , "HEAD"
940
948
).stdout .strip ()
941
- state ["last_build" ] = dt .now (timezone .utc )
942
- state ["last_build_duration" ] = build_duration
943
- states [f"/{ self .language .tag } /{ self .version .name } /" ] = state
949
+ states [key ] = state
944
950
state_file .write_text (tomlkit .dumps (states ), encoding = "UTF-8" )
945
951
952
+ tbl = tomlkit .inline_table ()
953
+ tbl |= state
954
+ logging .info ("Saved new rebuild state for %s: %s" , key , tbl .as_string ())
955
+
946
956
947
957
def symlink (
948
958
www_root : Path ,
0 commit comments