some strange storage stuff
This commit is contained in:
25
main.go
25
main.go
@@ -43,11 +43,16 @@ func spawn(id CartId) (*CartGrain, error) {
|
||||
Deliveries: []*CartDelivery{},
|
||||
Id: id,
|
||||
Items: []*CartItem{},
|
||||
// storageMessages removed (legacy event log deprecated)
|
||||
TotalPrice: 0,
|
||||
TotalPrice: 0,
|
||||
}
|
||||
err := loadMessages(ret, id)
|
||||
return ret, err
|
||||
// Set baseline lastChange at spawn; replay may update it to last event timestamp.
|
||||
ret.lastChange = time.Now().Unix()
|
||||
|
||||
// Legacy loadMessages (no-op) retained; then replay append-only event log
|
||||
_ = loadMessages(ret, id)
|
||||
_ = ReplayCartEvents(ret, id)
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -160,7 +165,7 @@ func main() {
|
||||
log.Printf("Error loading state: %v\n", err)
|
||||
}
|
||||
app := &App{
|
||||
pool: NewGrainLocalPool(65535, 5*time.Minute, spawn),
|
||||
pool: NewGrainLocalPool(65535, 2*time.Hour, spawn),
|
||||
storage: storage,
|
||||
}
|
||||
|
||||
@@ -384,11 +389,15 @@ func main() {
|
||||
}
|
||||
|
||||
func triggerOrderCompleted(err error, syncedServer *PoolServer, order *CheckoutOrder) error {
|
||||
_, err = syncedServer.pool.Apply(ToCartId(order.MerchantReference1), &messages.OrderCreated{
|
||||
mutation := &messages.OrderCreated{
|
||||
OrderId: order.ID,
|
||||
Status: order.Status,
|
||||
})
|
||||
return err
|
||||
}
|
||||
_, applyErr := syncedServer.pool.Apply(ToCartId(order.MerchantReference1), mutation)
|
||||
if applyErr == nil {
|
||||
_ = AppendCartEvent(ToCartId(order.MerchantReference1), mutation)
|
||||
}
|
||||
return applyErr
|
||||
}
|
||||
|
||||
func confirmOrder(order *CheckoutOrder, orderHandler *AmqpOrderHandler) error {
|
||||
|
||||
Reference in New Issue
Block a user