fix(telegram): add request timeout for notifications
Deploy / Test, build and deploy (push) Failing after 6m3s

This commit is contained in:
2026-07-08 04:59:24 +04:00
parent 57e723db65
commit b76fd546fe
8 changed files with 236 additions and 35 deletions
+14 -6
View File
@@ -66,12 +66,14 @@ type DBConfig struct {
}
type TelegramConfig struct {
BotToken string `env:"BOT_TOKEN"`
ChatID int64 `env:"CHAT_ID"`
NotifyInfo bool `env:"NOTIFY_INFO" envDefault:"true"`
NotifyWarn bool `env:"NOTIFY_WARN" envDefault:"true"`
NotifyAlert bool `env:"NOTIFY_ALERT" envDefault:"true"`
NotifyReport bool `env:"NOTIFY_REPORT" envDefault:"true"`
BotToken string `env:"BOT_TOKEN"`
ChatID int64 `env:"CHAT_ID"`
NotifyInfo bool `env:"NOTIFY_INFO" envDefault:"true"`
NotifyWarn bool `env:"NOTIFY_WARN" envDefault:"true"`
NotifyAlert bool `env:"NOTIFY_ALERT" envDefault:"true"`
NotifyReport bool `env:"NOTIFY_REPORT" envDefault:"true"`
RequestTimeoutSec int `env:"REQUEST_TIMEOUT_SEC" envDefault:"10"`
QueueSize int `env:"QUEUE_SIZE" envDefault:"256"`
}
type StrategyConfig struct {
@@ -201,6 +203,12 @@ func (c *Config) Validate() error {
if c.TInvest.RequestTimeoutSec <= 0 {
return errors.New("TINVEST_REQUEST_TIMEOUT_SEC must be positive")
}
if c.Telegram.RequestTimeoutSec <= 0 {
return errors.New("TELEGRAM_REQUEST_TIMEOUT_SEC must be positive")
}
if c.Telegram.QueueSize <= 0 {
return errors.New("TELEGRAM_QUEUE_SIZE must be positive")
}
if c.TInvest.TradingCalendarExchange == "" {
c.TInvest.TradingCalendarExchange = "MOEX"
}
+37
View File
@@ -86,6 +86,39 @@ func TestLoadSchedulerKnobsFromEnv(t *testing.T) {
}
}
func TestLoadTelegramQueueDefaults(t *testing.T) {
t.Setenv("APP_MODE", "backtest")
cfg, err := Load()
if err != nil {
t.Fatal(err)
}
if cfg.Telegram.RequestTimeoutSec != 10 {
t.Fatalf("telegram request timeout=%d, want 10", cfg.Telegram.RequestTimeoutSec)
}
if cfg.Telegram.QueueSize != 256 {
t.Fatalf("telegram queue size=%d, want 256", cfg.Telegram.QueueSize)
}
}
func TestValidateRejectsInvalidTelegramRequestTimeout(t *testing.T) {
cfg := minimalBrokerConfig(domain.ModeSandbox)
cfg.Telegram.RequestTimeoutSec = 0
err := cfg.Validate()
if err == nil || !strings.Contains(err.Error(), "TELEGRAM_REQUEST_TIMEOUT_SEC") {
t.Fatalf("Validate err=%v, want TELEGRAM_REQUEST_TIMEOUT_SEC requirement", err)
}
}
func TestValidateRejectsInvalidTelegramQueueSize(t *testing.T) {
cfg := minimalBrokerConfig(domain.ModeSandbox)
cfg.Telegram.QueueSize = 0
err := cfg.Validate()
if err == nil || !strings.Contains(err.Error(), "TELEGRAM_QUEUE_SIZE") {
t.Fatalf("Validate err=%v, want TELEGRAM_QUEUE_SIZE requirement", err)
}
}
func minimalBrokerConfig(mode domain.Mode) Config {
return Config{
App: AppConfig{
@@ -99,6 +132,10 @@ func minimalBrokerConfig(mode domain.Mode) Config {
RequestTimeoutSec: 10,
},
DB: DBConfig{DSN: "user:pass@tcp(localhost:3306)/bot"},
Telegram: TelegramConfig{
RequestTimeoutSec: 10,
QueueSize: 256,
},
Execution: ExecutionConfig{
EntrySignalTime: mustTOD("18:10:00"),
EntryWindowStart: mustTOD("18:20:00"),