Skip to content

Add Retry button when creating a mirror-repo fails #26228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ milestones = Milestones

ok = OK
cancel = Cancel
retry = Retry
rerun = Re-run
rerun_all = Re-run all jobs
save = Save
Expand Down
9 changes: 9 additions & 0 deletions routers/web/repo/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@ func setMigrationContextData(ctx *context.Context, serviceType structs.GitServic
ctx.Data["service"] = serviceType
}

func MigrateRetryPost(ctx *context.Context) {
if err := task.RetryMigrateTask(ctx.Repo.Repository.ID); err != nil {
log.Error("Retry task failed: %v", err)
ctx.ServerError("task.RetryMigrateTask", err)
return
}
ctx.JSONOK()
}

func MigrateCancelPost(ctx *context.Context) {
migratingTask, err := admin_model.GetMigratingTask(ctx.Repo.Repository.ID)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,11 @@ func registerRoutes(m *web.Route) {
addSettingsSecretsRoutes()
addSettingVariablesRoutes()
}, actions.MustEnableActions)
m.Post("/migrate/cancel", repo.MigrateCancelPost) // this handler must be under "settings", otherwise this incomplete repo can't be accessed
// the follow handler must be under "settings", otherwise this incomplete repo can't be accessed
m.Group("/migrate", func() {
m.Post("/retry", repo.MigrateRetryPost)
m.Post("/cancel", repo.MigrateCancelPost)
})
}, ctxDataSet("PageIsRepoSettings", true, "LFSStartServer", setting.LFS.StartServer))
}, reqSignIn, context.RepoAssignment, context.UnitTypes(), reqRepoAdmin, context.RepoRef())

Expand Down
24 changes: 24 additions & 0 deletions services/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,27 @@ func CreateMigrateTask(doer, u *user_model.User, opts base.MigrateOptions) (*adm

return task, nil
}

// RetryMigrateTask retry a migrate task
func RetryMigrateTask(repoID int64) error {
migratingTask, err := admin_model.GetMigratingTask(repoID)
if err != nil {
log.Error("GetMigratingTask: %v", err)
return err
}
if migratingTask.Status == structs.TaskStatusQueued || migratingTask.Status == structs.TaskStatusRunning {
return nil
}

// TODO Need to removing the storage/database garbage brought by the failed task

// Reset task status and messages
migratingTask.Status = structs.TaskStatusQueued
migratingTask.Message = ""
if err = migratingTask.UpdateCols("status", "message"); err != nil {
log.Error("task.UpdateCols failed: %v", err)
return err
}

return taskQueue.Push(migratingTask)
}
5 changes: 3 additions & 2 deletions templates/repo/migrate/migrating.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@
<div class="divider"></div>
<div class="item">
{{if .Failed}}
<button class="ui basic red show-modal button" data-modal="#delete-repo-modal">{{.locale.Tr "repo.settings.delete"}}</button>
<button class="ui basic red show-modal button" data-modal="#delete-repo-modal">{{.locale.Tr "repo.settings.delete"}}</button>
{{else}}
<button class="ui basic red show-modal button" data-modal="#cancel-repo-modal">{{.locale.Tr "cancel"}}</button>
<button class="ui basic red show-modal button" data-modal="#cancel-repo-modal">{{.locale.Tr "cancel"}}</button>
{{end}}
<button id="repo_migrating_retry" data-migrating-task-retry-url="{{.Link}}/settings/migrate/retry" class="ui basic button gt-hidden">{{.locale.Tr "retry"}}</button>
</div>
{{end}}
</div>
Expand Down
16 changes: 15 additions & 1 deletion web_src/js/features/repo-migrate.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import $ from 'jquery';
import {hideElem, showElem} from '../utils/dom.js';

const {appSubUrl} = window.config;
const {appSubUrl, csrfToken} = window.config;

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

$('#repo_migrating_retry').on('click', doMigrationRetry);

const task = $repoMigrating.attr('data-migrating-task-id');

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

syncTaskStatus(); // no await
}

async function doMigrationRetry(e) {
await fetch($(e.target).attr('data-migrating-task-retry-url'), {
method: 'post',
headers: {
'X-Csrf-Token': csrfToken,
'Content-Type': 'application/json',
},
});
window.location.reload();
}