mirror of http://gitlab.batiao8.com/yic/film.git
syncInterval
This commit is contained in:
parent
8996e27b70
commit
2c81091b94
|
@ -1,3 +1,4 @@
|
||||||
{
|
{
|
||||||
"token": "d6847dfbd7b79bc18709e0311fd7813b"
|
"token": "d6847dfbd7b79bc18709e0311fd7813b",
|
||||||
|
"syncInterval": 10
|
||||||
}
|
}
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
type Haha struct {
|
type Haha struct {
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
|
SyncInterval int `json:"syncInterval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -18,8 +19,8 @@ func LoadHahaConfig() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
dadiConfig = new(Dadi)
|
hahaConfig = new(Haha)
|
||||||
if err := json.Unmarshal([]byte(body), dadiConfig); err != nil {
|
if err := json.Unmarshal([]byte(body), hahaConfig); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-co-op/gocron"
|
"github.com/go-co-op/gocron"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/smbrave/goutil"
|
||||||
"github.com/spf13/cast"
|
"github.com/spf13/cast"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -18,10 +19,12 @@ type SyncOrderConfig struct {
|
||||||
Token string
|
Token string
|
||||||
NewOrder chan *model.Order
|
NewOrder chan *model.Order
|
||||||
UpdateOrder chan *model.Order
|
UpdateOrder chan *model.Order
|
||||||
|
SyncInterval int
|
||||||
}
|
}
|
||||||
|
|
||||||
type SyncOrder struct {
|
type SyncOrder struct {
|
||||||
token string
|
token string
|
||||||
|
syncInterval int
|
||||||
newOrder chan *model.Order
|
newOrder chan *model.Order
|
||||||
updateOrder chan *model.Order
|
updateOrder chan *model.Order
|
||||||
}
|
}
|
||||||
|
@ -31,6 +34,7 @@ func NewSyncOrder(cfg *SyncOrderConfig) *SyncOrder {
|
||||||
token: cfg.Token,
|
token: cfg.Token,
|
||||||
newOrder: cfg.NewOrder,
|
newOrder: cfg.NewOrder,
|
||||||
updateOrder: cfg.UpdateOrder,
|
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")
|
timezone, _ := time.LoadLocation("Asia/Shanghai")
|
||||||
cron := gocron.NewScheduler(timezone)
|
cron := gocron.NewScheduler(timezone)
|
||||||
|
|
||||||
cron.Every(30).Seconds().Do(func() {
|
cron.Every(s.syncInterval).Seconds().Do(func() {
|
||||||
s.run()
|
s.run()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -115,6 +115,7 @@ func (w *Worker) Run() {
|
||||||
Token: config.GetHahaConfig().Token,
|
Token: config.GetHahaConfig().Token,
|
||||||
NewOrder: newOrderChan,
|
NewOrder: newOrderChan,
|
||||||
UpdateOrder: updateOrderChan,
|
UpdateOrder: updateOrderChan,
|
||||||
|
SyncInterval: config.GetHahaConfig().SyncInterval,
|
||||||
})
|
})
|
||||||
|
|
||||||
hahaSyncer.Sync()
|
hahaSyncer.Sync()
|
||||||
|
|
Loading…
Reference in New Issue