55 lines
991 B
Go
55 lines
991 B
Go
|
package data_updater
|
||
|
|
||
|
import (
|
||
|
"amocrm/internal/repository"
|
||
|
"amocrm/pkg/amoClient"
|
||
|
"context"
|
||
|
"go.uber.org/zap"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
type Deps struct {
|
||
|
AmoClient *amoClient.Amo
|
||
|
Repo *repository.Repository
|
||
|
Logger *zap.Logger
|
||
|
}
|
||
|
|
||
|
type DataUpdater struct {
|
||
|
amoClient *amoClient.Amo
|
||
|
repo *repository.Repository
|
||
|
logger *zap.Logger
|
||
|
}
|
||
|
|
||
|
func NewDataUpdaterWC(deps Deps) *DataUpdater {
|
||
|
return &DataUpdater{
|
||
|
amoClient: deps.AmoClient,
|
||
|
repo: deps.Repo,
|
||
|
logger: deps.Logger,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (wc *DataUpdater) Start(ctx context.Context) {
|
||
|
nextStart := calculateTime()
|
||
|
ticker := time.NewTicker(time.Second * time.Duration(nextStart))
|
||
|
defer ticker.Stop()
|
||
|
|
||
|
for {
|
||
|
select {
|
||
|
case <-ticker.C:
|
||
|
wc.processTasks(ctx)
|
||
|
nextStart = calculateTime()
|
||
|
ticker.Reset(time.Second * time.Duration(nextStart))
|
||
|
case <-ctx.Done():
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (wc *DataUpdater) processTasks(ctx context.Context) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func (wc *DataUpdater) Stop(ctx context.Context) error {
|
||
|
return nil
|
||
|
}
|