Compare commits

..

No commits in common. "55f4cbdd6b2c47304205e76604bd16065f10429c" and "bb8dde6361ab1a578eb1ca409f5f76876d8ec99e" have entirely different histories.

3 changed files with 7 additions and 23 deletions

View File

@ -6,19 +6,18 @@ import (
)
type Cron struct {
time time.Time
ctx context.Context
cancel context.CancelFunc
f func()
time time.Time
ctx context.Context
f func()
}
func NewCron() *Cron {
func NewCron(ctx context.Context) *Cron {
now := time.Now()
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),
}
return c
}
func (c *Cron) SetFunc(f func()) *Cron {
@ -39,8 +38,7 @@ func (c *Cron) SetTimeHHmm(HHmm string) *Cron {
return c
}
func (c *Cron) Run(ctx context.Context) {
c.ctx, c.cancel = context.WithCancel(ctx)
func (c *Cron) Run() {
for {
if time.Now().After(c.time) {
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()
}

View File

@ -10,7 +10,6 @@ import (
type ProviderArticleApi interface {
Get(query GetProviderArticleQuery) (article v2.ProviderArticle, err error)
Upsert(article v2.ProviderArticle) error
AutoMigrate() error
}
type providerArticleApi struct {
@ -59,7 +58,3 @@ func (p *providerArticleApi) Upsert(article v2.ProviderArticle) error {
DoUpdates: clause.AssignmentColumns([]string{"cost"}),
}).Create(&article).Error
}
func (p *providerArticleApi) AutoMigrate() error {
return p.db.AutoMigrate(&v2.ProviderArticle{})
}

View File

@ -10,7 +10,6 @@ import (
type SellerArticleApi interface {
Get(query GetProviderArticleQuery) (article v2.ProviderArticle, err error)
Upsert(article v2.SellerArticle) error
AutoMigrate() error
}
type sellerArticleApi struct {
@ -55,7 +54,3 @@ func (p *sellerArticleApi) Upsert(article v2.SellerArticle) error {
DoUpdates: clause.AssignmentColumns([]string{"sell"}),
}).Create(&article).Error
}
func (p *sellerArticleApi) AutoMigrate() error {
return p.db.AutoMigrate(&v2.SellerArticle{})
}