feat: task manager

This commit is contained in:
Noah Hsu
2022-06-17 15:57:16 +08:00
parent 6d0e54d87e
commit 53e969e894
4 changed files with 106 additions and 21 deletions

View File

@@ -1,10 +1,36 @@
// manage task, such as file upload, file copy between accounts, offline download, etc.
package task
type Func func(task *Task) error
var (
PENDING = "pending"
RUNNING = "running"
FINISHED = "finished"
)
type Task struct {
Name string
Status string
Error error
Finish bool
Children []*Task
ID int64
Name string
Status string
Error error
Func Func
}
func NewTask(name string, func_ Func) *Task {
return &Task{
Name: name,
Status: PENDING,
Func: func_,
}
}
func (t *Task) SetStatus(status string) {
t.Status = status
}
func (t *Task) Run() {
t.Status = RUNNING
t.Error = t.Func(t)
t.Status = FINISHED
}