forked from open-falcon/falcon-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sms_sender.go
45 lines (39 loc) · 940 Bytes
/
sms_sender.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package cron
import (
log "github.com/Sirupsen/logrus"
"github.com/open-falcon/falcon-plus/modules/alarm/g"
"github.com/open-falcon/falcon-plus/modules/alarm/model"
"github.com/open-falcon/falcon-plus/modules/alarm/redi"
"github.com/toolkits/net/httplib"
"time"
)
func ConsumeSms() {
for {
L := redi.PopAllSms()
if len(L) == 0 {
time.Sleep(time.Millisecond * 200)
continue
}
SendSmsList(L)
}
}
func SendSmsList(L []*model.Sms) {
for _, sms := range L {
SmsWorkerChan <- 1
go SendSms(sms)
}
}
func SendSms(sms *model.Sms) {
defer func() {
<-SmsWorkerChan
}()
url := g.Config().Api.Sms
r := httplib.Post(url).SetTimeout(5*time.Second, 30*time.Second)
r.Param("tos", sms.Tos)
r.Param("content", sms.Content)
resp, err := r.String()
if err != nil {
log.Errorf("send sms fail, tos:%s, cotent:%s, error:%v", sms.Tos, sms.Content, err)
}
log.Debugf("send sms:%v, resp:%v, url:%s", sms, resp, url)
}