refactor(coin): retire completed startup cleanup

This commit is contained in:
2026-07-21 19:13:23 +07:00
parent 907d07f0af
commit bc2d3528cb
5 changed files with 0 additions and 366 deletions
-29
View File
@@ -29,7 +29,6 @@ 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"
)
@@ -95,10 +94,6 @@ 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()
@@ -136,18 +131,6 @@ 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",
@@ -226,18 +209,6 @@ 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,13 +77,3 @@ 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")
}
}