Compare commits
No commits in common. "55f4cbdd6b2c47304205e76604bd16065f10429c" and "bb8dde6361ab1a578eb1ca409f5f76876d8ec99e" have entirely different histories.
55f4cbdd6b
...
bb8dde6361
@ -6,19 +6,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Cron struct {
|
type Cron struct {
|
||||||
time time.Time
|
time time.Time
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancel context.CancelFunc
|
f func()
|
||||||
f func()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCron() *Cron {
|
func NewCron(ctx context.Context) *Cron {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
l, _ := time.LoadLocation("Asia/Shanghai")
|
l, _ := time.LoadLocation("Asia/Shanghai")
|
||||||
c := &Cron{
|
return &Cron{
|
||||||
|
ctx: ctx,
|
||||||
time: time.Date(now.Year(), now.Month(), now.Day(), 01, 0, 0, 0, l),
|
time: time.Date(now.Year(), now.Month(), now.Day(), 01, 0, 0, 0, l),
|
||||||
}
|
}
|
||||||
return c
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cron) SetFunc(f func()) *Cron {
|
func (c *Cron) SetFunc(f func()) *Cron {
|
||||||
@ -39,8 +38,7 @@ func (c *Cron) SetTimeHHmm(HHmm string) *Cron {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cron) Run(ctx context.Context) {
|
func (c *Cron) Run() {
|
||||||
c.ctx, c.cancel = context.WithCancel(ctx)
|
|
||||||
for {
|
for {
|
||||||
if time.Now().After(c.time) {
|
if time.Now().After(c.time) {
|
||||||
c.time = c.time.Add(time.Hour * 24)
|
c.time = c.time.Add(time.Hour * 24)
|
||||||
@ -55,7 +53,3 @@ func (c *Cron) Run(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cron) Stop() {
|
|
||||||
c.cancel()
|
|
||||||
}
|
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
type ProviderArticleApi interface {
|
type ProviderArticleApi interface {
|
||||||
Get(query GetProviderArticleQuery) (article v2.ProviderArticle, err error)
|
Get(query GetProviderArticleQuery) (article v2.ProviderArticle, err error)
|
||||||
Upsert(article v2.ProviderArticle) error
|
Upsert(article v2.ProviderArticle) error
|
||||||
AutoMigrate() error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type providerArticleApi struct {
|
type providerArticleApi struct {
|
||||||
@ -59,7 +58,3 @@ func (p *providerArticleApi) Upsert(article v2.ProviderArticle) error {
|
|||||||
DoUpdates: clause.AssignmentColumns([]string{"cost"}),
|
DoUpdates: clause.AssignmentColumns([]string{"cost"}),
|
||||||
}).Create(&article).Error
|
}).Create(&article).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *providerArticleApi) AutoMigrate() error {
|
|
||||||
return p.db.AutoMigrate(&v2.ProviderArticle{})
|
|
||||||
}
|
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
type SellerArticleApi interface {
|
type SellerArticleApi interface {
|
||||||
Get(query GetProviderArticleQuery) (article v2.ProviderArticle, err error)
|
Get(query GetProviderArticleQuery) (article v2.ProviderArticle, err error)
|
||||||
Upsert(article v2.SellerArticle) error
|
Upsert(article v2.SellerArticle) error
|
||||||
AutoMigrate() error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type sellerArticleApi struct {
|
type sellerArticleApi struct {
|
||||||
@ -55,7 +54,3 @@ func (p *sellerArticleApi) Upsert(article v2.SellerArticle) error {
|
|||||||
DoUpdates: clause.AssignmentColumns([]string{"sell"}),
|
DoUpdates: clause.AssignmentColumns([]string{"sell"}),
|
||||||
}).Create(&article).Error
|
}).Create(&article).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *sellerArticleApi) AutoMigrate() error {
|
|
||||||
return p.db.AutoMigrate(&v2.SellerArticle{})
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user