-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
120 lines (106 loc) · 2.55 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package main
import (
"context"
"github.com/leaq-ru/exporter/cached_export"
"github.com/leaq-ru/exporter/call"
"github.com/leaq-ru/exporter/config"
"github.com/leaq-ru/exporter/consumer"
"github.com/leaq-ru/exporter/exporter_bucket"
"github.com/leaq-ru/exporter/exporterimpl"
"github.com/leaq-ru/exporter/file"
"github.com/leaq-ru/exporter/logger"
"github.com/leaq-ru/exporter/minio"
"github.com/leaq-ru/exporter/mongo"
"github.com/leaq-ru/exporter/processing_export"
"github.com/leaq-ru/exporter/row"
"github.com/leaq-ru/exporter/stan"
graceful "github.com/leaq-ru/lib-graceful"
"github.com/leaq-ru/proto/codegen/go/exporter"
"google.golang.org/grpc"
"google.golang.org/grpc/health"
"google.golang.org/grpc/health/grpc_health_v1"
"log"
"net"
"strings"
"sync"
)
func main() {
ctx := context.Background()
cfg, err := config.NewConfig()
if err != nil {
log.Fatal(err)
}
logg, err := logger.NewLogger(cfg.LogLevel)
if err != nil {
log.Fatal(err)
}
companyClient, cityClient, categoryClient, err := call.NewClients(cfg.Service.Parser)
logg.Must(err)
stanConn, err := stan.NewConn(cfg.ServiceName, cfg.STAN.ClusterID, cfg.NATS.URL)
logg.Must(err)
db, err := mongo.NewConn(ctx, cfg.ServiceName, cfg.MongoDB.URL)
logg.Must(err)
minioClient, err := minio.NewClient(
ctx,
cfg.S3.AccessKeyID,
cfg.S3.SecretAccessKey,
cfg.S3.Endpoint,
cfg.S3.Secure,
)
logg.Must(err)
exporterBucket, err := exporter_bucket.NewExporterBucket(
ctx,
minioClient,
cfg.S3.ExporterBucketName,
cfg.S3.Region,
)
logg.Must(err)
fileModel := file.NewModel(db)
cachedExportModel := cached_export.NewModel(db)
processingExportModel := processing_export.NewModel(db)
rowModel := row.NewModel(db)
cons := consumer.NewConsumer(
logg.ZL,
stanConn,
exporterBucket,
companyClient,
fileModel,
rowModel,
cachedExportModel,
processingExportModel,
cfg.ServiceName,
)
logg.Must(cons.Subscribe())
srv := grpc.NewServer()
grpc_health_v1.RegisterHealthServer(srv, health.NewServer())
exporter.RegisterExporterServer(srv, exporterimpl.NewServer(
logg.ZL,
exporterBucket,
companyClient,
cityClient,
categoryClient,
fileModel,
cachedExportModel,
cons.ProcessAsync,
))
lis, err := net.Listen("tcp", strings.Join([]string{
"0.0.0.0",
cfg.Grpc.Port,
}, ":"))
logg.Must(err)
var wg sync.WaitGroup
wg.Add(3)
go func() {
defer wg.Done()
graceful.HandleSignals(srv.GracefulStop, cons.GracefulStop)
}()
go func() {
defer wg.Done()
logg.Must(srv.Serve(lis))
}()
go func() {
defer wg.Done()
logg.Must(cons.Serve())
}()
wg.Wait()
}