2025-01-12 19:40:36 -05:00
|
|
|
package share
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
PruneInterval = time.Hour * 4
|
|
|
|
)
|
|
|
|
|
|
|
|
type Service interface {
|
|
|
|
Store() Store
|
|
|
|
|
|
|
|
Go(ctx context.Context)
|
|
|
|
}
|
|
|
|
|
|
|
|
type service struct {
|
|
|
|
store Store
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *service) Store() Store {
|
|
|
|
return s.store
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *service) Go(ctx context.Context) {
|
|
|
|
tick := time.NewTicker(PruneInterval)
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
2025-01-15 23:11:42 -05:00
|
|
|
case <-tick.C:
|
2025-01-12 19:40:36 -05:00
|
|
|
err := s.store.Prune(ctx)
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Err(err).Msg("share prune failed")
|
|
|
|
}
|
|
|
|
case <-ctx.Done():
|
|
|
|
tick.Stop()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewService() *service {
|
|
|
|
return &service{
|
|
|
|
store: NewStore(),
|
|
|
|
}
|
|
|
|
}
|