-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
83 lines (65 loc) · 1.96 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"context"
"github.com/woodhds/vk.service/database"
vkService "github.com/woodhds/vk.service/internal/app/vk-service"
"github.com/woodhds/vk.service/internal/parser"
sweeper "github.com/woodhds/vk.service/internal/sweeper"
"github.com/woodhds/vk.service/internal/vkclient"
"log"
"os"
"os/signal"
"time"
)
var (
token string
version string
count int
port int
connectionString string
)
func main() {
token = os.Getenv("TOKEN")
version = os.Getenv("VERSION")
ParseInt(&count, 50, os.Getenv("COUNT"))
ParseInt(&port, 4222, os.Getenv("PORT"))
connectionString = os.Getenv("CONNECTION_STRING")
if token == "" {
panic("access token required")
}
log.Printf("Used token: %s", token)
log.Printf("Used version: %s", version)
log.Printf("Used count: %d", count)
if connectionString == "" {
connectionString = ":memory?Pooling=True&MaxPoolSize=100&Cache=shared"
}
factory, err := database.NewConnectionFactory(connectionString)
if err != nil {
log.Fatal(err)
return
}
messageQueryService := database.NewMessageQueryService(factory)
usersQueryService := database.NewUserQueryService(factory)
groupsQueryService := database.NewGroupsQueryService(factory)
wallClient, _ := vkclient.NewWallClient(token, version)
messagesService := parser.NewMessageService(wallClient)
conn, _ := factory.GetConnection(context.Background())
database.Migrate(conn)
deleteCtx, cl := context.WithTimeout(context.TODO(), time.Second*15)
defer cl()
sw := sweeper.NewSweeper(factory)
go sw.Run(deleteCtx)
if e := conn.Close(); e != nil {
log.Println(e)
}
app := vkService.NewApp(messageQueryService, usersQueryService, groupsQueryService, factory, messagesService, token, version, count)
app.Initialize()
go app.Run(port)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
defer cancel()
app.Stop(ctx)
os.Exit(0)
}