|
46 | 46 | YAMLParseError,
|
47 | 47 | )
|
48 | 48 | from readthedocs.storage import build_media_storage
|
| 49 | +from readthedocs.telemetry.collectors import BuildDataCollector |
49 | 50 | from readthedocs.worker import app
|
50 | 51 |
|
51 | 52 | from ..exceptions import (
|
@@ -341,6 +342,8 @@ def before_start(self, task_id, args, kwargs):
|
341 | 342 | # Reset any previous build error reported to the user
|
342 | 343 | self.data.build['error'] = ''
|
343 | 344 |
|
| 345 | + self.data.build_data = None |
| 346 | + |
344 | 347 | # Also note there are builds that are triggered without a commit
|
345 | 348 | # because they just build the latest commit for that version
|
346 | 349 | self.data.build_commit = kwargs.get('build_commit')
|
@@ -535,6 +538,7 @@ def after_return(self, status, retval, task_id, args, kwargs, einfo):
|
535 | 538 | self.data.build['length'] = (timezone.now() - self.data.start_time).seconds
|
536 | 539 |
|
537 | 540 | self.update_build(BUILD_STATE_FINISHED)
|
| 541 | + self.upload_build_data() |
538 | 542 |
|
539 | 543 | build_complete.send(sender=Build, build=self.data.build)
|
540 | 544 |
|
@@ -590,13 +594,43 @@ def execute(self):
|
590 | 594 | # ``__exit__``
|
591 | 595 | self.data.build_director.create_build_environment()
|
592 | 596 | with self.data.build_director.build_environment:
|
593 |
| - # Installing |
594 |
| - self.update_build(state=BUILD_STATE_INSTALLING) |
595 |
| - self.data.build_director.setup_environment() |
| 597 | + try: |
| 598 | + # Installing |
| 599 | + self.update_build(state=BUILD_STATE_INSTALLING) |
| 600 | + self.data.build_director.setup_environment() |
| 601 | + |
| 602 | + # Building |
| 603 | + self.update_build(state=BUILD_STATE_BUILDING) |
| 604 | + self.data.build_director.build() |
| 605 | + finally: |
| 606 | + self.data.build_data = self.collect_build_data() |
| 607 | + |
| 608 | + def collect_build_data(self): |
| 609 | + """ |
| 610 | + Collect data from the current build. |
| 611 | +
|
| 612 | + The data is collected from inside the container, |
| 613 | + to this must be called before killing the container. |
| 614 | + """ |
| 615 | + try: |
| 616 | + return BuildDataCollector( |
| 617 | + self.data.build_director.build_environment |
| 618 | + ).collect() |
| 619 | + except Exception: |
| 620 | + log.exception("Error while collecting build data") |
| 621 | + |
| 622 | + def upload_build_data(self): |
| 623 | + """ |
| 624 | + Upload data collected from the build after the build has ended. |
596 | 625 |
|
597 |
| - # Building |
598 |
| - self.update_build(state=BUILD_STATE_BUILDING) |
599 |
| - self.data.build_director.build() |
| 626 | + This must be called after the build has finished updating its state, |
| 627 | + otherwise some attributes like ``length`` won't be available. |
| 628 | + """ |
| 629 | + try: |
| 630 | + if self.data.build_data: |
| 631 | + api_v2.build(self.data.build_pk).telemetry.post(self.data.build_data) |
| 632 | + except Exception: |
| 633 | + log.exception("Error while uploading build data") |
600 | 634 |
|
601 | 635 | @staticmethod
|
602 | 636 | def get_project(project_pk):
|
|
0 commit comments