feat(task): add speed monitor (#7655)
This commit is contained in:
@ -29,7 +29,7 @@ type AddURLArgs struct {
|
||||
DeletePolicy DeletePolicy
|
||||
}
|
||||
|
||||
func AddURL(ctx context.Context, args *AddURLArgs) (task.TaskInfoWithCreator, error) {
|
||||
func AddURL(ctx context.Context, args *AddURLArgs) (task.TaskExtensionInfo, error) {
|
||||
// get tool
|
||||
tool, err := Tools.Get(args.Tool)
|
||||
if err != nil {
|
||||
@ -81,7 +81,7 @@ func AddURL(ctx context.Context, args *AddURLArgs) (task.TaskInfoWithCreator, er
|
||||
|
||||
taskCreator, _ := ctx.Value("user").(*model.User) // taskCreator is nil when convert failed
|
||||
t := &DownloadTask{
|
||||
TaskWithCreator: task.TaskWithCreator{
|
||||
TaskExtension: task.TaskExtension{
|
||||
Creator: taskCreator,
|
||||
},
|
||||
Url: args.URL,
|
||||
|
@ -16,11 +16,12 @@ type AddUrlArgs struct {
|
||||
}
|
||||
|
||||
type Status struct {
|
||||
Progress float64
|
||||
NewGID string
|
||||
Completed bool
|
||||
Status string
|
||||
Err error
|
||||
TotalBytes int64
|
||||
Progress float64
|
||||
NewGID string
|
||||
Completed bool
|
||||
Status string
|
||||
Err error
|
||||
}
|
||||
|
||||
type Tool interface {
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
type DownloadTask struct {
|
||||
task.TaskWithCreator
|
||||
task.TaskExtension
|
||||
Url string `json:"url"`
|
||||
DstDirPath string `json:"dst_dir_path"`
|
||||
TempDir string `json:"temp_dir"`
|
||||
@ -28,6 +28,9 @@ type DownloadTask struct {
|
||||
}
|
||||
|
||||
func (t *DownloadTask) Run() error {
|
||||
t.ClearEndTime()
|
||||
t.SetStartTime(time.Now())
|
||||
defer func() { t.SetEndTime(time.Now()) }()
|
||||
if t.tool == nil {
|
||||
tool, err := Tools.Get(t.Toolname)
|
||||
if err != nil {
|
||||
@ -131,6 +134,7 @@ func (t *DownloadTask) Update() (bool, error) {
|
||||
}
|
||||
t.callStatusRetried = 0
|
||||
t.SetProgress(info.Progress)
|
||||
t.SetTotalBytes(info.TotalBytes)
|
||||
t.Status = fmt.Sprintf("[%s]: %s", t.tool.Name(), info.Status)
|
||||
if info.NewGID != "" {
|
||||
log.Debugf("followen by: %+v", info.NewGID)
|
||||
@ -171,16 +175,18 @@ func (t *DownloadTask) Complete() error {
|
||||
// upload files
|
||||
for i := range files {
|
||||
file := files[i]
|
||||
TransferTaskManager.Add(&TransferTask{
|
||||
TaskWithCreator: task.TaskWithCreator{
|
||||
Creator: t.Creator,
|
||||
tsk := &TransferTask{
|
||||
TaskExtension: task.TaskExtension{
|
||||
Creator: t.GetCreator(),
|
||||
},
|
||||
file: file,
|
||||
DstDirPath: t.DstDirPath,
|
||||
TempDir: t.TempDir,
|
||||
DeletePolicy: t.DeletePolicy,
|
||||
FileDir: file.Path,
|
||||
})
|
||||
}
|
||||
tsk.SetTotalBytes(file.Size)
|
||||
TransferTaskManager.Add(tsk)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/internal/op"
|
||||
@ -16,7 +17,7 @@ import (
|
||||
)
|
||||
|
||||
type TransferTask struct {
|
||||
task.TaskWithCreator
|
||||
task.TaskExtension
|
||||
FileDir string `json:"file_dir"`
|
||||
DstDirPath string `json:"dst_dir_path"`
|
||||
TempDir string `json:"temp_dir"`
|
||||
@ -25,6 +26,9 @@ type TransferTask struct {
|
||||
}
|
||||
|
||||
func (t *TransferTask) Run() error {
|
||||
t.ClearEndTime()
|
||||
t.SetStartTime(time.Now())
|
||||
defer func() { t.SetEndTime(time.Now()) }()
|
||||
// check dstDir again
|
||||
var err error
|
||||
if (t.file == File{}) {
|
||||
|
Reference in New Issue
Block a user