Make repo migration cancelable and fix various bugs (#24605)
Replace #12917 Close #24601 Close #12845     --------- Co-authored-by: Yarden Shoham <git@yardenshoham.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
parent
58dfaf3a75
commit
f6e029e6c7
10 changed files with 128 additions and 106 deletions
|
@ -17,8 +17,6 @@ import (
|
|||
"code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
// Task represents a task
|
||||
|
@ -35,7 +33,7 @@ type Task struct {
|
|||
StartTime timeutil.TimeStamp
|
||||
EndTime timeutil.TimeStamp
|
||||
PayloadContent string `xorm:"TEXT"`
|
||||
Message string `xorm:"TEXT"` // if task failed, saved the error reason
|
||||
Message string `xorm:"TEXT"` // if task failed, saved the error reason, it could be a JSON string of TranslatableMessage or a plain message
|
||||
Created timeutil.TimeStamp `xorm:"created"`
|
||||
}
|
||||
|
||||
|
@ -185,14 +183,6 @@ func GetMigratingTask(repoID int64) (*Task, error) {
|
|||
return &task, nil
|
||||
}
|
||||
|
||||
// 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).
|
||||
Table("task").
|
||||
Exist()
|
||||
}
|
||||
|
||||
// GetMigratingTaskByID returns the migrating task by repo's id
|
||||
func GetMigratingTaskByID(id, doerID int64) (*Task, *migration.MigrateOptions, error) {
|
||||
task := Task{
|
||||
|
@ -214,27 +204,6 @@ func GetMigratingTaskByID(id, doerID int64) (*Task, *migration.MigrateOptions, e
|
|||
return &task, &opts, nil
|
||||
}
|
||||
|
||||
// FindTaskOptions find all tasks
|
||||
type FindTaskOptions struct {
|
||||
Status int
|
||||
}
|
||||
|
||||
// ToConds generates conditions for database operation.
|
||||
func (opts FindTaskOptions) ToConds() builder.Cond {
|
||||
cond := builder.NewCond()
|
||||
if opts.Status >= 0 {
|
||||
cond = cond.And(builder.Eq{"status": opts.Status})
|
||||
}
|
||||
return cond
|
||||
}
|
||||
|
||||
// FindTasks find all tasks
|
||||
func FindTasks(opts FindTaskOptions) ([]*Task, error) {
|
||||
tasks := make([]*Task, 0, 10)
|
||||
err := db.GetEngine(db.DefaultContext).Where(opts.ToConds()).Find(&tasks)
|
||||
return tasks, err
|
||||
}
|
||||
|
||||
// CreateTask creates a task on database
|
||||
func CreateTask(task *Task) error {
|
||||
return db.Insert(db.DefaultContext, task)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue