fix(coin): remove stale dividend cursor fields

This commit is contained in:
tiennm99 committed 2026-07-21 18:50:30 +07:00
1 parent ee2c520944
commit 01efb83df7
5 files changed
+366

No files matched your search

+29
View File
@@ -29,6 +29,7 @@ import (
"github.com/tiennm99/miti99bot/internal/modules/wordle"
"github.com/tiennm99/miti99bot/internal/server"
"github.com/tiennm99/miti99bot/internal/storage"
"github.com/tiennm99/miti99bot/internal/systemstate"
"github.com/tiennm99/miti99bot/internal/telegram"
)
@@ -94,6 +95,10 @@ func factories() map[string]modules.Factory {
// container; 10s leaves headroom without hiding a wedged cluster.
const mongodbInitTimeout = 10 * time.Second
// portfolioCleanupTimeout bounds the temporary one-time cleanup of legacy
// coin portfolio fields before Telegram handlers begin serving requests.
const portfolioCleanupTimeout = 2 * time.Minute
func main() {
rootCtx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()
@@ -131,6 +136,18 @@ func main() {
if err != nil {
log.Fatal("module registry build failed", "err", err)
}
if moduleLoaded(reg, coin.CollectionName) {
cleanupCtx, cancel := context.WithTimeout(rootCtx, portfolioCleanupTimeout)
err = coin.InitStore(
cleanupCtx,
provider.Collection(coin.CollectionName),
provider.Collection(systemstate.CollectionName),
)
cancel()
if err != nil {
log.Fatal("coin storage cleanup failed", "err", err)
}
}
auth := modules.Auth{BotOwnerID: cfg.BotOwnerID, AdminUserIDs: cfg.AdminUserIDs}
modules.Install(b, reg, auth)
log.Info("modules loaded",
@@ -209,6 +226,18 @@ func main() {
}
}
func moduleLoaded(reg *modules.Registry, name string) bool {
if reg == nil {
return false
}
for _, module := range reg.Modules {
if module.Name == name {
return true
}
}
return false
}
// buildProvider picks the storage backend. Selection order:
// 1. Explicit KV_PROVIDER env (memory|mongodb) wins.
// 2. Auto-detect: MONGO_URL set → mongodb; otherwise memory.
+10
View File
@@ -77,3 +77,13 @@ func TestFactoriesIncludesExpectedModules(t *testing.T) {
}
}
}
func TestModuleLoaded(t *testing.T) {
reg := &modules.Registry{Modules: []modules.Module{{Name: "coin"}}}
if !moduleLoaded(reg, "coin") {
t.Fatal("coin module was not detected")
}
if moduleLoaded(reg, "stock") || moduleLoaded(nil, "coin") {
t.Fatal("moduleLoaded reported an absent module")
}
}