summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-09-28 11:02:37 +0300
committerPaul Buetow <paul@buetow.org>2024-09-28 11:02:37 +0300
commit6865389682c865717bb28f19943c09d0610a7981 (patch)
tree43356c5d709977aca65ebb51d7ec4dfe122fc28b /internal
parentb8c5cb42095cf9406e3e4330aefee5063bf00bea (diff)
add lookback time
Diffstat (limited to 'internal')
-rw-r--r--internal/config/args.go3
-rw-r--r--internal/schedule/schedule.go2
-rw-r--r--internal/schedule/stats.go21
3 files changed, 18 insertions, 8 deletions
diff --git a/internal/config/args.go b/internal/config/args.go
index 5b16912..b71c53e 100644
--- a/internal/config/args.go
+++ b/internal/config/args.go
@@ -1,7 +1,10 @@
package config
+import "time"
+
type Args struct {
GosDir string
DryRun bool
Platforms []string
+ Lookback time.Duration
}
diff --git a/internal/schedule/schedule.go b/internal/schedule/schedule.go
index 321e096..427c208 100644
--- a/internal/schedule/schedule.go
+++ b/internal/schedule/schedule.go
@@ -13,7 +13,7 @@ var NothingToSchedule = errors.New("nothing to schedule")
func Run(args config.Args, platform string) (string, error) {
dir := fmt.Sprintf("%s/db/platforms/%s", args.GosDir, strings.ToLower(platform))
- stats, err := newStats(dir)
+ stats, err := newStats(dir, args.Lookback)
if err != nil {
return "", err
}
diff --git a/internal/schedule/stats.go b/internal/schedule/stats.go
index ac1671a..d6cbf20 100644
--- a/internal/schedule/stats.go
+++ b/internal/schedule/stats.go
@@ -25,10 +25,10 @@ func (s stats) String() string {
)
}
-func newStats(dir string) (stats, error) {
+func newStats(dir string, lookback time.Duration) (stats, error) {
var stats stats
- if err := stats.gatherPostedStats(dir); err != nil {
+ if err := stats.gatherPostedStats(dir, pastTime(lookback)); err != nil {
return stats, err
}
if err := stats.gatherQueuedStats(dir); err != nil {
@@ -38,8 +38,7 @@ func newStats(dir string) (stats, error) {
return stats, nil
}
-// TODO: Only take entries into consideration from last n days
-func (s *stats) gatherPostedStats(dir string) error {
+func (s *stats) gatherPostedStats(dir string, lookbackTime time.Time) error {
ch, err := oi.ReadDirFilter(dir, func(file os.DirEntry) bool {
return strings.HasSuffix(file.Name(), ".posted")
})
@@ -53,14 +52,18 @@ func (s *stats) gatherPostedStats(dir string) error {
)
var errs []error
+ // TODO: Maybe refactor to include in ReadDirFilter filter
for filePath := range ch {
- newOldest, err := parseEntryPath(filePath)
+ entryTime, err := parseEntryPath(filePath)
if err != nil {
errs = append(errs, err)
continue
}
- if newOldest.Before(oldest) {
- oldest = newOldest
+ if entryTime.Before(lookbackTime) {
+ continue
+ }
+ if entryTime.Before(oldest) {
+ oldest = entryTime
}
s.posted++
}
@@ -106,6 +109,10 @@ func nowTime() time.Time {
return simplerNow
}
+func pastTime(duration time.Duration) time.Time {
+ return nowTime().Add(-duration)
+}
+
func parseEntryPath(filePath string) (time.Time, error) {
// Format: foobarbaz.something.here.txt.STAMP.{posted,queued}
// We want to get the STAMP!