Skip to content

Commit

Permalink
chore: add global timeout for builds
Browse files Browse the repository at this point in the history
  • Loading branch information
aixaCode committed Jan 31, 2025
1 parent 7e5df8a commit 7ff677f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build-unitycloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ jobs:
API_KEY: ${{ secrets.UNITY_CLOUD_API_KEY }}
ORG_ID: ${{ secrets.UNITY_CLOUD_ORG_ID }}
PROJECT_ID: ${{ secrets.UNITY_CLOUD_PROJECT_ID }}
POLL_TIME: 60 # In seconds (int)
POLL_TIME: 60 # Set the polling time in seconds
GLOBAL_TIMEOUT: 10800 # Set the global timeout in seconds (e.g., 3 hours)
TARGET: t_${{ matrix.target }}
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
COMMIT_SHA: ${{ needs.prebuild.outputs.commit_sha }}
Expand Down
11 changes: 9 additions & 2 deletions scripts/cloudbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def _extract_member(self, member, targetpath, pwd):
URL = utils.create_base_url(os.getenv('ORG_ID'), os.getenv('PROJECT_ID'))
HEADERS = utils.create_headers(os.getenv('API_KEY'))
POLL_TIME = int(os.getenv('POLL_TIME', '60')) # Seconds
GLOBAL_TIMEOUT = int(os.getenv('GLOBAL_TIMEOUT', '10800')) # Seconds

build_healthy = True

Expand Down Expand Up @@ -538,11 +539,17 @@ def get_clean_build_bool():
# Poll the build stats every {POLL_TIME}s
start_time = time.time()
while True:
elapsed_time = time.time() - start_time
if elapsed_time > GLOBAL_TIMEOUT:
print(f'Global timeout reached: {datetime.timedelta(seconds=elapsed_time)}. Cancelling build...')
cancel_build(id)
sys.exit(1)

if poll_build(id):
print(f'Runner elapsed time: {datetime.timedelta(seconds=(time.time() - start_time))} | Polling again in {POLL_TIME}s [...]')
print(f'Runner elapsed time: {datetime.timedelta(seconds=elapsed_time)} | Polling again in {POLL_TIME}s [...]')
time.sleep(POLL_TIME)
else:
print(f'Runner FINAL elapsed time: {datetime.timedelta(seconds=(time.time() - start_time))}')
print(f'Runner FINAL elapsed time: {datetime.timedelta(seconds=elapsed_time)}')
break

# Handle build artifact
Expand Down

0 comments on commit 7ff677f

Please sign in to comment.