File tree 6 files changed +31
-7
lines changed 6 files changed +31
-7
lines changed Original file line number Diff line number Diff line change @@ -53,12 +53,13 @@ type TaskConfig struct {
53
53
}
54
54
55
55
type TasksConfig struct {
56
- Download TaskConfig `json:"download" envPrefix:"DOWNLOAD_"`
57
- Transfer TaskConfig `json:"transfer" envPrefix:"TRANSFER_"`
58
- Upload TaskConfig `json:"upload" envPrefix:"UPLOAD_"`
59
- Copy TaskConfig `json:"copy" envPrefix:"COPY_"`
60
- Decompress TaskConfig `json:"decompress" envPrefix:"DECOMPRESS_"`
61
- DecompressUpload TaskConfig `json:"decompress_upload" envPrefix:"DECOMPRESS_UPLOAD_"`
56
+ Download TaskConfig `json:"download" envPrefix:"DOWNLOAD_"`
57
+ Transfer TaskConfig `json:"transfer" envPrefix:"TRANSFER_"`
58
+ Upload TaskConfig `json:"upload" envPrefix:"UPLOAD_"`
59
+ Copy TaskConfig `json:"copy" envPrefix:"COPY_"`
60
+ Decompress TaskConfig `json:"decompress" envPrefix:"DECOMPRESS_"`
61
+ DecompressUpload TaskConfig `json:"decompress_upload" envPrefix:"DECOMPRESS_UPLOAD_"`
62
+ AllowRetryCanceled bool `json:"allow_retry_canceled" env:"ALLOW_RETRY_CANCELED"`
62
63
}
63
64
64
65
type Cors struct {
@@ -182,6 +183,7 @@ func DefaultConfig() *Config {
182
183
Workers : 5 ,
183
184
MaxRetry : 2 ,
184
185
},
186
+ AllowRetryCanceled : false ,
185
187
},
186
188
Cors : Cors {
187
189
AllowOrigins : []string {"*" },
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ func (t *ArchiveDownloadTask) GetStatus() string {
50
50
}
51
51
52
52
func (t * ArchiveDownloadTask ) Run () error {
53
+ t .ReinitCtx ()
53
54
t .ClearEndTime ()
54
55
t .SetStartTime (time .Now ())
55
56
defer func () { t .SetEndTime (time .Now ()) }()
@@ -144,6 +145,7 @@ func (t *ArchiveContentUploadTask) GetStatus() string {
144
145
}
145
146
146
147
func (t * ArchiveContentUploadTask ) Run () error {
148
+ t .ReinitCtx ()
147
149
t .ClearEndTime ()
148
150
t .SetStartTime (time .Now ())
149
151
defer func () { t .SetEndTime (time .Now ()) }()
@@ -235,7 +237,9 @@ func (t *ArchiveContentUploadTask) RunWithNextTaskCallback(f func(nextTsk *Archi
235
237
236
238
func (t * ArchiveContentUploadTask ) Cancel () {
237
239
t .TaskExtension .Cancel ()
238
- t .deleteSrcFile ()
240
+ if ! conf .Conf .Tasks .AllowRetryCanceled {
241
+ t .deleteSrcFile ()
242
+ }
239
243
}
240
244
241
245
func (t * ArchiveContentUploadTask ) deleteSrcFile () {
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ func (t *CopyTask) GetStatus() string {
39
39
}
40
40
41
41
func (t * CopyTask ) Run () error {
42
+ t .ReinitCtx ()
42
43
t .ClearEndTime ()
43
44
t .SetStartTime (time .Now ())
44
45
defer func () { t .SetEndTime (time .Now ()) }()
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ type DownloadTask struct {
28
28
}
29
29
30
30
func (t * DownloadTask ) Run () error {
31
+ t .ReinitCtx ()
31
32
t .ClearEndTime ()
32
33
t .SetStartTime (time .Now ())
33
34
defer func () { t .SetEndTime (time .Now ()) }()
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ type TransferTask struct {
32
32
}
33
33
34
34
func (t * TransferTask ) Run () error {
35
+ t .ReinitCtx ()
35
36
t .ClearEndTime ()
36
37
t .SetStartTime (time .Now ())
37
38
defer func () { t .SetEndTime (time .Now ()) }()
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package task
2
2
3
3
import (
4
4
"context"
5
+ "github.com/alist-org/alist/v3/internal/conf"
5
6
"github.com/alist-org/alist/v3/internal/model"
6
7
"github.com/xhofe/tache"
7
8
"sync"
@@ -66,6 +67,20 @@ func (t *TaskExtension) Ctx() context.Context {
66
67
return t .ctx
67
68
}
68
69
70
+ func (t * TaskExtension ) ReinitCtx () {
71
+ if ! conf .Conf .Tasks .AllowRetryCanceled {
72
+ return
73
+ }
74
+ select {
75
+ case <- t .Base .Ctx ().Done ():
76
+ ctx , cancel := context .WithCancel (context .Background ())
77
+ t .SetCtx (ctx )
78
+ t .SetCancelFunc (cancel )
79
+ t .ctx = nil
80
+ default :
81
+ }
82
+ }
83
+
69
84
type TaskExtensionInfo interface {
70
85
tache.TaskWithInfo
71
86
GetCreator () * model.User
You can’t perform that action at this time.
0 commit comments