@@ -11,6 +11,7 @@ import (
1111 "time"
1212
1313 "github.com/uber-go/tally/v4"
14+ "github.com/uber/submitqueue/extensions/storage/mysql"
1415 "github.com/uber/submitqueue/gateway/controller"
1516 pb "github.com/uber/submitqueue/gateway/protopb"
1617 "go.uber.org/zap"
@@ -21,12 +22,18 @@ import (
2122// GatewayServer wraps the controller and implements the gRPC service interface
2223type GatewayServer struct {
2324 pb.UnimplementedSubmitQueueGatewayServer
24- controller * controller.PingController
25+ pingController * controller.PingController
26+ landController * controller.LandController
2527}
2628
2729// Ping delegates to the controller
2830func (s * GatewayServer ) Ping (ctx context.Context , req * pb.PingRequest ) (* pb.PingResponse , error ) {
29- return s .controller .Ping (ctx , req )
31+ return s .pingController .Ping (ctx , req )
32+ }
33+
34+ // Land delegates to the controller
35+ func (s * GatewayServer ) Land (ctx context.Context , req * pb.LandRequest ) (* pb.LandResponse , error ) {
36+ return s .landController .Land (ctx , req )
3037}
3138
3239func main () {
@@ -75,21 +82,42 @@ func run() error {
7582 metricsWgDone .Wait ()
7683 }()
7784
85+ // Initialize MySQL storage factory
86+ mysqlDSN := os .Getenv ("MYSQL_DSN" )
87+ if mysqlDSN == "" {
88+ mysqlDSN = "root:root@tcp(localhost:3306)/submitqueue?parseTime=true"
89+ }
90+ storeFactory , err := mysql .NewFactory (mysql.MySQLParameters {
91+ DSN : mysqlDSN ,
92+ MaxOpenConns : 10 ,
93+ MaxIdleConns : 5 ,
94+ ConnMaxLifetime : 5 * time .Minute ,
95+ })
96+ if err != nil {
97+ return fmt .Errorf ("failed to create MySQL storage factory: %w" , err )
98+ }
99+ defer storeFactory .Close ()
100+
78101 // Create gRPC server
79102 grpcServer := grpc .NewServer ()
80103
81- // Create ping controller and wrap it for gRPC
104+ // Create controllers and wrap them for gRPC
82105 pingController := controller .NewPingController (logger , scope )
106+ landController := controller .NewLandController (logger , scope , storeFactory )
83107 gatewayServer := & GatewayServer {
84- controller : pingController ,
108+ pingController : pingController ,
109+ landController : landController ,
85110 }
86111 pb .RegisterSubmitQueueGatewayServer (grpcServer , gatewayServer )
87112
88113 // Register reflection service for debugging with grpcurl
89114 reflection .Register (grpcServer )
90115
91- // Listen on port 8081
92- port := ":8081"
116+ // Listen on configurable port
117+ port := os .Getenv ("PORT" )
118+ if port == "" {
119+ port = ":8081"
120+ }
93121 listener , err := net .Listen ("tcp" , port )
94122 if err != nil {
95123 return fmt .Errorf ("failed to listen on port %s: %w" , port , err )
0 commit comments