| Total Complexity | 4 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| 1 | import httplib |
||
| 7 | class WaitUntilBuildFinishes(CircleCI): |
||
| 8 | |||
| 9 | def run(self, build_number, project, wait_timeout=600): |
||
| 10 | """ |
||
| 11 | Get build number for a SHA in project. |
||
| 12 | """ |
||
| 13 | path = 'project/%s/%s' % (project, build_number) |
||
| 14 | |||
| 15 | start_time = time.time() |
||
| 16 | done = False |
||
| 17 | while not done: |
||
| 18 | response = self._perform_request( |
||
| 19 | path, method='GET', |
||
| 20 | ) |
||
| 21 | |||
| 22 | if response.status_code != httplib.OK: |
||
| 23 | msg = ('Build number %s for project ' + |
||
| 24 | '%s not found.' % (project, build_number)) |
||
| 25 | raise Exception(msg) |
||
| 26 | |||
| 27 | response = response.json |
||
| 28 | |||
| 29 | if response['lifecycle'] == 'finished': |
||
| 30 | return True |
||
| 31 | |||
| 32 | time.sleep(10) |
||
| 33 | done = (time.time() - start_time) > wait_timeout |
||
| 34 | |||
| 35 | return False |
||
| 36 |