more stuff
This commit is contained in:
23
main.go
23
main.go
@@ -12,7 +12,9 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
messages "git.tornberg.me/go-cart-actor/proto"
|
||||
"git.tornberg.me/go-cart-actor/pkg/actor"
|
||||
"git.tornberg.me/go-cart-actor/pkg/discovery"
|
||||
messages "git.tornberg.me/go-cart-actor/pkg/messages"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
@@ -46,7 +48,8 @@ func spawn(id CartId) (*CartGrain, error) {
|
||||
TotalPrice: 0,
|
||||
}
|
||||
// Set baseline lastChange at spawn; replay may update it to last event timestamp.
|
||||
ret.lastChange = time.Now().Unix()
|
||||
ret.lastChange = time.Now()
|
||||
ret.lastAccess = time.Now()
|
||||
|
||||
// Legacy loadMessages (no-op) retained; then replay append-only event log
|
||||
//_ = loadMessages(ret, id)
|
||||
@@ -69,7 +72,7 @@ func (a *App) Save() error {
|
||||
if grain == nil {
|
||||
continue
|
||||
}
|
||||
if grain.GetLastChange() > a.storage.LastSaves[uint64(id)] {
|
||||
if grain.GetLastChange().After(a.storage.LastSaves[uint64(id)]) {
|
||||
|
||||
err := a.storage.Store(id, grain)
|
||||
if err != nil {
|
||||
@@ -106,7 +109,7 @@ func getCountryFromHost(host string) string {
|
||||
return "se"
|
||||
}
|
||||
|
||||
func GetDiscovery() Discovery {
|
||||
func GetDiscovery() discovery.Discovery {
|
||||
if podIp == "" {
|
||||
return nil
|
||||
}
|
||||
@@ -120,7 +123,7 @@ func GetDiscovery() Discovery {
|
||||
if err != nil {
|
||||
log.Fatalf("Error creating client: %v\n", err)
|
||||
}
|
||||
return NewK8sDiscovery(client)
|
||||
return discovery.NewK8sDiscovery(client)
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -137,9 +140,9 @@ func main() {
|
||||
storage: storage,
|
||||
}
|
||||
|
||||
grpcSrv, err := StartGRPCServer(":1337", pool)
|
||||
grpcSrv, err := actor.NewControlServer(":1337", pool)
|
||||
if err != nil {
|
||||
log.Fatalf("Error starting gRPC server: %v\n", err)
|
||||
log.Fatalf("Error starting control plane gRPC server: %v\n", err)
|
||||
}
|
||||
defer grpcSrv.GracefulStop()
|
||||
|
||||
@@ -236,7 +239,7 @@ func main() {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.Header().Set("Permissions-Policy", "payment=(self \"https://js.stripe.com\" \"https://m.stripe.network\" \"https://js.playground.kustom.co\")")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(fmt.Sprintf(tpl, order.HTMLSnippet)))
|
||||
fmt.Fprintf(w, tpl, order.HTMLSnippet)
|
||||
})
|
||||
mux.HandleFunc("/confirmation/{order_id}", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -263,7 +266,7 @@ func main() {
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(fmt.Sprintf(tpl, order.HTMLSnippet)))
|
||||
fmt.Fprintf(w, tpl, order.HTMLSnippet)
|
||||
})
|
||||
mux.HandleFunc("/validate", func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("Klarna order validation, method: %s", r.Method)
|
||||
@@ -362,7 +365,7 @@ func triggerOrderCompleted(err error, syncedServer *PoolServer, order *CheckoutO
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid cart id in order reference: %s", order.MerchantReference1)
|
||||
}
|
||||
_, applyErr := syncedServer.pool.Apply(cid, mutation)
|
||||
_, applyErr := syncedServer.pool.Apply(uint64(cid), mutation)
|
||||
if applyErr == nil {
|
||||
_ = AppendCartEvent(cid, mutation)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user