feat: add scheduled cleanup tasks for temporary files and old scores in works and beatleader/scoresaber services
This commit is contained in:
32
handler/works/clean.go
Normal file
32
handler/works/clean.go
Normal 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())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user