修复列表页加载慢并支持 Gitea 1.27 一键停止
1. 状态同步加 20 秒节流、超时缩短到 8 秒;Gitea 改用 runs 列表接口一次批量取回全部任务状态,在途任务并发补查作业,消除逐任务串行 API 请求导致的后台/我的构建/详情页慢。 2. 停止时先区分 404:运行已删除则本地标记取消;Gitea 1.27 无取消 API 时,若后台配置了 Gitea 网页账号密码则模拟网页登录取消,否则回退手动链接提示。 3. 后台 Gitea 连接设置新增网页登录账号/密码两个可选项。
This commit is contained in:
+14
-11
@@ -32,11 +32,9 @@ def staff_required(view_func):
|
||||
@login_required
|
||||
def my_builds(request):
|
||||
builds = list(GithubRun.objects.filter(created_by=request.user))
|
||||
# 列表打开时向构建平台同步在途任务的真实状态(Gitea 可能不主动回调终态)
|
||||
from .views import refresh_active_run
|
||||
for run in builds:
|
||||
if not run.is_finished():
|
||||
refresh_active_run(run)
|
||||
# 列表打开时并发同步在途任务的真实状态(带短节流,避免频繁刷页面拖慢)
|
||||
from .views import refresh_active_runs
|
||||
refresh_active_runs(builds)
|
||||
return render(request, 'my_builds.html', {'builds': builds})
|
||||
|
||||
|
||||
@@ -82,11 +80,16 @@ def stop_build(request, run_id):
|
||||
if e.kind == 'finished':
|
||||
# 平台侧已结束:立即拉一次真实状态,避免本地仍显示构建中
|
||||
from .views import refresh_active_run
|
||||
refresh_active_run(run)
|
||||
refresh_active_run(run, force=True)
|
||||
if run.is_finished():
|
||||
messages.info(request, f"构建平台上该任务实际已结束({run.status_label()}),列表状态已同步。")
|
||||
else:
|
||||
messages.error(request, str(e))
|
||||
elif e.kind == 'missing':
|
||||
# 平台上运行已被删除:本地直接标记取消,避免永远卡在构建中
|
||||
run.status = 'cancelled'
|
||||
run.save(update_fields=['status', 'updated_at'])
|
||||
messages.info(request, "Gitea 上该运行已不存在(可能已被删除),已在本平台标记为已取消。")
|
||||
elif e.kind == 'unsupported':
|
||||
# 平台版本不支持远程取消(如 Gitea ≤ 1.27):给出运行页,本地状态保持构建中
|
||||
log_link = backend.log_url(run.github_run_id)
|
||||
@@ -167,11 +170,9 @@ def delete_token(request, key):
|
||||
@staff_required
|
||||
def dashboard(request):
|
||||
builds = list(GithubRun.objects.select_related('created_by').all()[:100])
|
||||
# 打开仪表盘时同步在途任务的真实状态
|
||||
from .views import refresh_active_run
|
||||
for run in builds:
|
||||
if not run.is_finished():
|
||||
refresh_active_run(run)
|
||||
# 打开仪表盘时并发同步在途任务的真实状态(带短节流)
|
||||
from .views import refresh_active_runs
|
||||
refresh_active_runs(builds)
|
||||
stats = {
|
||||
'total': GithubRun.objects.count(),
|
||||
'in_progress': GithubRun.objects.exclude(
|
||||
@@ -317,6 +318,7 @@ _PLAIN_FIELDS = [
|
||||
('GITEA_OWNER', 'gitea_owner'),
|
||||
('GITEA_REPO', 'gitea_repo'),
|
||||
('GITEA_BRANCH', 'gitea_branch'),
|
||||
('GITEA_WEB_USERNAME', 'gitea_web_username'),
|
||||
('GHUSER', 'ghuser'),
|
||||
('REPONAME', 'reponame'),
|
||||
('GHBRANCH', 'ghbranch'),
|
||||
@@ -326,6 +328,7 @@ _PLAIN_FIELDS = [
|
||||
# 密钥配置项:设置键 -> (输入字段名, 清除复选框字段名)
|
||||
_SECRET_FIELDS = [
|
||||
('GITEA_TOKEN', ('gitea_token', 'clear_gitea_token')),
|
||||
('GITEA_WEB_PASSWORD', ('gitea_web_password', 'clear_gitea_web_password')),
|
||||
('GITEA_PROXY', ('gitea_proxy', 'clear_gitea_proxy')),
|
||||
('GHBEARER', ('ghbearer', 'clear_ghbearer')),
|
||||
('ZIP_PASSWORD', ('zip_password', 'clear_zip_password')),
|
||||
|
||||
Reference in New Issue
Block a user