gocron/modules/notify/notify.go

33 lines
479 B
Go
Raw Normal View History

2017-04-28 03:54:46 +00:00
package notify
import (
"time"
)
var SlackUrl string
type Message map[string]interface{}
2017-04-28 06:55:24 +00:00
2017-04-28 03:54:46 +00:00
type Notifiable interface {
2017-04-28 06:55:24 +00:00
Send(msg Message)
2017-04-28 03:54:46 +00:00
}
var queue chan Message = make(chan Message, 100)
func init() {
go run()
}
// 把消息推入队列
func Push(msg Message) {
queue <- msg
}
func run() {
slack := new(Slack)
for msg := range queue {
2017-04-28 06:55:24 +00:00
// 根据任务配置发送通知
2017-04-28 03:54:46 +00:00
go slack.Send(msg)
time.Sleep(1 * time.Second)
}
}