-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduler.go
54 lines (47 loc) · 1.1 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"context"
"log"
"os"
"time"
"github.com/arihantdaga/kiotsundaython/database"
"github.com/arihantdaga/kiotsundaython/runner"
"github.com/joho/godotenv"
)
func main() {
println("Starting scheduler...")
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
DBStr := os.Getenv("DB_CONNECTION")
dbClient, err := database.DB(DBStr)
if err != nil {
log.Fatal(err)
}
defer func() {
if err = dbClient.Disconnect(context.TODO()); err != nil {
panic(err)
}
}()
time.Sleep(time.Second * 3)
if err := dbClient.Ping(context.TODO(), nil); err != nil {
log.Println("Error pinging database. Exiting...")
panic(err)
} else {
log.Println("Successfully pinged database")
}
// Runner
runnerDie := make(chan string, 1)
runner := runner.JobRunnerImpl{}
runner.New(dbClient)
go runner.Run(runnerDie)
// time.Sleep(time.Second * 10)
// API Setup
// TODO:I think this is not the right way - I think New should return something like a pointer to APIServerImpl.
api := APiServerImpl{}
api.New(dbClient)
api.HandleRoutes()
api.Start()
print(<-runnerDie)
}