Skip to content

Commit

Permalink
Actions 创建storage时超时重试
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-cq committed Mar 23, 2024
1 parent 2eb2a13 commit 4ff8a17
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/alist-sync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,15 @@ jobs:
./alist/data
- name: Install and Init Alist Server
env:
_ALIST_ADMIN_PASSWORD: ${{ secrets.ALIST_ADMIN_PASSWORD }}
run: |
sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
bash -ex bootstrap.sh install
# init-alist 总是会重置管理员密码为环境变量。
bash -x bootstrap.sh alist-init
- name: Create Storage for Alist if load cache failed
if: github.event.inputs.reload_storage == 'true' || steps.alist-data-cache.outputs.cache-hit != 'true'
env:
_ALIST_ADMIN_PASSWORD: ${{ secrets.ALIST_ADMIN_PASSWORD }}

_ALIST_BACKUP: ${{secrets.ALIST_BACKUP}}
_ALIST_BACKUP_URL: ${{secrets.ALIST_BACKUP_URL}}
_ALIST_BACKUP_USERNAME: ${{secrets.ALIST_BACKUP_USERNAME}}
Expand Down
41 changes: 28 additions & 13 deletions tools/create_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
import datetime
import json
import os
import time
from pathlib import Path

import httpx

from alist_sdk import Storage
from alist_sdk.tools.client import ExtraClient

Expand All @@ -18,7 +21,7 @@
alist_config = json.loads(PROJECT_ROOT.joinpath("alist/data/config.json").read_text())

alist_port = alist_config["scheme"]["http_port"]
admin_password = os.getenv("_ALIST_ADMIN_PASSWORD", ) or "123456"
admin_password = os.getenv("_ALIST_ADMIN_PASSWORD", "123456")

remote_url = os.getenv("_ALIST_BACKUP_URL")
remote_username = os.getenv("_ALIST_BACKUP_USERNAME")
Expand Down Expand Up @@ -70,18 +73,30 @@
}
)
)
print(res)
print("创建本地存储状态", res)


if remote_url:
local_client.import_config_from_other_client(
base_url=remote_url,
username=remote_username,
password=remote_password,
verify=False,
)
exit(0)
def create_storage(retry=3):
try:
if remote_url:
local_client.import_config_from_other_client(
base_url=remote_url,
username=remote_username,
password=remote_password,
verify=False,
)
exit(0)

_bk_file = PROJECT_ROOT.joinpath("alist-backup-config.json")
if _bk_file.exists():
local_client.import_configs(json.loads(_bk_file.read_text()))
except httpx.ReadTimeout as _e:
if retry <= 0:
raise _e

print(f"超时 {retry = }")
time.sleep(3)
create_storage(retry=retry - 1)


_bk_file = PROJECT_ROOT.joinpath("alist-backup-config.json")
if _bk_file.exists():
local_client.import_configs(json.loads(_bk_file.read_text()))
create_storage()

0 comments on commit 4ff8a17

Please sign in to comment.