1 Star 0 Fork 51

buyaopa / 柚备

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 1.70 KB
一键复制 编辑 原始数据 按行查看 历史
countpoison 提交于 2020-08-18 15:12 . no commit message
package main
import (
"errors"
"fmt"
"time"
md "gitee.com/countpoison/youbei/models"
_ "gitee.com/countpoison/youbei/routers"
"gitee.com/countpoison/youbei/utils"
db "gitee.com/countpoison/youbei/utils/database"
"gitee.com/countpoison/youbei/utils/jobs"
"github.com/astaxie/beego"
"github.com/astaxie/beego/toolbox"
)
func main() {
md.Init("data")
ts, err := md.All()
if err != nil {
panic(err)
}
if len(ts) > 0 {
for _, ob := range ts {
if ob.DBType == "mysql" {
err = db.MysqlConnectTest(ob.Host, ob.Port, ob.DBname, ob.User, ob.Password, ob.Char)
} else if ob.DBType == "mssql" {
err = db.MssqlConnectTest(ob.Host, ob.DBname, ob.User, ob.Password)
} else if ob.DBType == "sqlite" {
err = db.SqliteConnectTest(ob.DBpath)
} else if ob.DBType == "file" {
bol, errs := utils.PathExists(ob.DBpath)
err = errs
if !bol {
err = errors.New(ob.DBpath + " not found")
}
} else {
fmt.Println("dbtype not found")
}
if err == nil && ob.Crontab != "" {
toolbox.AddTask(ob.ID, toolbox.NewTask(ob.ID, ob.Crontab, jobs.Jobs(ob.ID)))
}
}
}
sshtasks := []md.SshTask{}
if err := md.Localdb().Find(&sshtasks); err != nil {
panic(err.Error())
}
for _, sshtask := range sshtasks {
toolbox.AddTask(sshtask.ID, toolbox.NewTask(sshtask.ID, sshtask.Crontab, jobs.SshJobs(sshtask.ID)))
}
toolbox.AddTask("expireDelete", toolbox.NewTask("expireDelete", "0/10 * * * * *", func() error {
tasks, err := md.All()
if err != nil {
return err
}
for _, v := range tasks {
if v.Expire != 0 {
now := time.Now().Unix()
day := int64(v.Expire * 86400)
jobs.ExpireDelete(v.ID, now-day)
}
}
return nil
}))
toolbox.StartTask()
beego.Run()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/haoyj/youbei.git
git@gitee.com:haoyj/youbei.git
haoyj
youbei
柚备
master

搜索帮助

Bbcd6f05 5694891 0cc6727d 5694891