mirror of
https://github.com/tiennm99/tiennm99bot.git
synced 2026-10-19 00:15:24 +00:00
feat(stock): persist per-user dividend history
This commit is contained in:
1 parent
8de459b131
commit
df240a5db0
25 files changed
+2076
-582
No files matched your search
@@ -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
|
||||
|
||||
// stockMigrationTimeout bounds the one-time scan of persisted stock
|
||||
// portfolios without tying it to the shorter MongoDB connection timeout.
|
||||
const stockMigrationTimeout = 2 * time.Minute
|
||||
|
||||
func main() {
|
||||
rootCtx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer stop()
|
||||
@@ -119,6 +124,12 @@ func main() {
|
||||
if err := lol.InitStore(rootCtx, provider.Collection(lol.CollectionName)); err != nil {
|
||||
log.Fatal("lol storage init failed", "err", err)
|
||||
}
|
||||
migrationCtx, cancelMigration := context.WithTimeout(rootCtx, stockMigrationTimeout)
|
||||
if err := initStockStore(migrationCtx, provider); err != nil {
|
||||
cancelMigration()
|
||||
log.Fatal("stock storage init failed", "err", err)
|
||||
}
|
||||
cancelMigration()
|
||||
|
||||
b, err := telegram.NewBot(cfg.TelegramBotToken)
|
||||
if err != nil {
|
||||
@@ -209,6 +220,20 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func initStockStore(ctx context.Context, provider storage.Provider) error {
|
||||
return initStockStoreWith(ctx, provider, stock.InitStore)
|
||||
}
|
||||
|
||||
type stockStoreInitializer func(context.Context, storage.Collection, storage.Collection) error
|
||||
|
||||
func initStockStoreWith(ctx context.Context, provider storage.Provider, init stockStoreInitializer) error {
|
||||
return init(
|
||||
ctx,
|
||||
provider.Collection(stock.CollectionName),
|
||||
provider.Collection(systemstate.CollectionName),
|
||||
)
|
||||
}
|
||||
|
||||
// buildProvider picks the storage backend. Selection order:
|
||||
// 1. Explicit KV_PROVIDER env (memory|mongodb) wins.
|
||||
// 2. Auto-detect: MONGO_URL set → mongodb; otherwise memory.
|
||||
|
||||
Reference in new issue
Block a user