mirror of
https://github.com/gabehf/Koito.git
synced 2026-03-18 03:36:35 -07:00
feat: time-gated imports via cfg
This commit is contained in:
parent
6d000d87e4
commit
c14df8c2fb
6 changed files with 59 additions and 4 deletions
|
|
@ -4,11 +4,13 @@ import (
|
|||
"context"
|
||||
"os"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"github.com/gabehf/koito/internal/cfg"
|
||||
"github.com/gabehf/koito/internal/logger"
|
||||
)
|
||||
|
||||
// runs after every importer
|
||||
func finishImport(ctx context.Context, filename string, numImported int) error {
|
||||
l := logger.FromContext(ctx)
|
||||
_, err := os.Stat(path.Join(cfg.ConfigDir(), "import_complete"))
|
||||
|
|
@ -27,3 +29,18 @@ func finishImport(ctx context.Context, filename string, numImported int) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// from https://stackoverflow.com/a/55093788 with modification to use cfg and check for zero values
|
||||
func inImportTimeWindow(check time.Time) bool {
|
||||
end, start := cfg.ImportWindow()
|
||||
if start.IsZero() && end.IsZero() {
|
||||
return true
|
||||
}
|
||||
if !start.IsZero() && end.IsZero() {
|
||||
return !check.Before(start)
|
||||
}
|
||||
if start.IsZero() && !end.IsZero() {
|
||||
return !check.After(end)
|
||||
}
|
||||
return !check.Before(start) && !check.After(end)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue