-
Notifications
You must be signed in to change notification settings - Fork 0
/
jobs.go
45 lines (37 loc) · 1.01 KB
/
jobs.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
package jobs
import (
"context"
"net/http"
"os"
"sync"
"github.com/simster7/notion-automation/client"
"github.com/simster7/notion-automation/common"
"github.com/simster7/notion-automation/tasks"
)
var notion = client.NewClient(os.Getenv("NOTION_TOKEN"))
func Nightly(_ http.ResponseWriter, _ *http.Request) {
common.SetTime()
common.InitLogger("nightly")
log := common.GetLogger()
log.Infof("starting nightly job...")
ctx := context.Background()
taskQueue := []tasks.Task{tasks.GetCreateJournalEntry(), tasks.GetDoOnToday(), tasks.GetRepeatTasks()}
var wg sync.WaitGroup
wg.Add(len(taskQueue))
for _, task := range taskQueue {
task := task
log.Infof("starting task '%s'", task.GetName())
go func() {
defer wg.Done()
err := task.Do(ctx, notion)
if err != nil {
log.Errorf("error completing task '%s': %s", task.GetName(), err)
}
}()
}
wg.Wait()
err := tasks.GetAddCalendarEvents().Do(ctx, notion)
if err != nil {
log.Errorf("error completing task 'AddCalendarEvents': %s", err)
}
}