mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00

* refactor(feeds): make feed scheduling more robust * feat(feeds): add daily cleanup job * removes feed cache older than 30 days * fix(feeds): fmt wrong type
35 lines
750 B
Go
35 lines
750 B
Go
// Copyright (c) 2021 - 2023, Ludvig Lundgren and the autobrr contributors.
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
package feed
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/autobrr/autobrr/internal/domain"
|
|
|
|
"github.com/rs/zerolog"
|
|
)
|
|
|
|
type CleanupJob struct {
|
|
log zerolog.Logger
|
|
cacheRepo domain.FeedCacheRepo
|
|
|
|
CronSchedule time.Duration
|
|
}
|
|
|
|
func NewCleanupJob(log zerolog.Logger, cacheRepo domain.FeedCacheRepo) *CleanupJob {
|
|
return &CleanupJob{
|
|
log: log,
|
|
cacheRepo: cacheRepo,
|
|
}
|
|
}
|
|
|
|
func (j *CleanupJob) Run() {
|
|
if err := j.cacheRepo.DeleteStale(context.Background()); err != nil {
|
|
j.log.Error().Err(err).Msg("error when running feed cache cleanup job")
|
|
}
|
|
|
|
j.log.Info().Msg("successfully ran feed-cache-cleanup job")
|
|
}
|