@@ -2,32 +2,32 @@ package service
22
33import (
44 "common"
5- "context"
65 "flag"
6+
77 pb "gen/services/property_svc/v1"
8+ daprd "github.com/dapr/go-sdk/service/grpc"
89 "github.com/rs/zerolog/log"
910 "hwdb"
1011 "hwes/eventstoredb"
12+ "hwes/eventstoredb/projections"
13+
1114 propertySet "property-svc/internal/property-set/api"
15+ psh "property-svc/internal/property-set/handlers"
1216 propertyValue "property-svc/internal/property-value/api"
17+ pvh "property-svc/internal/property-value/handlers"
1318 "property-svc/internal/property-value/projections/property_value_postgres_projection"
1419 propertyViews "property-svc/internal/property-view/api"
20+ pvih "property-svc/internal/property-view/handlers"
1521 "property-svc/internal/property-view/projections/property_rules_postgres"
1622 property "property-svc/internal/property/api"
17- "property-svc/internal/property/projections/property_postgres_projection"
18-
19- daprd "github.com/dapr/go-sdk/service/grpc"
20- psh "property-svc/internal/property-set/handlers"
21- pvh "property-svc/internal/property-value/handlers"
22- pvih "property-svc/internal/property-view/handlers"
2323 ph "property-svc/internal/property/handlers"
24+ "property-svc/internal/property/projections/property_postgres_projection"
2425)
2526
2627const ServiceName = "property-svc"
2728
2829func Main (version string , ready func ()) {
29- ctx , cancel := context .WithCancel (context .Background ())
30- common .Setup (ServiceName , version , common .WithAuth ())
30+ ctx := common .Setup (ServiceName , version , common .WithAuth ())
3131
3232 replayMode := flag .Bool ("replay" , false , "" )
3333 flag .Parse ()
@@ -39,44 +39,22 @@ func Main(version string, ready func()) {
3939 eventStore := eventstoredb .SetupEventStoreByEnv ()
4040 aggregateStore := eventstoredb .NewAggregateStore (eventStore )
4141
42- propertyPostgresProjection := property_postgres_projection .
43- NewProjection (eventStore , ServiceName , hwdb .GetDB ())
44-
45- propertyValuePostgresProjection := property_value_postgres_projection .
46- NewProjection (eventStore , ServiceName , hwdb .GetDB ())
47-
4842 if * replayMode {
49- if err := replay (ctx , eventStore ); err != nil {
43+ err := replay (ctx , eventStore )
44+ if err != nil {
5045 log .Err (err ).Msg ("error during replay" )
51- cancel ()
5246 }
53- // TODO: Find a more generic approach to run common.Shutdown()
54- common .Shutdown ()
55- cancel ()
47+ common .Shutdown (err )
5648 return
5749 }
5850
59- go func () {
60- if err := propertyPostgresProjection .Subscribe (ctx ); err != nil {
61- log .Err (err ).Msg ("error during property-postgres projection subscription" )
62- cancel ()
63- }
64- }()
65-
66- go func () {
67- if err := propertyValuePostgresProjection .Subscribe (ctx ); err != nil {
68- log .Err (err ).Msg ("error during propertyValue-postgres projection subscription" )
69- cancel ()
70- }
71- }()
72-
73- go func () {
74- taskViewsPostgresProjection := property_rules_postgres .NewProjection (eventStore , ServiceName )
75- if err := taskViewsPostgresProjection .Subscribe (ctx ); err != nil {
76- log .Err (err ).Msg ("error during taskViewsPostgresProjection subscription" )
77- cancel ()
78- }
79- }()
51+ go projections .StartProjections (
52+ ctx ,
53+ common .Shutdown ,
54+ property_postgres_projection .NewProjection (eventStore , ServiceName , hwdb .GetDB ()),
55+ property_value_postgres_projection .NewProjection (eventStore , ServiceName , hwdb .GetDB ()),
56+ property_rules_postgres .NewProjection (eventStore , ServiceName ),
57+ )
8058
8159 propertyHandlers := ph .NewPropertyHandlers (aggregateStore )
8260 propertySetHandlers := psh .NewPropertySetHandlers (aggregateStore )
@@ -96,5 +74,5 @@ func Main(version string, ready func()) {
9674 }
9775 })
9876
99- cancel ( )
77+ common . Shutdown ( nil )
10078}
0 commit comments