2024-02-19 18:20:09 +00:00
|
|
|
package shortstat
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"database/sql"
|
|
|
|
"fmt"
|
|
|
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
|
2024-07-23 17:12:23 +00:00
|
|
|
"penahub.gitlab.yandexcloud.net/backend/quiz/worker/workers"
|
2024-02-19 18:20:09 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ShortStat struct of worker for expiration worker
|
|
|
|
type ShortStat struct {
|
|
|
|
w *workers.Worker
|
|
|
|
d *dal.DAL
|
|
|
|
}
|
|
|
|
|
|
|
|
// New creation of worker
|
|
|
|
func New(d *dal.DAL, p time.Duration) *ShortStat {
|
|
|
|
return &ShortStat{
|
|
|
|
w: workers.New(p),
|
|
|
|
d: d,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start method for starting worker with long polling from postgres
|
|
|
|
func (t *ShortStat) Start(ctx context.Context) {
|
|
|
|
t.w.Start(ctx, func(ctx context.Context) error {
|
|
|
|
fmt.Println("SHORTSTAT1")
|
|
|
|
if err := t.d.WorkerRepo.WorkerStatProcess(ctx); err != nil {
|
|
|
|
fmt.Println("SHORTSTAT2", err)
|
|
|
|
if err != sql.ErrNoRows {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *ShortStat) ExposeErr(ctx context.Context, err *error) {
|
|
|
|
t.w.ExposeErr(ctx, err)
|
|
|
|
}
|