-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (44 loc) · 1.1 KB
/
main.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
package main
import (
"os"
"time"
"github.com/charmbracelet/log"
"github.com/nesvoboda/slotwatch/notify"
"github.com/nesvoboda/slotwatch/slot"
)
func main() {
projectName := os.Getenv("PROJECT_NAME")
teamId := os.Getenv("TEAM_ID")
cookie := os.Getenv("COOKIE")
if projectName == "" {
log.Fatal("PROJECT_NAME is not set")
}
if teamId == "" {
log.Fatal("TEAM_ID is not set")
}
if cookie == "" {
log.Fatal("COOKIE is not set")
}
notify.Init()
log.SetLevel(log.DebugLevel)
log.Info("Starting watcher")
notify.StartMessage(projectName, teamId)
watch(projectName, teamId, cookie)
}
// a global cache to store the slots
var cache = make(map[string]slot.Slot)
func watch(projectName string, teamId string, cookie string) {
for {
slots := slot.GetAll(projectName, teamId, cookie)
log.Debug("Got slots: ", slots)
for _, slot := range slots {
if _, ok := cache[slot.Id]; !ok {
cache[slot.Id] = slot
notify.Send(slot)
log.Debug("New slot: ", slot.Id, " ", slot.Start)
}
log.Debug("Slot already in cache: ", slot.Id, " ", slot.Start)
}
time.Sleep(time.Second * 3)
}
}