Ai
0 Star 1 Fork 0

shallot/Go开发工具集

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
loop_clean.go 1.01 KB
一键复制 编辑 原始数据 按行查看 历史
shallot 提交于 2024-08-22 14:58 +08:00 . 移入autohttp库。
package autohttp
import (
"context"
"time"
)
func init() {
go loopClean()
}
// 循环检测待清理项
func loopClean() {
ctx := context.Background()
for {
// 校验数据库回调
if DatabaseCallback == nil {
time.Sleep(1 * time.Second)
continue
}
// 判断是否开启循环
if !AutoCleanEnable {
time.Sleep(1 * time.Minute)
continue
}
// 查询待清理的项目
now := time.Now().Unix()
statusMap := map[uint8]int64{
StatusFailure: AutoCleanFailureTime,
StatusSuccess: AutoCleanSuccessTime,
StatusStopped: AutoCleanStoppedTime,
}
taskIdList := []uint64{}
for status, beforeTime := range statusMap {
if beforeTime == 0 {
continue
}
list, e := DatabaseCallback.TaskToCleanList(ctx, status, now-beforeTime)
if e == nil {
taskIdList = append(taskIdList, list...)
}
}
// 清理项目
for _, taskId := range taskIdList {
_ = DatabaseCallback.DeleteTask(ctx, taskId)
}
// 间隔
time.Sleep(time.Duration(AutoCleanLoopInterval) * time.Second)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/gxsshallot/gotool.git
git@gitee.com:gxsshallot/gotool.git
gxsshallot
gotool
Go开发工具集
d05a69787598

搜索帮助