31 lines
588 B
Go
31 lines
588 B
Go
package discord
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
const (
|
|
cleanUpGroupsJobTimeout = 10 * time.Minute
|
|
)
|
|
|
|
type cleanUpGroupsJob struct {
|
|
svc GroupService
|
|
logger *zap.Logger
|
|
}
|
|
|
|
func (j *cleanUpGroupsJob) Run() {
|
|
ctx, cancel := context.WithTimeout(context.Background(), cleanUpGroupsJobTimeout)
|
|
defer cancel()
|
|
|
|
start := time.Now()
|
|
if err := j.svc.CleanUp(ctx); err != nil {
|
|
j.logger.Error("something went wrong while deleting old groups", zap.Error(err))
|
|
return
|
|
}
|
|
|
|
j.logger.Info("old groups have been deleted", zap.Duration("duration", time.Since(start)))
|
|
}
|