All checks were successful
Build image / build (push) Successful in 2m26s
- 实现定时抓取供应商商品信息功能 - 添加供应商配置变更监听及处理逻辑 - 完善商品价格计算及更新机制 - 添加商品库存跟踪功能 - 实现商品详情抓取及更新接口 - 优化错误处理及日志记录 - 添加服务就绪状态检查 - 完善数据库迁移及初始化逻辑"
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package options
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
"time"
|
|
|
|
coach_client "gitea.timerzz.com/kedaya_haitao/common/pkg/coach-client"
|
|
v2 "gitea.timerzz.com/kedaya_haitao/common/structs/v2"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
type Config struct {
|
|
ProviderId v2.ProviderId `yaml:"provider_id"`
|
|
WatchInterval time.Duration
|
|
AtsInterval time.Duration
|
|
AtsThreshold int // 库存一定时间内减少多少个通知
|
|
ClientType string
|
|
ClientArea string // 客户端的地域
|
|
}
|
|
|
|
func LoadConfigs() (opt *Config, err error) {
|
|
opt = &Config{}
|
|
// 从环境变量中读取ProviderId
|
|
opt.ProviderId = v2.ProviderId(os.Getenv("PROVIDER_ID"))
|
|
if opt.ProviderId == "" {
|
|
return nil, fmt.Errorf("环境变量未配置供应商id")
|
|
}
|
|
|
|
opt.WatchInterval, _ = time.ParseDuration(os.Getenv("WATCH_INTERVAL"))
|
|
opt.AtsInterval, _ = time.ParseDuration(os.Getenv("ATS_INTERVAL"))
|
|
if opt.WatchInterval == 0 {
|
|
opt.WatchInterval = 5 * time.Minute
|
|
}
|
|
if opt.AtsInterval == 0 {
|
|
opt.AtsInterval = 15 * time.Minute
|
|
}
|
|
opt.AtsThreshold, _ = strconv.Atoi(os.Getenv("ATS_THRESHOLD"))
|
|
if opt.AtsThreshold == 0 {
|
|
opt.AtsThreshold = 40
|
|
}
|
|
opt.ClientType = coach_client.LoadUSClientType()
|
|
logrus.Infof("加载watch interval %s\nats interval %s\nats threshold %d\nclient type %s", opt.WatchInterval, opt.AtsInterval, opt.AtsThreshold, opt.ClientType)
|
|
return
|
|
}
|