refactor
This commit is contained in:
+12
-1
@@ -24,6 +24,11 @@ import (
|
||||
type Server struct {
|
||||
inventoryService *inventory.RedisInventoryService
|
||||
reservationService *inventory.RedisCartReservationService
|
||||
|
||||
// rdb + conn back the batch write path (pipelined UpdateInventory + level
|
||||
// crossing). conn is nil when RABBIT_HOST is unset; emit is then skipped.
|
||||
rdb *redis.Client
|
||||
conn *rabbit.Conn
|
||||
}
|
||||
|
||||
func (srv *Server) livezHandler(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -124,13 +129,16 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
server := &Server{inventoryService: s, reservationService: r}
|
||||
server := &Server{inventoryService: s, reservationService: r, rdb: rdb}
|
||||
|
||||
// Set up HTTP routes
|
||||
http.HandleFunc("/livez", server.livezHandler)
|
||||
http.HandleFunc("/readyz", server.readyzHandler)
|
||||
http.HandleFunc("/inventory/{sku}/{locationId}", server.getInventoryHandler)
|
||||
http.HandleFunc("/reservations/{sku}/{locationId}", server.getReservationHandler)
|
||||
http.HandleFunc("POST /reservations", server.reserveInventoryHandler)
|
||||
http.HandleFunc("POST /reservations/release", server.releaseReservationHandler)
|
||||
http.HandleFunc("POST /inventory/batch", server.batchInventoryHandler)
|
||||
|
||||
stockhandler := &StockHandler{
|
||||
MainStockLocationID: inventory.LocationID(country),
|
||||
@@ -151,6 +159,9 @@ func main() {
|
||||
// The catalog-feed handler emits inventory.level_changed crossings
|
||||
// directly on this connection as it writes stock.
|
||||
stockhandler.conn = conn
|
||||
// Share the bus connection with the batch handler so its writes emit
|
||||
// inventory.level_changed crossings too.
|
||||
server.conn = conn
|
||||
// Reconnecting consumer: re-listen on reconnect.
|
||||
conn.NotifyOnReconnect(func() {
|
||||
ch, err := conn.Channel()
|
||||
|
||||
Reference in New Issue
Block a user