mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-09-13 18:19:15 +00:00
refactor(coin): retire completed startup cleanup
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user