From f2b71be0ee8d117d10c2b1c1c621a85bc54f7098 Mon Sep 17 00:00:00 2001 From: louwenzhi Date: Mon, 15 Mar 2021 11:32:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/db.go | 4 +++- db/corn.go | 37 +++++++++++++++++++++++++++++++++++++ db/db.go | 3 +++ main.go | 5 +++-- 4 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 db/corn.go diff --git a/conf/db.go b/conf/db.go index 2800ce9..be62584 100644 --- a/conf/db.go +++ b/conf/db.go @@ -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", -//} +//} \ No newline at end of file diff --git a/db/corn.go b/db/corn.go new file mode 100644 index 0000000..8b34205 --- /dev/null +++ b/db/corn.go @@ -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 {} +} \ No newline at end of file diff --git a/db/db.go b/db/db.go index 331f82a..f51f532 100644 --- a/db/db.go +++ b/db/db.go @@ -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" ) diff --git a/main.go b/main.go index 34b0264..e5e9db7 100644 --- a/main.go +++ b/main.go @@ -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))