1
0

Implement refetch

This commit is contained in:
dump_stack() 2023-05-12 00:07:51 +00:00
parent 3d2b8b7d2a
commit efbdc9db36
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
2 changed files with 32 additions and 10 deletions

View File

@ -1,6 +1,8 @@
package main package main
import ( import (
"time"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"code.dumpstack.io/tools/out-of-tree/distro/debian" "code.dumpstack.io/tools/out-of-tree/distro/debian"
@ -12,7 +14,8 @@ type DebianCmd struct {
} }
type DebianCacheCmd struct { type DebianCacheCmd struct {
Path string `help:"path to cache" default:"debian.cache"` Path string `help:"path to cache" default:"debian.cache"`
Refetch int `help:"days before refetch versions without deb package" default:"7"`
} }
func (cmd *DebianCacheCmd) Run() (err error) { func (cmd *DebianCacheCmd) Run() (err error) {
@ -33,20 +36,32 @@ func (cmd *DebianCacheCmd) Run() (err error) {
slog := log.With().Str("version", version).Logger() slog := log.With().Str("version", version).Logger()
slog.Info().Msgf("%03d/%03d", i, len(versions)) slog.Info().Msgf("%03d/%03d", i, len(versions))
_, err = c.Get(version) var dk debian.DebianKernel
if err == nil {
dk, err = c.Get(version)
if err == nil && !dk.Internal.Invalid {
slog.Info().Msgf("found in cache") slog.Info().Msgf("found in cache")
continue continue
} }
var dk debian.DebianKernel if dk.Internal.Invalid {
refetch := dk.Internal.LastFetch.AddDate(0, 0, cmd.Refetch)
if refetch.After(time.Now()) {
slog.Info().Msgf("refetch at %v", refetch)
continue
}
}
dk, err = debian.GetDebianKernel(version) dk, err = debian.GetDebianKernel(version)
if err == debian.ErrNoBinaryPackages { if err != nil {
slog.Warn().Err(err).Msg("") if err == debian.ErrNoBinaryPackages {
continue slog.Warn().Err(err).Msg("")
} else if err != nil { } else {
slog.Error().Err(err).Msg("get debian kernel") slog.Error().Err(err).Msg("get debian kernel")
continue }
dk.Internal.Invalid = true
dk.Internal.LastFetch = time.Now()
} }
err = c.Put(dk) err = c.Put(dk)

View File

@ -4,6 +4,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"strings" "strings"
"time"
"code.dumpstack.io/tools/out-of-tree/distro/debian/snapshot" "code.dumpstack.io/tools/out-of-tree/distro/debian/snapshot"
) )
@ -23,6 +24,12 @@ type DebianKernel struct {
Version DebianKernelVersion Version DebianKernelVersion
Image snapshot.Package Image snapshot.Package
Headers snapshot.Package Headers snapshot.Package
// FIXME There is a better way
Internal struct {
Invalid bool
LastFetch time.Time
}
} }
var ( var (