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