From e177728a823ce5974a101994c3f687a579ed8ca4 Mon Sep 17 00:00:00 2001 From: techknowlogick <techknowlogick@gitea.io> Date: Sat, 24 Oct 2020 01:02:36 -0400 Subject: [PATCH] Store task errors following migrations and display them (#13246) (#13287) * Store task errors following migrations and display them When migrate tasks fail store the error in the task table and ensure that they show on the status page. Fix #13242 Signed-off-by: Andrew Thornton <art27@cantab.net> * Update web_src/js/index.js * Hide the failed first Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: zeripath <art27@cantab.net> --- models/task.go | 21 ++++++++++++++ modules/task/migrate.go | 39 +++++++++++++++----------- public/img/failed.png | Bin 0 -> 11009 bytes routers/repo/repo.go | 16 ----------- routers/routes/routes.go | 3 +- routers/user/task.go | 30 ++++++++++++++++++++ templates/repo/migrate/migrating.tmpl | 8 +++++- web_src/js/index.js | 19 +++++++++---- 8 files changed, 95 insertions(+), 41 deletions(-) create mode 100644 public/img/failed.png create mode 100644 routers/user/task.go diff --git a/models/task.go b/models/task.go index 43cb2d4d9a..b86314b449 100644 --- a/models/task.go +++ b/models/task.go @@ -147,6 +147,27 @@ func GetMigratingTask(repoID int64) (*Task, error) { return &task, nil } +// GetMigratingTaskByID returns the migrating task by repo's id +func GetMigratingTaskByID(id, doerID int64) (*Task, *migration.MigrateOptions, error) { + var task = Task{ + ID: id, + DoerID: doerID, + Type: structs.TaskTypeMigrateRepo, + } + has, err := x.Get(&task) + if err != nil { + return nil, nil, err + } else if !has { + return nil, nil, ErrTaskDoesNotExist{id, 0, task.Type} + } + + var opts migration.MigrateOptions + if err := json.Unmarshal([]byte(task.PayloadContent), &opts); err != nil { + return nil, nil, err + } + return &task, &opts, nil +} + // FindTaskOptions find all tasks type FindTaskOptions struct { Status int diff --git a/modules/task/migrate.go b/modules/task/migrate.go index d25decaa00..99f0435b28 100644 --- a/modules/task/migrate.go +++ b/modules/task/migrate.go @@ -20,7 +20,7 @@ import ( "code.gitea.io/gitea/modules/util" ) -func handleCreateError(owner *models.User, err error, name string) error { +func handleCreateError(owner *models.User, err error) error { switch { case models.IsErrReachLimitOfRepo(err): return fmt.Errorf("You have already reached your limit of %d repositories", owner.MaxCreationLimit()) @@ -38,8 +38,8 @@ func handleCreateError(owner *models.User, err error, name string) error { func runMigrateTask(t *models.Task) (err error) { defer func() { if e := recover(); e != nil { - err = fmt.Errorf("PANIC whilst trying to do migrate task: %v\nStacktrace: %v", err, log.Stack(2)) - log.Critical("PANIC during runMigrateTask[%d] by DoerID[%d] to RepoID[%d] for OwnerID[%d]: %v", t.ID, t.DoerID, t.RepoID, t.OwnerID, err) + err = fmt.Errorf("PANIC whilst trying to do migrate task: %v", e) + log.Critical("PANIC during runMigrateTask[%d] by DoerID[%d] to RepoID[%d] for OwnerID[%d]: %v\nStacktrace: %v", t.ID, t.DoerID, t.RepoID, t.OwnerID, e, log.Stack(2)) } if err == nil { @@ -55,7 +55,8 @@ func runMigrateTask(t *models.Task) (err error) { t.EndTime = timeutil.TimeStampNow() t.Status = structs.TaskStatusFailed t.Errors = err.Error() - if err := t.UpdateCols("status", "errors", "end_time"); err != nil { + t.RepoID = 0 + if err := t.UpdateCols("status", "errors", "repo_id", "end_time"); err != nil { log.Error("Task UpdateCols failed: %v", err) } @@ -66,8 +67,8 @@ func runMigrateTask(t *models.Task) (err error) { } }() - if err := t.LoadRepo(); err != nil { - return err + if err = t.LoadRepo(); err != nil { + return } // if repository is ready, then just finsih the task @@ -75,33 +76,35 @@ func runMigrateTask(t *models.Task) (err error) { return nil } - if err := t.LoadDoer(); err != nil { - return err + if err = t.LoadDoer(); err != nil { + return } - if err := t.LoadOwner(); err != nil { - return err + if err = t.LoadOwner(); err != nil { + return } t.StartTime = timeutil.TimeStampNow() t.Status = structs.TaskStatusRunning - if err := t.UpdateCols("start_time", "status"); err != nil { - return err + if err = t.UpdateCols("start_time", "status"); err != nil { + return } var opts *migration.MigrateOptions opts, err = t.MigrateConfig() if err != nil { - return err + return } opts.MigrateToRepoID = t.RepoID - repo, err := migrations.MigrateRepository(graceful.GetManager().HammerContext(), t.Doer, t.Owner.Name, *opts) + var repo *models.Repository + repo, err = migrations.MigrateRepository(graceful.GetManager().HammerContext(), t.Doer, t.Owner.Name, *opts) if err == nil { log.Trace("Repository migrated [%d]: %s/%s", repo.ID, t.Owner.Name, repo.Name) - return nil + return } if models.IsErrRepoAlreadyExist(err) { - return errors.New("The repository name is already used") + err = errors.New("The repository name is already used") + return } // remoteAddr may contain credentials, so we sanitize it @@ -113,5 +116,7 @@ func runMigrateTask(t *models.Task) (err error) { return fmt.Errorf("Migration failed: %v", err.Error()) } - return handleCreateError(t.Owner, err, "MigratePost") + // do not be tempted to coalesce this line with the return + err = handleCreateError(t.Owner, err) + return } diff --git a/public/img/failed.png b/public/img/failed.png new file mode 100644 index 0000000000000000000000000000000000000000..b37545f90ca3b304357516661efb9e1431fa96aa GIT binary patch literal 11009 zcmW-n1yCH#5`ZDN6Wqy<2MO+$KyVKd+_}TuCAhoW;T{O?ZoxU+;cy6UK@WMCw^h4S zyE9uW)7{hkbw{cy%V43Cp~Jz!VadsU{RV4iVS5lNGVI7roYn+u5M3nXG*DriFRFP2 z>>SNeR>uW44&mPpe;Ydpg<T|dmC|-qcL2D0m^fR&d3bnyva+{vF*9+r_~hUW%sv+( zgM<43C-?P>h9~GO#|M<-=6ATcxp@OxGq-O`_#A|eH>&uKXs|nknIjWzTEo?Vb<ui7 ztFqqWBS1o@rbBsYJZMbu^RD%;cDG;6rc1i*G_nk8iwbKcO)2KcF-WY4BcbN!hj-6n z&|wz<7h2l{s4XWMbRX>%x|DhI{A1HAck}+ypqsxa%Id@#W1#eKjb_dpKONmCv`_wn zw&e;@1S98<s0U$!jk%7;D<F|>{v48?CH&a-&kkLq_g=5beON*CaLDokI@+oJGpDM! z%$_V8@KU`kl(v4g4gSLtV{SsKngi8l<47!fMe*-?;<xdXe`1(t!r>_|+zwB?e^;N# zsqY#ig-`ussTge6awp!MP@glV@q5|kM2OK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T`lj ip&jiROR=wSD8zsWV}8L1Cs?^EoSc;M*J=slp#K48eBxaI literal 0 HcmV?d00001 diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 742c952f6e..4220750328 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -402,19 +402,3 @@ func Download(ctx *context.Context) { ctx.ServeFile(archivePath, ctx.Repo.Repository.Name+"-"+refName+ext) } - -// Status returns repository's status -func Status(ctx *context.Context) { - task, err := models.GetMigratingTask(ctx.Repo.Repository.ID) - if err != nil { - ctx.JSON(500, map[string]interface{}{ - "err": err, - }) - return - } - - ctx.JSON(200, map[string]interface{}{ - "status": ctx.Repo.Repository.Status, - "err": task.Errors, - }) -} diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 135c6b56a8..586474a661 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -479,6 +479,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("/forgot_password", user.ForgotPasswd) m.Post("/forgot_password", user.ForgotPasswdPost) m.Post("/logout", user.SignOut) + m.Get("/task/:task", user.TaskStatus) }) // ***** END: User ***** @@ -986,8 +987,6 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("/archive/*", repo.MustBeNotEmpty, reqRepoCodeReader, repo.Download) - m.Get("/status", reqRepoCodeReader, repo.Status) - m.Group("/branches", func() { m.Get("", repo.Branches) }, repo.MustBeNotEmpty, context.RepoRef(), reqRepoCodeReader) diff --git a/routers/user/task.go b/routers/user/task.go new file mode 100644 index 0000000000..a88257ee50 --- /dev/null +++ b/routers/user/task.go @@ -0,0 +1,30 @@ +// Copyright 2020 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package user + +import ( + "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/context" +) + +// TaskStatus returns task's status +func TaskStatus(ctx *context.Context) { + task, opts, err := models.GetMigratingTaskByID(ctx.ParamsInt64("task"), ctx.User.ID) + if err != nil { + ctx.JSON(500, map[string]interface{}{ + "err": err, + }) + return + } + + ctx.JSON(200, map[string]interface{}{ + "status": task.Status, + "err": task.Errors, + "repo-id": task.RepoID, + "repo-name": opts.RepoName, + "start": task.StartTime, + "end": task.EndTime, + }) +} diff --git a/templates/repo/migrate/migrating.tmpl b/templates/repo/migrate/migrating.tmpl index 0057325e91..fdda33a2c7 100644 --- a/templates/repo/migrate/migrating.tmpl +++ b/templates/repo/migrate/migrating.tmpl @@ -7,11 +7,16 @@ {{template "base/alert" .}} <div class="home"> <div class="ui stackable middle very relaxed page grid"> - <div id="repo_migrating" class="sixteen wide center aligned centered column" repo="{{.Repo.Repository.FullName}}"> + <div id="repo_migrating" class="sixteen wide center aligned centered column" task="{{.MigrateTask.ID}}"> <div> <img src="{{StaticUrlPrefix}}/img/loading.png"/> </div> </div> + <div id="repo_migrating_failed_image" class="sixteen wide center aligned centered column" style="display: none;"> + <div> + <img src="{{StaticUrlPrefix}}/img/failed.png"/> + </div> + </div> </div> <div class="ui stackable middle very relaxed page grid"> <div class="sixteen wide center aligned centered column"> @@ -20,6 +25,7 @@ </div> <div id="repo_migrating_failed"> <p>{{.i18n.Tr "repo.migrate.migrating_failed" .CloneAddr | Safe}}</p> + <p id="repo_migrating_failed_error"></p> </div> </div> </div> diff --git a/web_src/js/index.js b/web_src/js/index.js index 9fafe62d3e..94238ca3d9 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -191,25 +191,32 @@ function updateIssuesMeta(url, action, issueIds, elementId) { function initRepoStatusChecker() { const migrating = $('#repo_migrating'); $('#repo_migrating_failed').hide(); + $('#repo_migrating_failed_image').hide(); if (migrating) { - const repo_name = migrating.attr('repo'); - if (typeof repo_name === 'undefined') { + const task = migrating.attr('task'); + if (typeof task === 'undefined') { return; } $.ajax({ type: 'GET', - url: `${AppSubUrl}/${repo_name}/status`, + url: `${AppSubUrl}/user/task/${task}`, data: { _csrf: csrf, }, complete(xhr) { if (xhr.status === 200) { if (xhr.responseJSON) { - if (xhr.responseJSON.status === 0) { + if (xhr.responseJSON.status === 4) { window.location.reload(); return; + } else if (xhr.responseJSON.status === 3) { + $('#repo_migrating_progress').hide(); + $('#repo_migrating').hide(); + $('#repo_migrating_failed').show(); + $('#repo_migrating_failed_image').show(); + $('#repo_migrating_failed_error').text(xhr.responseJSON.err); + return; } - setTimeout(() => { initRepoStatusChecker(); }, 2000); @@ -217,7 +224,9 @@ function initRepoStatusChecker() { } } $('#repo_migrating_progress').hide(); + $('#repo_migrating').hide(); $('#repo_migrating_failed').show(); + $('#repo_migrating_failed_image').show(); } }); }