Skip to content

Only check for non-finished migrating task #19601

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 3 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions models/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ func GetMigratingTask(repoID int64) (*Task, error) {
return &task, nil
}

// HasMigratingTask returns if migrating task exist for repo.
func HasMigratingTask(repoID int64) (bool, error) {
return db.GetEngine(db.DefaultContext).Exist(&Task{
RepoID: repoID,
Type: structs.TaskTypeMigrateRepo,
})
// HasFinishedMigratingTask returns if a finished migration task exists for the repo.
func HasFinishedMigratingTask(repoID int64) (bool, error) {
return db.GetEngine(db.DefaultContext).
Where("repo_id=? AND type=? AND status=?", repoID, structs.TaskTypeMigrateRepo, structs.TaskStatusFinished).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Where("repo_id=? AND type=? AND status=?", repoID, structs.TaskTypeMigrateRepo, structs.TaskStatusFinished).
Where("repo_id=? AND type=? AND status<>?", repoID, structs.TaskTypeMigrateRepo, structs.TaskStatusRunning).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or how should failed migrations be handled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed migrations don't have a any information in the Mirror table.

Table("task").
Exist()
}

// GetMigratingTaskByID returns the migrating task by repo's id
Expand Down
10 changes: 5 additions & 5 deletions modules/context/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,14 @@ func repoAssignment(ctx *Context, repo *repo_model.Repository) {

if repo.IsMirror {

// Check if there's a migrating task.
// If it does exist, don't fetch the Mirror from the database as it doesn't exist yet.
hasTask, err := models.HasMigratingTask(repo.ID)
// Check if the mirror has finsihed migrationg, only then we can
// lookup the mirror informtation the database.
finishedMigrating, err := models.HasFinishedMigratingTask(repo.ID)
if err != nil {
ctx.ServerError("GetMirrorByRepoID", err)
ctx.ServerError("HasFinishedMigratingTask", err)
return
}
if !hasTask {
if finishedMigrating {
ctx.Repo.Mirror, err = repo_model.GetMirrorByRepoID(repo.ID)
if err != nil {
ctx.ServerError("GetMirrorByRepoID", err)
Expand Down