mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-05-11 01:59:40 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d5f214494c |
@@ -8,6 +8,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
Threads int `toml:"threads" mapstructure:"threads"`
|
||||||
|
Workers int `toml:"workers" mapstructure:"workers"`
|
||||||
|
|
||||||
Temp tempConfig `toml:"temp" mapstructure:"temp"`
|
Temp tempConfig `toml:"temp" mapstructure:"temp"`
|
||||||
Log logConfig `toml:"log" mapstructure:"log"`
|
Log logConfig `toml:"log" mapstructure:"log"`
|
||||||
DB dbConfig `toml:"db" mapstructure:"db"`
|
DB dbConfig `toml:"db" mapstructure:"db"`
|
||||||
@@ -72,6 +75,9 @@ func Init() {
|
|||||||
viper.AddConfigPath(".")
|
viper.AddConfigPath(".")
|
||||||
viper.SetConfigType("toml")
|
viper.SetConfigType("toml")
|
||||||
|
|
||||||
|
viper.SetDefault("threads", 3)
|
||||||
|
viper.SetDefault("workers", 3)
|
||||||
|
|
||||||
viper.SetDefault("temp.base_path", "cache/")
|
viper.SetDefault("temp.base_path", "cache/")
|
||||||
viper.SetDefault("temp.cache_ttl", 3600)
|
viper.SetDefault("temp.cache_ttl", 3600)
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ func processPendingTask(task types.Task) error {
|
|||||||
bot.Client.EditMessage(task.ChatID, task.ReplyMessageID, "正在下载文件...")
|
bot.Client.EditMessage(task.ChatID, task.ReplyMessageID, "正在下载文件...")
|
||||||
dest, err := message.Download(&telegram.DownloadOptions{
|
dest, err := message.Download(&telegram.DownloadOptions{
|
||||||
FileName: common.GetCacheFilePath(task.FileName),
|
FileName: common.GetCacheFilePath(task.FileName),
|
||||||
|
Threads: config.Cfg.Threads,
|
||||||
// ProgressCallback: func(totalBytes, downloadedBytes int64) {},
|
// ProgressCallback: func(totalBytes, downloadedBytes int64) {},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -90,8 +91,8 @@ func worker(queue *queue.TaskQueue, semaphore chan struct{}) {
|
|||||||
|
|
||||||
func Run() {
|
func Run() {
|
||||||
logger.L.Info("Start processing tasks...")
|
logger.L.Info("Start processing tasks...")
|
||||||
semaphore := make(chan struct{}, 3)
|
semaphore := make(chan struct{}, config.Cfg.Workers)
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < config.Cfg.Workers; i++ {
|
||||||
go worker(queue.Queue, semaphore)
|
go worker(queue.Queue, semaphore)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user