Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
enoch
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DevOps
enoch
Commits
35c9f6c5
Commit
35c9f6c5
authored
Mar 27, 2019
by
Node- 门 忠鑫
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
# 修改任务执行方式
parent
46dcb996
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
1 deletion
+26
-1
main.go
main.go
+2
-1
alarm.go
service/job/alarm.go
+24
-0
No files found.
main.go
View file @
35c9f6c5
...
@@ -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
)
}()
}()
...
...
service/job/alarm.go
View file @
35c9f6c5
...
@@ -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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment