feat: runtime manager

This commit is contained in:
Ilia Denisov
2026-04-28 20:39:18 +02:00
committed by GitHub
parent e0a99b346b
commit a7cee15115
289 changed files with 45660 additions and 2207 deletions
@@ -0,0 +1,56 @@
// Package streamoffsetinmem provides an in-process ports.StreamOffsetStore
// used by worker-level tests that do not need Redis. Production code
// never wires this stub.
package streamoffsetinmem
import (
"context"
"errors"
"sync"
"galaxy/lobby/internal/ports"
)
// Store is a concurrency-safe in-memory ports.StreamOffsetStore.
type Store struct {
mu sync.Mutex
offsets map[string]string
}
// NewStore constructs an empty Store.
func NewStore() *Store {
return &Store{offsets: make(map[string]string)}
}
// Load returns the last saved entry id for streamLabel.
func (store *Store) Load(ctx context.Context, streamLabel string) (string, bool, error) {
if ctx == nil {
return "", false, errors.New("load offset: nil context")
}
store.mu.Lock()
defer store.mu.Unlock()
value, ok := store.offsets[streamLabel]
return value, ok, nil
}
// Save records entryID as the offset for streamLabel.
func (store *Store) Save(ctx context.Context, streamLabel, entryID string) error {
if ctx == nil {
return errors.New("save offset: nil context")
}
store.mu.Lock()
defer store.mu.Unlock()
store.offsets[streamLabel] = entryID
return nil
}
// Set forces the in-memory value for streamLabel; useful in tests to
// pre-populate state.
func (store *Store) Set(streamLabel, entryID string) {
store.mu.Lock()
defer store.mu.Unlock()
store.offsets[streamLabel] = entryID
}
// Compile-time interface assertion.
var _ ports.StreamOffsetStore = (*Store)(nil)