feat: add progress for task
This commit is contained in:
@ -8,6 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type Manager struct {
|
||||
works uint
|
||||
curID uint64
|
||||
tasks generic_sync.MapOf[uint64, *Task]
|
||||
}
|
||||
|
@ -17,13 +17,14 @@ var (
|
||||
type Func func(task *Task) error
|
||||
|
||||
type Task struct {
|
||||
ID uint64
|
||||
Name string
|
||||
Status string
|
||||
Error error
|
||||
Func Func
|
||||
Ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
ID uint64
|
||||
Name string
|
||||
Status string
|
||||
Error error
|
||||
Func Func
|
||||
Progress int
|
||||
Ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
}
|
||||
|
||||
func newTask(name string, func_ Func) *Task {
|
||||
@ -41,6 +42,10 @@ func (t *Task) SetStatus(status string) {
|
||||
t.Status = status
|
||||
}
|
||||
|
||||
func (t *Task) SetProgress(percentage int) {
|
||||
t.Progress = percentage
|
||||
}
|
||||
|
||||
func (t *Task) Run() {
|
||||
t.Status = RUNNING
|
||||
t.Error = t.Func(t)
|
||||
|
Reference in New Issue
Block a user