Skip to content

Commit 865d222

Browse files
Add Retry button when creating a mirror-repo fails (#26228)
fixed #26156 * Added a retry button in the frontend (only displayed when the status is abnormal) * After clicking Retry, the backend adds the task back to the task queue ![7UJDNM671RI})EA8~~XPL39](https://github.com/go-gitea/gitea/assets/3371163/e088fd63-5dcc-4bc6-8849-7db3086511b7) ![T83F1WL9)VGHR@MB956$VT9](https://github.com/go-gitea/gitea/assets/3371163/744425bb-dde1-4315-be2e-5c99ac3a44d4) --------- Co-authored-by: wxiaoguang <[email protected]>
1 parent 907beda commit 865d222

File tree

6 files changed

+57
-4
lines changed

6 files changed

+57
-4
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ milestones = Milestones
8080

8181
ok = OK
8282
cancel = Cancel
83+
retry = Retry
8384
rerun = Re-run
8485
rerun_all = Re-run all jobs
8586
save = Save

routers/web/repo/migrate.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,15 @@ func setMigrationContextData(ctx *context.Context, serviceType structs.GitServic
259259
ctx.Data["service"] = serviceType
260260
}
261261

262+
func MigrateRetryPost(ctx *context.Context) {
263+
if err := task.RetryMigrateTask(ctx.Repo.Repository.ID); err != nil {
264+
log.Error("Retry task failed: %v", err)
265+
ctx.ServerError("task.RetryMigrateTask", err)
266+
return
267+
}
268+
ctx.JSONOK()
269+
}
270+
262271
func MigrateCancelPost(ctx *context.Context) {
263272
migratingTask, err := admin_model.GetMigratingTask(ctx.Repo.Repository.ID)
264273
if err != nil {

routers/web/web.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,11 @@ func registerRoutes(m *web.Route) {
953953
addSettingsSecretsRoutes()
954954
addSettingVariablesRoutes()
955955
}, actions.MustEnableActions)
956-
m.Post("/migrate/cancel", repo.MigrateCancelPost) // this handler must be under "settings", otherwise this incomplete repo can't be accessed
956+
// the follow handler must be under "settings", otherwise this incomplete repo can't be accessed
957+
m.Group("/migrate", func() {
958+
m.Post("/retry", repo.MigrateRetryPost)
959+
m.Post("/cancel", repo.MigrateCancelPost)
960+
})
957961
}, ctxDataSet("PageIsRepoSettings", true, "LFSStartServer", setting.LFS.StartServer))
958962
}, reqSignIn, context.RepoAssignment, context.UnitTypes(), reqRepoAdmin, context.RepoRef())
959963

services/task/task.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,27 @@ func CreateMigrateTask(doer, u *user_model.User, opts base.MigrateOptions) (*adm
126126

127127
return task, nil
128128
}
129+
130+
// RetryMigrateTask retry a migrate task
131+
func RetryMigrateTask(repoID int64) error {
132+
migratingTask, err := admin_model.GetMigratingTask(repoID)
133+
if err != nil {
134+
log.Error("GetMigratingTask: %v", err)
135+
return err
136+
}
137+
if migratingTask.Status == structs.TaskStatusQueued || migratingTask.Status == structs.TaskStatusRunning {
138+
return nil
139+
}
140+
141+
// TODO Need to removing the storage/database garbage brought by the failed task
142+
143+
// Reset task status and messages
144+
migratingTask.Status = structs.TaskStatusQueued
145+
migratingTask.Message = ""
146+
if err = migratingTask.UpdateCols("status", "message"); err != nil {
147+
log.Error("task.UpdateCols failed: %v", err)
148+
return err
149+
}
150+
151+
return taskQueue.Push(migratingTask)
152+
}

templates/repo/migrate/migrating.tmpl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@
3636
<div class="divider"></div>
3737
<div class="item">
3838
{{if .Failed}}
39-
<button class="ui basic red show-modal button" data-modal="#delete-repo-modal">{{.locale.Tr "repo.settings.delete"}}</button>
39+
<button class="ui basic red show-modal button" data-modal="#delete-repo-modal">{{.locale.Tr "repo.settings.delete"}}</button>
4040
{{else}}
41-
<button class="ui basic red show-modal button" data-modal="#cancel-repo-modal">{{.locale.Tr "cancel"}}</button>
41+
<button class="ui basic red show-modal button" data-modal="#cancel-repo-modal">{{.locale.Tr "cancel"}}</button>
4242
{{end}}
43+
<button id="repo_migrating_retry" data-migrating-task-retry-url="{{.Link}}/settings/migrate/retry" class="ui basic button gt-hidden">{{.locale.Tr "retry"}}</button>
4344
</div>
4445
{{end}}
4546
</div>

web_src/js/features/repo-migrate.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import $ from 'jquery';
22
import {hideElem, showElem} from '../utils/dom.js';
33

4-
const {appSubUrl} = window.config;
4+
const {appSubUrl, csrfToken} = window.config;
55

66
export function initRepoMigrationStatusChecker() {
77
const $repoMigrating = $('#repo_migrating');
88
if (!$repoMigrating.length) return;
99

10+
$('#repo_migrating_retry').on('click', doMigrationRetry);
11+
1012
const task = $repoMigrating.attr('data-migrating-task-id');
1113

1214
// returns true if the refresh still need to be called after a while
@@ -31,6 +33,7 @@ export function initRepoMigrationStatusChecker() {
3133
if (data.status === 3) {
3234
hideElem('#repo_migrating_progress');
3335
hideElem('#repo_migrating');
36+
showElem('#repo_migrating_retry');
3437
showElem('#repo_migrating_failed');
3538
showElem('#repo_migrating_failed_image');
3639
$('#repo_migrating_failed_error').text(data.message);
@@ -53,3 +56,14 @@ export function initRepoMigrationStatusChecker() {
5356

5457
syncTaskStatus(); // no await
5558
}
59+
60+
async function doMigrationRetry(e) {
61+
await fetch($(e.target).attr('data-migrating-task-retry-url'), {
62+
method: 'post',
63+
headers: {
64+
'X-Csrf-Token': csrfToken,
65+
'Content-Type': 'application/json',
66+
},
67+
});
68+
window.location.reload();
69+
}

0 commit comments

Comments
 (0)