Browse Source

提交

pull/2/head
娄文智 4 years ago
parent
commit
f2b71be0ee
4 changed files with 46 additions and 3 deletions
  1. +3
    -1
      conf/db.go
  2. +37
    -0
      db/corn.go
  3. +3
    -0
      db/db.go
  4. +3
    -2
      main.go

+ 3
- 1
conf/db.go View File

@ -8,6 +8,7 @@ type DbConf struct {
User string
Pwd string
DbName string
BackUp string
}
//线上服务器配置
@ -17,6 +18,7 @@ var MasterDbConfig DbConf = DbConf{
User: "root",
Pwd: "Leit2020",
DbName: "lappserver",
BackUp: "C:\\lappServer\\dblog",
}
//测试服务器配置
@ -26,4 +28,4 @@ var MasterDbConfig DbConf = DbConf{
// User: "root",
// Pwd: "Leit2020",
// DbName: "wyserver8094",
//}
//}

+ 37
- 0
db/corn.go View File

@ -0,0 +1,37 @@
// Copyright (c) Shenyang Leading Edge Intelligent Technology Co., Ltd. All rights reserved.
package db
import (
cron "github.com/robfig/cron/v3"
)
/******************************************************************************
*
* @Function Name :
*-----------------------------------------------------------------------------
*
* @Description : 定时任务
*
* @Function Parameters:
*
* @Return Value :
*
* @Author : Lou Wenzhi
*
* @Date : 2021/3/8 18:00
*
******************************************************************************/
func CornTime() {
crontab := cron.New()
task := func() {
BackUp()
}
// 添加定时任务, * * * * * 是 crontab,表示每分钟执行一次
//crontab.AddFunc("*/1 * * * *", task)
crontab.AddFunc("@midnight", task)
// 启动定时器
crontab.Start()
// 定时任务是另起协程执行的,这里使用 select 简答阻塞.实际开发中需要
// 根据实际情况进行控制
select {}
}

+ 3
- 0
db/db.go View File

@ -8,7 +8,10 @@ import (
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"lapp_-wy/conf"
"lapp_-wy/utils"
"lapp_-wy/web/middleware/glog"
"log"
"path/filepath"
"sync"
"time"
)


+ 3
- 2
main.go View File

@ -5,6 +5,7 @@ import (
"fmt"
"github.com/kardianos/service"
"github.com/kataras/iris"
"lapp_-wy/db"
"lapp_-wy/inits/parse"
"lapp_-wy/utils"
"lapp_-wy/web/middleware/glog"
@ -17,7 +18,6 @@ import (
//基于windows系统服务器,安装成服务
type program struct{}
func (p *program) Start(s service.Service) error {
@ -103,7 +103,8 @@ func imain() {
app.RegisterView(iris.HTML(savePath, ".html"))
// 设置静态资源
app.StaticWeb("/public", savePath)
//数据备份
go db.CornTime()
//启动监听端口
app.Run(iris.Addr(":22000"), iris.WithConfiguration(parse.C))
//app.Run(iris.Addr(":8092"), iris.WithConfiguration(parse.C))


Loading…
Cancel
Save