26 lines
649 B
Go
26 lines
649 B
Go
package summaryqa
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// Cleanup is retryable and deletes only expired temporary source rows. API reads
|
|
// also enforce expiration independently; a delayed worker never grants access.
|
|
func RunPurger(ctx context.Context, repo Repository, interval time.Duration, onFailure func()) {
|
|
ticker := time.NewTicker(interval)
|
|
defer ticker.Stop()
|
|
for {
|
|
attempt, cancel := context.WithTimeout(ctx, 10*time.Second)
|
|
if err := repo.PurgeExpiredQASources(attempt, time.Now()); err != nil && ctx.Err() == nil && onFailure != nil {
|
|
onFailure()
|
|
}
|
|
cancel()
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case <-ticker.C:
|
|
}
|
|
}
|
|
}
|