From 04b7bb7d8c118054fdf124f8f8c28483a7286c76 Mon Sep 17 00:00:00 2001 From: Toby Yan Date: Fri, 21 Jun 2019 09:46:31 +0800 Subject: [PATCH] every minute should notify once Signed-off-by: Toby Yan --- app/console/commands/alert.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/console/commands/alert.go b/app/console/commands/alert.go index 2f4693d..344e4f8 100644 --- a/app/console/commands/alert.go +++ b/app/console/commands/alert.go @@ -136,6 +136,11 @@ func (hw *Alert) Handler(arg *cmd.Arg) error { } func (hw *Alert) notify(direction Direction, nowData *TickData) { + // every minute should notify once + if cache.Has(hw.cacheKey(zone.Now())+"_notified"){ + return + } + diff, _ := strconv.ParseFloat(hw.difference, 64) dataStr, _ := json.Marshal(nowData) @@ -150,6 +155,8 @@ func (hw *Alert) notify(direction Direction, nowData *TickData) { "message": string(dataStr), }, }).Biu() + + cache.Put(hw.cacheKey(zone.Now())+"_notified", true, zone.Now().Add(hw.duration+5*zone.Minute)) } func nowData(resp *response) *TickData {