worker/workers/timeout/timeout.go
skeris efdaff564d
Some checks failed
Deploy / CreateImage (push) Failing after 56s
Deploy / DeployService (push) Has been skipped
gitea ci implements
2025-05-15 16:27:07 +03:00

41 lines
760 B
Go

package timeout
import (
"context"
"database/sql"
"gitea.pena/SQuiz/common/dal"
"gitea.pena/SQuiz/worker/workers"
"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)
}