@@ -3,6 +3,7 @@ package main
33import (
44 "common"
55 "context"
6+ "flag"
67 pb "gen/proto/services/property_svc/v1"
78 "hwdb"
89 "hwes/eventstoredb"
@@ -31,27 +32,40 @@ func main() {
3132 ctx , cancel := context .WithCancel (context .Background ())
3233 common .Setup (ServiceName , Version , common .WithAuth ())
3334
35+ replayMode := flag .Bool ("replay" , false , "" )
36+ flag .Parse ()
37+ log .Debug ().Bool ("replayMode" , * replayMode ).Msg ("flags" )
38+
3439 closeDBPool := hwdb .SetupDatabaseFromEnv (ctx )
3540 defer closeDBPool ()
3641
3742 eventStore := eventstoredb .SetupEventStoreByEnv ()
3843 aggregateStore := eventstoredb .NewAggregateStore (eventStore )
3944
40- propertyHandlers := ph .NewPropertyHandlers (aggregateStore )
41- propertySetHandlers := psh .NewPropertySetHandlers (aggregateStore )
42- propertyViewHandlers := pvih .NewPropertyViewHandlers (aggregateStore )
43- propertyValueHandlers := pvh .NewPropertyValueHandlers (aggregateStore )
45+ propertyPostgresProjection := property_postgres_projection .
46+ NewProjection (eventStore , ServiceName , hwdb .GetDB ())
47+
48+ propertyValuePostgresProjection := property_value_postgres_projection .
49+ NewProjection (eventStore , ServiceName , hwdb .GetDB ())
50+
51+ if * replayMode {
52+ if err := replay (ctx , eventStore ); err != nil {
53+ log .Err (err ).Msg ("error during replay" )
54+ cancel ()
55+ }
56+ // TODO: Find a more generic approach to run common.Shutdown()
57+ common .Shutdown ()
58+ return
59+ }
4460
4561 go func () {
46- propertyPostgresProjection := property_postgres_projection .NewProjection (eventStore , ServiceName )
4762 if err := propertyPostgresProjection .Subscribe (ctx ); err != nil {
4863 log .Err (err ).Msg ("error during property-postgres projection subscription" )
4964 cancel ()
5065 }
5166 }()
5267
5368 go func () {
54- propertyValuePostgresProjection := property_value_postgres_projection .NewProjection (eventStore , ServiceName )
5569 if err := propertyValuePostgresProjection .Subscribe (ctx ); err != nil {
5670 log .Err (err ).Msg ("error during propertyValue-postgres projection subscription" )
5771 cancel ()
@@ -66,6 +80,11 @@ func main() {
6680 }
6781 }()
6882
83+ propertyHandlers := ph .NewPropertyHandlers (aggregateStore )
84+ propertySetHandlers := psh .NewPropertySetHandlers (aggregateStore )
85+ propertyViewHandlers := pvih .NewPropertyViewHandlers (aggregateStore )
86+ propertyValueHandlers := pvh .NewPropertyValueHandlers (aggregateStore )
87+
6988 common .StartNewGRPCServer (context .Background (), common .ResolveAddrFromEnv (), func (server * daprd.Server ) {
7089 grpcServer := server .GrpcServer ()
7190
0 commit comments