47 lines
736 B
Go
47 lines
736 B
Go
|
package workers
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"github.com/go-redis/redis/v8"
|
||
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
type Deps struct {
|
||
|
BotID int64
|
||
|
Redis *redis.Client
|
||
|
Dal *dal.DAL
|
||
|
}
|
||
|
|
||
|
type TgListenerWorker struct {
|
||
|
botID int64
|
||
|
redis *redis.Client
|
||
|
dal *dal.DAL
|
||
|
}
|
||
|
|
||
|
func NewTgListenerWC(deps Deps) *TgListenerWorker {
|
||
|
return &TgListenerWorker{
|
||
|
botID: deps.BotID,
|
||
|
redis: deps.Redis,
|
||
|
dal: deps.Dal,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (wc *TgListenerWorker) Start(ctx context.Context) {
|
||
|
ticker := time.NewTicker(10 * time.Second)
|
||
|
defer ticker.Stop()
|
||
|
|
||
|
for {
|
||
|
select {
|
||
|
case <-ticker.C:
|
||
|
wc.processTasks(ctx)
|
||
|
case <-ctx.Done():
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (wc *TgListenerWorker) processTasks(ctx context.Context) {
|
||
|
|
||
|
}
|