Skip to content

Commit 798fc0f

Browse files
committed
Do not reset the build start time when running build env
We are creating one Setup Environment and another Build Environment. Once each of them is created they define the `start_time` which is UTC now. Then they use the `start_time` to calculate the `length` of the build each time the build object is updated via the API. Since the Build Environment calls again UTC now, we override the old `start_time` and we loose track of the timing for the Setup Environment (close repository, among others). This commit saves the original `start_time` and passes it to the Build Environment so it continues calculating the difference for the `length` considering the Setup Environment times as well.
1 parent 7b41b22 commit 798fc0f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

readthedocs/doc_builder/environments.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ def __init__(
548548
record=True,
549549
environment=None,
550550
update_on_success=True,
551+
start_time=None,
551552
):
552553
super().__init__(project, environment)
553554
self.version = version
@@ -557,7 +558,7 @@ def __init__(
557558
self.update_on_success = update_on_success
558559

559560
self.failure = None
560-
self.start_time = datetime.utcnow()
561+
self.start_time = start_time or datetime.utcnow()
561562

562563
def __enter__(self):
563564
return self

readthedocs/projects/tasks.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ def __init__(
473473
if config is not None:
474474
self.config = config
475475
self.task = task
476+
self.build_start_time = None
476477
# TODO: remove this
477478
self.setup_env = None
478479

@@ -577,6 +578,7 @@ def run_setup(self, record=True):
577578
update_on_success=False,
578579
environment=self.get_rtd_env_vars(),
579580
)
581+
self.build_start_time = environment.start_time
580582

581583
# TODO: Remove.
582584
# There is code that still depends of this attribute
@@ -667,6 +669,9 @@ def run_build(self, record):
667669
build=self.build,
668670
record=record,
669671
environment=env_vars,
672+
673+
# Pass ``start_time`` here to not reset the timer
674+
start_time=self.build_start_time,
670675
)
671676

672677
# Environment used for building code, usually with Docker

0 commit comments

Comments
 (0)