add a simple timeout check for sync script (#42)

* add a simple timeout check for sync script

* add workflow timeout
This commit is contained in:
UUBulb 2024-07-21 16:18:25 +08:00 committed by GitHub
parent 0a6adea9ab
commit d7ca50dd83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -6,6 +6,7 @@ on:
jobs: jobs:
sync-release-to-gitee: sync-release-to-gitee:
runs-on: ubuntu-latest runs-on: ubuntu-latest
timeout-minutes: 30
env: env:
GITEE_TOKEN: ${{ secrets.GITEE_TOKEN }} GITEE_TOKEN: ${{ secrets.GITEE_TOKEN }}
steps: steps:

View File

@ -53,7 +53,17 @@ def sync_to_gitee(tag: str, body: str, files: slice):
'prerelease': False, 'prerelease': False,
'target_commitish': 'main' '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: if release_api_response.status_code == 201:
release_info = release_api_response.json() release_info = release_api_response.json()
release_id = release_info.get('id') release_id = release_info.get('id')