From d7ca50dd8309e4fa5a6aa5e2799840be5034c478 Mon Sep 17 00:00:00 2001 From: UUBulb <35923940+uubulb@users.noreply.github.com> Date: Sun, 21 Jul 2024 16:18:25 +0800 Subject: [PATCH] add a simple timeout check for sync script (#42) * add a simple timeout check for sync script * add workflow timeout --- .github/workflows/sync-release.yml | 1 + .github/workflows/sync.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sync-release.yml b/.github/workflows/sync-release.yml index a6482ed..901296d 100644 --- a/.github/workflows/sync-release.yml +++ b/.github/workflows/sync-release.yml @@ -6,6 +6,7 @@ on: jobs: sync-release-to-gitee: runs-on: ubuntu-latest + timeout-minutes: 30 env: GITEE_TOKEN: ${{ secrets.GITEE_TOKEN }} steps: diff --git a/.github/workflows/sync.py b/.github/workflows/sync.py index 478bdea..a30a417 100644 --- a/.github/workflows/sync.py +++ b/.github/workflows/sync.py @@ -53,7 +53,17 @@ def sync_to_gitee(tag: str, body: str, files: slice): 'prerelease': False, 'target_commitish': 'main' } - release_api_response = api_client.post(release_api_uri, json=release_data) + while True: + try: + release_api_response = api_client.post(release_api_uri, json=release_data, timeout=30) + release_api_response.raise_for_status() + break + except requests.exceptions.Timeout as errt: + print(f"Request timed out: {errt} Retrying in 60 seconds...") + time.sleep(60) + except requests.exceptions.RequestException as err: + print(f"Request failed: {err}") + break if release_api_response.status_code == 201: release_info = release_api_response.json() release_id = release_info.get('id')