mirror of
https://github.com/idanoo/autobrr
synced 2025-07-24 01:09:13 +00:00
feat(feeds): add scheduled cleanup (#1073)
* 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
This commit is contained in:
parent
cfc2436d50
commit
6fd8626507
11 changed files with 301 additions and 215 deletions
35
internal/feed/cleanup.go
Normal file
35
internal/feed/cleanup.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
// 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")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue