Files
OpenList/internal/task/task.go

37 lines
575 B
Go
Raw Normal View History

2022-06-14 17:19:43 +08:00
// manage task, such as file upload, file copy between accounts, offline download, etc.
2022-06-06 22:08:39 +08:00
package task
2022-06-14 17:19:43 +08:00
2022-06-17 15:57:16 +08:00
type Func func(task *Task) error
var (
PENDING = "pending"
RUNNING = "running"
FINISHED = "finished"
)
2022-06-14 17:19:43 +08:00
type Task struct {
2022-06-17 15:57:16 +08:00
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
2022-06-14 17:19:43 +08:00
}