refractor: downloader task action dispatch (#249)

This commit is contained in:
Levi authored and GitHub committed 2023-10-24 16:02:39 +08:00
1 parent ff6c0da262
commit 11befc09bd
5 files changed
+279 -206

No files matched your search

+268 -196
View File
File diff suppressed because it is too large. Load diff
+3 -4
View File
@@ -251,12 +251,12 @@ func (d *Downloader) triggerOnResolve(req *base.Request) (res *base.Resource) {
return
}
func (d *Downloader) triggerOnStart(task *Task) {
func (d *Downloader) triggerOnStart(task *Task) (req *base.Request) {
doTrigger(d,
EventOnStart,
task.Meta.Req,
&OnStartContext{
Task: task.clone(),
Task: task,
},
func(ext *Extension, gopeed *Instance, ctx *OnStartContext) {
// Validate request structure
@@ -265,8 +265,7 @@ func (d *Downloader) triggerOnStart(task *Task) {
gopeed.Logger.logger.Warn().Err(err).Msgf("[%s] request invalid", ext.buildIdentity())
return
}
// Modify real task request
task.Meta.Req = ctx.Task.Meta.Req
req = ctx.Task.Meta.Req
}
},
)
+3
View File
@@ -222,6 +222,9 @@ func (b *BoltStorage) Pop(bucket string, key string, v any) error {
if err != nil {
return err
}
if len(data) == 0 {
return nil
}
return json.Unmarshal(data, v)
}
-3
View File
@@ -204,19 +204,16 @@ func TestPauseAllAndContinueALLTasks(t *testing.T) {
// continue all
httpRequestCheckOk[any](http.MethodPut, "/api/v1/tasks/continue", nil)
time.Sleep(time.Millisecond * 100)
tasks := httpRequestCheckOk[[]*download.Task](http.MethodGet, fmt.Sprintf("/api/v1/tasks?status=%s", base.DownloadStatusRunning), nil)
if len(tasks) != cfg.MaxRunning {
t.Errorf("ContinueAllTasks() got = %v, want %v", len(tasks), cfg.MaxRunning)
}
// pause all
httpRequestCheckOk[any](http.MethodPut, "/api/v1/tasks/pause", nil)
time.Sleep(time.Millisecond * 500)
tasks = httpRequestCheckOk[[]*download.Task](http.MethodGet, fmt.Sprintf("/api/v1/tasks?status=%s", base.DownloadStatusPause), nil)
if len(tasks) != total {
t.Errorf("PauseAllTasks() got = %v, want %v", len(tasks), total)
}
})
}