Commit 35c9f6c5 authored by Node- 门 忠鑫's avatar Node- 门 忠鑫

# 修改任务执行方式

parent 46dcb996
...@@ -46,9 +46,10 @@ func main() { ...@@ -46,9 +46,10 @@ func main() {
if quartz { if quartz {
log.Println("启动定时任务") log.Println("启动定时任务")
job.AutoEmailPerformInfo() job.AutoEmailPerformInfo()
job.AutoAlarm()
} }
job.AutoAlarm()
go func() { go func() {
http.ListenAndServe("0.0.0.0:"+strconv.Itoa(intPort+1), nil) http.ListenAndServe("0.0.0.0:"+strconv.Itoa(intPort+1), nil)
}() }()
......
...@@ -5,6 +5,8 @@ import ( ...@@ -5,6 +5,8 @@ import (
"git.quantgroup.cn/DevOps/enoch/service/alarm" "git.quantgroup.cn/DevOps/enoch/service/alarm"
"git.quantgroup.cn/DevOps/enoch/service/log" "git.quantgroup.cn/DevOps/enoch/service/log"
"github.com/robfig/cron" "github.com/robfig/cron"
"net"
"os"
"time" "time"
) )
...@@ -12,6 +14,10 @@ import ( ...@@ -12,6 +14,10 @@ import (
报警定时任务,每分钟执行一次 报警定时任务,每分钟执行一次
*/ */
func AutoAlarm() { func AutoAlarm() {
if !checkIp("172.30.12.22"){
return
}
c := cron.New() c := cron.New()
err := c.AddFunc("@every 1m", func() { err := c.AddFunc("@every 1m", func() {
...@@ -24,3 +30,21 @@ func AutoAlarm() { ...@@ -24,3 +30,21 @@ func AutoAlarm() {
c.Start() c.Start()
} }
func checkIp(ip string) bool {
addrs, err := net.InterfaceAddrs()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
for _, address := range addrs {
// 检查ip地址判断是否回环地址
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
logger.Info.Println(ipnet.IP.String())
return ipnet.IP.String() == ip
}
}
}
return false
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment