From e177728a823ce5974a101994c3f687a579ed8ca4 Mon Sep 17 00:00:00 2001 From: techknowlogick 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 * Update web_src/js/index.js * Hide the failed first Signed-off-by: Andrew Thornton Co-authored-by: techknowlogick Co-authored-by: zeripath --- 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;Ydpgh9~GO#|M<-=6ATcxp@OxGq-O`_#A|eH>&uKXs|nknIjWzTEo?Vb%x|DhI{A1HAck}+ypqsxa%Id@#W1#eKjb_dpKONmCv`_wn zw&e;@1S98{v48?CH&a-&kkLq_g=5beON*CaLDokI@+oJGpDM! z%$_V8@KU`kl(v4g4gSLtV{SsKngi8l<47!fMe*-?;_|+zwB?e^;N# zsqY#ig-`ussTge6awp!MP@glV@q5|kM2OK&=|~xP_a*X4BO)t!8LOYB>atv{L4hB{Ys9W<%%*dvtiyWEfKA$xhK-8>d5>R!1d#R z=0(fSJ7FouvY3*m~(g@zjST%>ITW3Z|7?hxt1!G-J>4t@`*uE6;{n}s(?9-Umsx!u>w zN*s#Qe5*g-InAX>OX##bJv09#7emhdrIYa|XHRjkXGQu=^B9wR=V>fU_tl=q{XVg7 zwY6yE{W<0#h!;9`}=ARjPICoyjQ=+stM z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W?$@?B%iYVScfSW|`P^SJ z{E#sk)~gCWCy^Qhl%0+{ukt6ZAfVskS4*bR9prCsNwY%HHzZkoM_XXJ-!iL`i50k+ z@KOWa6kpHHaMqvx^h`=qjRU#jMR7{XXJ zhi}io7<4}+bg?e88}LTM%I15Iw%rCc18?oROft@_%lYh?4{Grf2IWEijfsy?6U1)1SDWJMPI1V!TX_zteigg^Y2G3h2i0}~6g;RH5ZTIVAXzb4KHF;E7l~)!OsG^>*Mr6GU z!i1Dru%>DU)e&e1*>aYXYGYcb=@fZ!0g4G7q>dHIzI9@Xo7Wm$hD0)k-s)Jw3T`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" .}}

-
+
+
@@ -20,6 +25,7 @@

{{.i18n.Tr "repo.migrate.migrating_failed" .CloneAddr | Safe}}

+

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(); } }); }