2024-03-31 20:04:15 +00:00
|
|
|
package workers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-04-01 14:24:35 +00:00
|
|
|
"go.uber.org/zap"
|
2024-03-31 20:04:15 +00:00
|
|
|
"mailnotifier/internal/clients"
|
|
|
|
"mailnotifier/internal/repository"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Notifyer struct {
|
|
|
|
repo *repository.Repository
|
|
|
|
mailClient *clients.MailClient
|
2024-04-01 14:24:35 +00:00
|
|
|
logger *zap.Logger
|
2024-03-31 20:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type NotifyerDeps struct {
|
|
|
|
Repo *repository.Repository
|
|
|
|
MailClient *clients.MailClient
|
2024-04-01 14:24:35 +00:00
|
|
|
Logger *zap.Logger
|
2024-03-31 20:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewNotifyer(deps NotifyerDeps) *Notifyer {
|
|
|
|
return &Notifyer{
|
|
|
|
repo: deps.Repo,
|
|
|
|
mailClient: deps.MailClient,
|
2024-04-01 14:24:35 +00:00
|
|
|
logger: deps.Logger,
|
2024-03-31 20:04:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Notifyer) Start(ctx context.Context) {
|
|
|
|
tiker := time.NewTicker(time.Hour)
|
|
|
|
defer tiker.Stop()
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-tiker.C:
|
|
|
|
// todo method
|
|
|
|
|
|
|
|
case <-ctx.Done():
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|