-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_status.go
58 lines (51 loc) · 1.47 KB
/
check_status.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
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
"strconv"
/*
* env
*/
"log"
"os"
"time"
bot "github.com/MinFengLin/check_service_status/bot"
service "github.com/MinFengLin/check_service_status/service"
"github.com/joho/godotenv"
"github.com/robfig/cron/v3"
)
var (
service_data service.Services_slice
)
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
chatID, _ := strconv.ParseInt(os.Getenv("chatID"), 10, 64)
yourToken := os.Getenv("yourToken")
Env_Time, _ := strconv.ParseInt(os.Getenv("Timer_Minutes"), 10, 64)
crontab_time := os.Getenv("Crontime")
if len(crontab_time) > 0 {
fmt.Printf("chatID: %d, yourToken: %s, Use crontab: %s \n", chatID, yourToken, crontab_time)
c := cron.New()
_, _ = c.AddFunc(crontab_time, func() {
failed_data := service.Check_service_status()
bot.Telegram_bot_run(&chatID, &yourToken, failed_data)
})
failed_data := service.Check_service_status()
bot.Telegram_bot_run(&chatID, &yourToken, failed_data)
go bot.Telegram_reply_run(&chatID, &yourToken)
c.Start()
select {}
} else {
fmt.Printf("chatID: %d, yourToken: %s, How often to run: %d (Minutes)\n", chatID, yourToken, Env_Time)
tChannel := time.NewTimer(time.Duration(Env_Time) * time.Minute)
go bot.Telegram_reply_run(&chatID, &yourToken)
for {
failed_data := service.Check_service_status()
bot.Telegram_bot_run(&chatID, &yourToken, failed_data)
tChannel.Reset(time.Duration(Env_Time) * time.Minute)
<-tChannel.C
}
}
}