-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
65 lines (59 loc) · 1.6 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
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"fmt"
"github.com/gregdel/pushover"
"github.com/jasonlvhit/gocron"
"log"
)
func main() {
// check if all env variables are present
pretalxURL, err := getEnvStr("PRETALX_URL")
if err != nil {
log.Fatal(err)
panic(err)
}
pretalxAuthToken, err := getEnvStr("PRETALX_AUTH")
if err != nil {
log.Fatal(err)
panic(err)
}
pushoverAPIToken, err := getEnvStr("PUSHOVER_API_TOKEN")
if err != nil {
log.Fatal(err)
panic(err)
}
pushoverUserToken, err := getEnvStr("PUSHOVER_USER_TOKEN")
if err != nil {
log.Fatal(err)
panic(err)
}
pushOverApp := pushover.New(pushoverAPIToken)
minutes, err := getEnvInt("MINUTES")
if err != nil {
log.Print("MINUTES not set, using default of 15 minutes")
minutes = 15
}
onlyNew, err := getEnvBool("ONLY_NEW")
if err != nil {
log.Print("ONLY_NEW not set, notifying on all changes")
onlyNew = false
}
log.Print("initially downloading submissions...")
submissions, err := getSubmissions(pretalxURL, pretalxAuthToken)
if err != nil {
log.Fatal(err)
panic(err)
}
var knownSubmissions = make(map[string]submission)
// initially download the submission (without notifying)
for _, submission := range submissions.Results {
knownSubmissions[submission.Code] = submission
}
// schedule checkSubmissions every x minutes
log.Print(fmt.Sprintf("scheduling submission check every %d minutes", minutes))
// simply ignore failures and reschedule the task
for ;; {
gocron.Every(uint64(minutes)).Minutes().Do(checkSubmissions, knownSubmissions, onlyNew, pretalxURL, pretalxAuthToken, pushOverApp, pushoverUserToken)
<-gocron.Start()
}
}