syncInterval

This commit is contained in:
jiangyong27 2023-04-09 13:05:52 +08:00
parent 8996e27b70
commit 2c81091b94
4 changed files with 24 additions and 17 deletions

View File

@ -1,3 +1,4 @@
{
"token": "d6847dfbd7b79bc18709e0311fd7813b"
"token": "d6847dfbd7b79bc18709e0311fd7813b",
"syncInterval": 10
}

View File

@ -6,7 +6,8 @@ import (
)
type Haha struct {
Token string `json:"token"`
Token string `json:"token"`
SyncInterval int `json:"syncInterval"`
}
var (
@ -18,8 +19,8 @@ func LoadHahaConfig() {
if err != nil {
panic(err)
}
dadiConfig = new(Dadi)
if err := json.Unmarshal([]byte(body), dadiConfig); err != nil {
hahaConfig = new(Haha)
if err := json.Unmarshal([]byte(body), hahaConfig); err != nil {
panic(err)
}
}

View File

@ -7,6 +7,7 @@ import (
"fmt"
"github.com/go-co-op/gocron"
log "github.com/sirupsen/logrus"
"github.com/smbrave/goutil"
"github.com/spf13/cast"
"io"
"net/http"
@ -15,22 +16,25 @@ import (
)
type SyncOrderConfig struct {
Token string
NewOrder chan *model.Order
UpdateOrder chan *model.Order
Token string
NewOrder chan *model.Order
UpdateOrder chan *model.Order
SyncInterval int
}
type SyncOrder struct {
token string
newOrder chan *model.Order
updateOrder chan *model.Order
token string
syncInterval int
newOrder chan *model.Order
updateOrder chan *model.Order
}
func NewSyncOrder(cfg *SyncOrderConfig) *SyncOrder {
return &SyncOrder{
token: cfg.Token,
newOrder: cfg.NewOrder,
updateOrder: cfg.UpdateOrder,
token: cfg.Token,
newOrder: cfg.NewOrder,
updateOrder: cfg.UpdateOrder,
syncInterval: goutil.If(cfg.SyncInterval == 0, 30, cfg.SyncInterval),
}
}
@ -38,7 +42,7 @@ func (s *SyncOrder) Sync() {
timezone, _ := time.LoadLocation("Asia/Shanghai")
cron := gocron.NewScheduler(timezone)
cron.Every(30).Seconds().Do(func() {
cron.Every(s.syncInterval).Seconds().Do(func() {
s.run()
})

View File

@ -112,9 +112,10 @@ func (w *Worker) Run() {
newOrderChan := make(chan *model.Order, 100000)
updateOrderChan := make(chan *model.Order, 100000)
hahaSyncer := haha.NewSyncOrder(&haha.SyncOrderConfig{
Token: config.GetHahaConfig().Token,
NewOrder: newOrderChan,
UpdateOrder: updateOrderChan,
Token: config.GetHahaConfig().Token,
NewOrder: newOrderChan,
UpdateOrder: updateOrderChan,
SyncInterval: config.GetHahaConfig().SyncInterval,
})
hahaSyncer.Sync()