mock amazon event processing stubbed

This commit is contained in:
2026-08-20 00:23:54 -06:00
parent 9f86b8e95c
commit 40afd176e7
4 changed files with 622 additions and 3 deletions
+36 -3
View File
@@ -22,6 +22,7 @@ import (
"github.com/lmittmann/tint"
"ruben/inventory2/domains/accounts"
"ruben/inventory2/domains/amazon"
"ruben/inventory2/domains/authentication"
etsy_platform "ruben/inventory2/domains/platforms/etsy"
"ruben/inventory2/domains/raw_events"
@@ -82,6 +83,11 @@ func runApp(ctx context.Context, logger *logging.Logger) error {
authErrCh := runAuthProcesses(ctx, auth)
eventErrCh := runEventProcessing(
ctx,
amazon.NewMocks(logger.WithGroup("amazon"), connPool),
)
// start http server
srvErrCh := runServer(ctx, logger, connPool, auth)
@@ -93,8 +99,9 @@ func runApp(ctx context.Context, logger *logging.Logger) error {
var (
alreadyShutdown struct {
server bool
authProcesses bool
server bool
authProcesses bool
eventProcessing bool
}
)
select {
@@ -107,6 +114,12 @@ func runApp(ctx context.Context, logger *logging.Logger) error {
if err != nil {
logger.Error("auth processes encountered error", "error", err)
}
case err := <-eventErrCh:
alreadyShutdown.eventProcessing = true
logger.Error("event processing shutdown unexpectedly")
if err != nil {
logger.Error("event processing encountered error", "error", err)
}
case err := <-srvErrCh:
alreadyShutdown.server = true
logger.Error("server shutdown unexpectedly")
@@ -128,6 +141,13 @@ func runApp(ctx context.Context, logger *logging.Logger) error {
logger.Info("auth processes shut down")
}
if !alreadyShutdown.eventProcessing {
if err := <-authErrCh; err != nil {
errs = append(errs, fmt.Errorf("event processing experienced an error: %w", err))
}
logger.Info("event processing shut down")
}
if !alreadyShutdown.server {
if err := <-srvErrCh; err != nil {
errs = append(errs, fmt.Errorf("server experienced an error: %w", err))
@@ -151,8 +171,21 @@ func runAuthProcesses(ctx context.Context, auth *authentication.Authenticator) <
return errCh
}
func runEventProcessing(ctx context.Context, amz *amazon.Mocks) <-chan error {
errCh := make(chan error, 1)
go func() {
defer close(errCh)
if err := amz.ProcessEvents(ctx); err != nil {
errCh <- err
}
}()
return errCh
}
func runServer(ctx context.Context, logger *logging.Logger, connPool *pgxpool.Pool, auth *authentication.Authenticator) <-chan error {
accts := accounts.NewStore(logger, connPool)
accts := accounts.NewStore(logger.WithGroup("accounts"), connPool)
r := server.NewRouter(
logger.WithGroup("server"),