File size: 3,770 Bytes
7107f0b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package bootstrap

import (
	"github.com/alist-org/alist/v3/internal/conf"
	"github.com/alist-org/alist/v3/internal/db"
	"github.com/alist-org/alist/v3/internal/fs"
	"github.com/alist-org/alist/v3/internal/offline_download/tool"
	"github.com/alist-org/alist/v3/pkg/tache"
)

func InitTaskManager() {
	fs.UploadTaskManager = tache.NewManager[*fs.UploadTask](tache.WithWorks(conf.Conf.Tasks.Upload.Workers), tache.WithMaxRetry(conf.Conf.Tasks.Upload.MaxRetry)) //upload will not support persist
	fs.CopyTaskManager = tache.NewManager[*fs.CopyTask](tache.WithWorks(conf.Conf.Tasks.Copy.Workers), tache.WithPersistFunction(db.GetTaskDataFunc("copy", conf.Conf.Tasks.Copy.TaskPersistant), db.UpdateTaskDataFunc("copy", conf.Conf.Tasks.Copy.TaskPersistant)), tache.WithMaxRetry(conf.Conf.Tasks.Copy.MaxRetry))
	tool.DownloadTaskManager = tache.NewManager[*tool.DownloadTask](tache.WithWorks(conf.Conf.Tasks.Download.Workers), tache.WithPersistFunction(db.GetTaskDataFunc("download", conf.Conf.Tasks.Download.TaskPersistant), db.UpdateTaskDataFunc("download", conf.Conf.Tasks.Download.TaskPersistant)), tache.WithMaxRetry(conf.Conf.Tasks.Download.MaxRetry))
	tool.TransferTaskManager = tache.NewManager[*tool.TransferTask](tache.WithWorks(conf.Conf.Tasks.Transfer.Workers), tache.WithPersistFunction(db.GetTaskDataFunc("transfer", conf.Conf.Tasks.Transfer.TaskPersistant), db.UpdateTaskDataFunc("transfer", conf.Conf.Tasks.Transfer.TaskPersistant)), tache.WithMaxRetry(conf.Conf.Tasks.Transfer.MaxRetry))
	if len(tool.TransferTaskManager.GetAll()) == 0 { //prevent offline downloaded files from being deleted
		CleanTempDir()
	}
}

// func InitTaskManager() {

// 	uploadTaskPersistPath := conf.Conf.Tasks.Upload.PersistPath
// 	copyTaskPersistPath := conf.Conf.Tasks.Copy.PersistPath
// 	downloadTaskPersistPath := conf.Conf.Tasks.Download.PersistPath
// 	transferTaskPersistPath := conf.Conf.Tasks.Transfer.PersistPath
// 	if !utils.Exists(uploadTaskPersistPath) {
// 		log.Infof("传输任务持久化文件")
// 		_, err := utils.CreateNestedFile(uploadTaskPersistPath)
// 		if err != nil {
// 			log.Fatalf("创建上传任务文件失败: %+v", err)
// 		}
// 	}

// 	if !utils.Exists(copyTaskPersistPath) {
// 		log.Infof("复制任务持久化文件")
// 		_, err := utils.CreateNestedFile(copyTaskPersistPath)
// 		if err != nil {
// 			log.Fatalf("创建复制任务文件失败: %+v", err)
// 		}

// 	}

// 	if !utils.Exists(downloadTaskPersistPath) {
// 		log.Infof("下载任务持久化文件")
// 		_, err := utils.CreateNestedFile(downloadTaskPersistPath)
// 		if err != nil {
// 			log.Fatalf("创建下载任务文件失败: %+v", err)
// 		}
// 	}

// 	if !utils.Exists(transferTaskPersistPath) {
// 		log.Infof("传输任务持久化文件")
// 		_, err := utils.CreateNestedFile(transferTaskPersistPath)
// 		if err != nil {
// 			log.Fatalf("创建传输任务文件失败: %+v", err)
// 		}
// 	}

// 	fs.UploadTaskManager = tache.NewManager[*fs.UploadTask](tache.WithWorks(conf.Conf.Tasks.Upload.Workers), tache.WithPersistPath(uploadTaskPersistPath), tache.WithMaxRetry(conf.Conf.Tasks.Upload.MaxRetry))
// 	fs.CopyTaskManager = tache.NewManager[*fs.CopyTask](tache.WithWorks(conf.Conf.Tasks.Copy.Workers), tache.WithPersistPath(copyTaskPersistPath), tache.WithMaxRetry(conf.Conf.Tasks.Copy.MaxRetry))
// 	tool.DownloadTaskManager = tache.NewManager[*tool.DownloadTask](tache.WithWorks(conf.Conf.Tasks.Download.Workers), tache.WithPersistPath(downloadTaskPersistPath), tache.WithMaxRetry(conf.Conf.Tasks.Download.MaxRetry))
// 	tool.TransferTaskManager = tache.NewManager[*tool.TransferTask](tache.WithWorks(conf.Conf.Tasks.Transfer.Workers), tache.WithPersistPath(transferTaskPersistPath), tache.WithMaxRetry(conf.Conf.Tasks.Transfer.MaxRetry))
// }