test: add task manager test

This commit is contained in:
Noah Hsu
2022-06-17 22:09:20 +08:00
parent 68ca2abd0c
commit 6ad2cf2003
2 changed files with 98 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package task
import (
"github.com/pkg/errors"
"sync/atomic"
"github.com/alist-org/alist/v3/pkg/generic_sync"
@ -32,6 +33,24 @@ func (tm *Manager) Get(id uint64) (*Task, bool) {
return tm.tasks.Load(id)
}
func (tm *Manager) Retry(id uint64) error {
t, ok := tm.Get(id)
if !ok {
return errors.New("task not found")
}
t.Retry()
return nil
}
func (tm *Manager) Cancel(id uint64) error {
t, ok := tm.Get(id)
if !ok {
return errors.New("task not found")
}
t.Cancel()
return nil
}
func (tm *Manager) Remove(id uint64) {
tm.tasks.Delete(id)
}