mirror of https://github.com/Xhofe/alist
chore(aria2): export task manager
parent
92983aa185
commit
40b7ecc845
|
@ -43,7 +43,7 @@ func AddURI(ctx context.Context, uri string, dstDirPath string) error {
|
|||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to add uri %s", uri)
|
||||
}
|
||||
downTaskManager.Submit(task.WithCancelCtx(&task.Task[string]{
|
||||
DownTaskManager.Submit(task.WithCancelCtx(&task.Task[string]{
|
||||
ID: gid,
|
||||
Name: fmt.Sprintf("download %s to [%s](%s)", uri, account.GetAccount().VirtualPath, dstDirActualPath),
|
||||
Func: func(tsk *task.Task[string]) error {
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
var downTaskManager = task.NewTaskManager[string](3)
|
||||
var DownTaskManager = task.NewTaskManager[string](3)
|
||||
var notify = NewNotify()
|
||||
var client rpc.Client
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ func TestDown(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("failed to add uri: %+v", err)
|
||||
}
|
||||
tasks := downTaskManager.GetAll()
|
||||
tasks := DownTaskManager.GetAll()
|
||||
if len(tasks) != 1 {
|
||||
t.Errorf("failed to get tasks: %+v", tasks)
|
||||
}
|
||||
|
@ -70,10 +70,10 @@ func TestDown(t *testing.T) {
|
|||
time.Sleep(time.Second)
|
||||
}
|
||||
for {
|
||||
if len(transferTaskManager.GetAll()) == 0 {
|
||||
if len(TransferTaskManager.GetAll()) == 0 {
|
||||
continue
|
||||
}
|
||||
tsk := transferTaskManager.GetAll()[0]
|
||||
tsk := TransferTaskManager.GetAll()[0]
|
||||
t.Logf("task: %+v", tsk)
|
||||
if tsk.GetState() == task.Succeeded {
|
||||
break
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
package aria2
|
||||
|
||||
import "context"
|
||||
|
||||
func ListFinished(ctx context.Context) {
|
||||
import (
|
||||
"context"
|
||||
"github.com/alist-org/alist/v3/pkg/task"
|
||||
)
|
||||
|
||||
func ListFinished(ctx context.Context) []*task.Task[string] {
|
||||
return DownTaskManager.GetByStates(task.Succeeded, task.CANCELED, task.ERRORED)
|
||||
}
|
||||
|
||||
func ListUndone(ctx context.Context) []*task.Task[string] {
|
||||
return DownTaskManager.GetByStates(task.PENDING, task.RUNNING, task.CANCELING)
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ func (m *Monitor) Update() (bool, error) {
|
|||
}
|
||||
}
|
||||
|
||||
var transferTaskManager = task.NewTaskManager[uint64](3, func(k *uint64) {
|
||||
var TransferTaskManager = task.NewTaskManager[uint64](3, func(k *uint64) {
|
||||
atomic.AddUint64(k, 1)
|
||||
})
|
||||
|
||||
|
@ -119,7 +119,7 @@ func (m *Monitor) Complete() error {
|
|||
}
|
||||
}()
|
||||
for _, file := range files {
|
||||
transferTaskManager.Submit(task.WithCancelCtx[uint64](&task.Task[uint64]{
|
||||
TransferTaskManager.Submit(task.WithCancelCtx[uint64](&task.Task[uint64]{
|
||||
Name: fmt.Sprintf("transfer %s to [%s](%s)", file.Path, account.GetAccount().VirtualPath, dstDirActualPath),
|
||||
Func: func(tsk *task.Task[uint64]) error {
|
||||
defer wg.Done()
|
||||
|
|
Loading…
Reference in New Issue