feat: add scheduled cleanup tasks for temporary files and old scores in works and beatleader/scoresaber services

This commit is contained in:
lixiangwuxian
2025-01-15 10:36:15 +08:00
parent a607e45fe3
commit db8ced6807
3 changed files with 54 additions and 0 deletions

32
handler/works/clean.go Normal file
View File

@@ -0,0 +1,32 @@
package works
import (
"log"
"os"
"time"
"git.lxtend.com/qqbot/util"
)
func init() {
util.AddCycleTask("cleanTmpFolder", 5*time.Minute, 5*time.Minute, cleanTmpFolder)
}
func cleanTmpFolder() {
//递归获取./tmp/目录下的所有文件
files, err := os.ReadDir("./tmp/")
if err != nil {
log.Println(err)
return
}
//删除创建时间超过5分钟的文件
for _, file := range files {
if file.IsDir() {
continue
}
info, _ := file.Info()
if time.Since(info.ModTime()) > 5*time.Minute {
os.RemoveAll(file.Name())
}
}
}