-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscheduler.go
39 lines (31 loc) · 974 Bytes
/
scheduler.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
package main
import (
"fmt"
"github.com/robfig/cron/v3"
)
func sendArticle() {
// Create new scheduler
c := cron.New() // To use seconds, add: `cron.WithSeconds()` inside New() func
fmt.Printf("Scheduler is starting...")
var setupData SetupData
deserializeData(CONFIG_SOURCE, &setupData)
timeConverter, err := convertTimeToCron(setupData.HourToSend)
if err != nil {
fmt.Println(err)
}
cronExpression := fmt.Sprintf("0 %s * * *", timeConverter)
emptyID := ""
// Add the task to be executed every day
c.AddFunc(cronExpression, func() { // To test every x seconds, use: "*/15 * * * * *"
var setupData SetupData
deserializeData(CONFIG_SOURCE, &setupData)
if setupData.Mode == "channel_mode" {
sendToChannel(setupData.SelectedChannelID, searchArticle(emptyID, &setupData.MediumCategory))
} else {
sendDM(setupData.UserID, searchArticle(emptyID, &setupData.MediumCategory))
}
})
c.Start()
// Prevents the func from stopping
select {}
}