From 10eb852c01e84619340290d1cbaba0b116dd3267 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 27 Oct 2024 18:19:13 +0200 Subject: add now tag --- internal/queue/queue.go | 7 +++---- internal/schedule/schedule.go | 16 +++++++++++++--- internal/schedule/stats.go | 6 +++++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/internal/queue/queue.go b/internal/queue/queue.go index e396761..229c3c5 100644 --- a/internal/queue/queue.go +++ b/internal/queue/queue.go @@ -42,6 +42,7 @@ func queueEntries(args config.Args) error { } for filePath := range ch { + // TODO: Document .ask. in README.md if strings.Contains(filepath.Base(filePath), ".ask.") { bytes, err := os.ReadFile(filePath) if err != nil { @@ -61,8 +62,7 @@ func queueEntries(args config.Args) error { return err } } - destPath := fmt.Sprintf("%s/db/%s.%s.queued", args.GosDir, - filepath.Base(filePath), timestamp.Now()) + destPath := fmt.Sprintf("%s/db/%s.%s.queued", args.GosDir, filepath.Base(filePath), timestamp.Now()) if args.DryRun { log.Println("Not queueing entry", filePath, "to", destPath, "as dry-run mode enabled") continue @@ -107,8 +107,7 @@ func queuePlatforms(args config.Args) error { } // Keep queued items in trash for a while. - trashPath := filepath.Join(trashDir, - strings.TrimSuffix(filepath.Base(filePath), ".queued")+".trash") + trashPath := filepath.Join(trashDir, strings.TrimSuffix(filepath.Base(filePath), ".queued")+".trash") log.Printf("Trashing %s -> %s", filePath, trashPath) if err := oi.EnsureParentDir(trashPath); err != nil { return err diff --git a/internal/schedule/schedule.go b/internal/schedule/schedule.go index b6be6be..5ac2732 100644 --- a/internal/schedule/schedule.go +++ b/internal/schedule/schedule.go @@ -27,13 +27,23 @@ func Run(args config.Args, platform string) (entry.Entry, error) { } log.Println("For", platform, "stats:", stats) + // Schedule random queued entry with "now" tag, ignoring the target hit stats. + // TODO: Document .now. tag + ent, err := selectRandomEntry(dir, "now") + if err != nil && !errors.Is(err, oi.ErrNotFound) { + // Unknown error + return ent, nil + } + if err == nil { + return ent, nil + } + if stats.targetHit(args.PauseDays) { return entry.Zero, ErrNothingToSchedule } - // Schedule random qeued entry for platform. First, try to find one with - // a priority tag. - ent, err := selectRandomEntry(dir, "prio") + // Schedule random qeued entry for platform. Find one with prio tag. + ent, err = selectRandomEntry(dir, "prio") if errors.Is(err, oi.ErrNotFound) { // No entry with priority tag found, select another one. ent, err = selectRandomEntry(dir, "") diff --git a/internal/schedule/stats.go b/internal/schedule/stats.go index bf5a12c..77271fe 100644 --- a/internal/schedule/stats.go +++ b/internal/schedule/stats.go @@ -5,6 +5,7 @@ import ( "log" "os" "path/filepath" + "strings" "time" "codeberg.org/snonux/gos/internal/entry" @@ -76,7 +77,10 @@ func (s *stats) gatherPostedStats(dir string, lookbackTime time.Time) error { if ent.Time.After(newest) { newest = ent.Time } - s.posted++ + // Ignore .now. + if !strings.Contains(file.Name(), ".now.") { + s.posted++ + } return nil }) if err != nil { -- cgit v1.2.3