mirror of https://github.com/Xhofe/alist
feat(task): allow retry canceled (#7852)
parent
23f3178f39
commit
d5ec998699
|
@ -53,12 +53,13 @@ type TaskConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type TasksConfig struct {
|
type TasksConfig struct {
|
||||||
Download TaskConfig `json:"download" envPrefix:"DOWNLOAD_"`
|
Download TaskConfig `json:"download" envPrefix:"DOWNLOAD_"`
|
||||||
Transfer TaskConfig `json:"transfer" envPrefix:"TRANSFER_"`
|
Transfer TaskConfig `json:"transfer" envPrefix:"TRANSFER_"`
|
||||||
Upload TaskConfig `json:"upload" envPrefix:"UPLOAD_"`
|
Upload TaskConfig `json:"upload" envPrefix:"UPLOAD_"`
|
||||||
Copy TaskConfig `json:"copy" envPrefix:"COPY_"`
|
Copy TaskConfig `json:"copy" envPrefix:"COPY_"`
|
||||||
Decompress TaskConfig `json:"decompress" envPrefix:"DECOMPRESS_"`
|
Decompress TaskConfig `json:"decompress" envPrefix:"DECOMPRESS_"`
|
||||||
DecompressUpload TaskConfig `json:"decompress_upload" envPrefix:"DECOMPRESS_UPLOAD_"`
|
DecompressUpload TaskConfig `json:"decompress_upload" envPrefix:"DECOMPRESS_UPLOAD_"`
|
||||||
|
AllowRetryCanceled bool `json:"allow_retry_canceled" env:"ALLOW_RETRY_CANCELED"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Cors struct {
|
type Cors struct {
|
||||||
|
@ -182,6 +183,7 @@ func DefaultConfig() *Config {
|
||||||
Workers: 5,
|
Workers: 5,
|
||||||
MaxRetry: 2,
|
MaxRetry: 2,
|
||||||
},
|
},
|
||||||
|
AllowRetryCanceled: false,
|
||||||
},
|
},
|
||||||
Cors: Cors{
|
Cors: Cors{
|
||||||
AllowOrigins: []string{"*"},
|
AllowOrigins: []string{"*"},
|
||||||
|
|
|
@ -50,6 +50,7 @@ func (t *ArchiveDownloadTask) GetStatus() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ArchiveDownloadTask) Run() error {
|
func (t *ArchiveDownloadTask) Run() error {
|
||||||
|
t.ReinitCtx()
|
||||||
t.ClearEndTime()
|
t.ClearEndTime()
|
||||||
t.SetStartTime(time.Now())
|
t.SetStartTime(time.Now())
|
||||||
defer func() { t.SetEndTime(time.Now()) }()
|
defer func() { t.SetEndTime(time.Now()) }()
|
||||||
|
@ -144,6 +145,7 @@ func (t *ArchiveContentUploadTask) GetStatus() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ArchiveContentUploadTask) Run() error {
|
func (t *ArchiveContentUploadTask) Run() error {
|
||||||
|
t.ReinitCtx()
|
||||||
t.ClearEndTime()
|
t.ClearEndTime()
|
||||||
t.SetStartTime(time.Now())
|
t.SetStartTime(time.Now())
|
||||||
defer func() { t.SetEndTime(time.Now()) }()
|
defer func() { t.SetEndTime(time.Now()) }()
|
||||||
|
@ -235,7 +237,9 @@ func (t *ArchiveContentUploadTask) RunWithNextTaskCallback(f func(nextTsk *Archi
|
||||||
|
|
||||||
func (t *ArchiveContentUploadTask) Cancel() {
|
func (t *ArchiveContentUploadTask) Cancel() {
|
||||||
t.TaskExtension.Cancel()
|
t.TaskExtension.Cancel()
|
||||||
t.deleteSrcFile()
|
if !conf.Conf.Tasks.AllowRetryCanceled {
|
||||||
|
t.deleteSrcFile()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ArchiveContentUploadTask) deleteSrcFile() {
|
func (t *ArchiveContentUploadTask) deleteSrcFile() {
|
||||||
|
|
|
@ -39,6 +39,7 @@ func (t *CopyTask) GetStatus() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *CopyTask) Run() error {
|
func (t *CopyTask) Run() error {
|
||||||
|
t.ReinitCtx()
|
||||||
t.ClearEndTime()
|
t.ClearEndTime()
|
||||||
t.SetStartTime(time.Now())
|
t.SetStartTime(time.Now())
|
||||||
defer func() { t.SetEndTime(time.Now()) }()
|
defer func() { t.SetEndTime(time.Now()) }()
|
||||||
|
|
|
@ -28,6 +28,7 @@ type DownloadTask struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *DownloadTask) Run() error {
|
func (t *DownloadTask) Run() error {
|
||||||
|
t.ReinitCtx()
|
||||||
t.ClearEndTime()
|
t.ClearEndTime()
|
||||||
t.SetStartTime(time.Now())
|
t.SetStartTime(time.Now())
|
||||||
defer func() { t.SetEndTime(time.Now()) }()
|
defer func() { t.SetEndTime(time.Now()) }()
|
||||||
|
|
|
@ -32,6 +32,7 @@ type TransferTask struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TransferTask) Run() error {
|
func (t *TransferTask) Run() error {
|
||||||
|
t.ReinitCtx()
|
||||||
t.ClearEndTime()
|
t.ClearEndTime()
|
||||||
t.SetStartTime(time.Now())
|
t.SetStartTime(time.Now())
|
||||||
defer func() { t.SetEndTime(time.Now()) }()
|
defer func() { t.SetEndTime(time.Now()) }()
|
||||||
|
|
|
@ -2,6 +2,7 @@ package task
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/alist-org/alist/v3/internal/conf"
|
||||||
"github.com/alist-org/alist/v3/internal/model"
|
"github.com/alist-org/alist/v3/internal/model"
|
||||||
"github.com/xhofe/tache"
|
"github.com/xhofe/tache"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -66,6 +67,20 @@ func (t *TaskExtension) Ctx() context.Context {
|
||||||
return t.ctx
|
return t.ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *TaskExtension) ReinitCtx() {
|
||||||
|
if !conf.Conf.Tasks.AllowRetryCanceled {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-t.Base.Ctx().Done():
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
t.SetCtx(ctx)
|
||||||
|
t.SetCancelFunc(cancel)
|
||||||
|
t.ctx = nil
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type TaskExtensionInfo interface {
|
type TaskExtensionInfo interface {
|
||||||
tache.TaskWithInfo
|
tache.TaskWithInfo
|
||||||
GetCreator() *model.User
|
GetCreator() *model.User
|
||||||
|
|
Loading…
Reference in New Issue