diff options
| author | Paul Buetow <paul@buetow.org> | 2024-10-02 11:06:51 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-10-02 11:06:51 +0300 |
| commit | 5c41467e63cb3ec20397dd1790a10ca3999204d3 (patch) | |
| tree | 7ea04b39c97d2fa05891fb58df3415bd4cbb47df | |
| parent | 87593db7993d1f3689d9602eed3ef095ac69cfb4 (diff) | |
fix
| -rw-r--r-- | internal/entry/entry.go | 10 | ||||
| -rw-r--r-- | internal/queue/queue.go | 2 | ||||
| -rw-r--r-- | internal/run.go | 2 | ||||
| -rw-r--r-- | internal/schedule/schedule.go | 8 | ||||
| -rw-r--r-- | internal/schedule/stats.go | 4 |
5 files changed, 20 insertions, 6 deletions
diff --git a/internal/entry/entry.go b/internal/entry/entry.go index 6934eba..91ed8e0 100644 --- a/internal/entry/entry.go +++ b/internal/entry/entry.go @@ -45,6 +45,16 @@ func (e Entry) String() string { var Zero = Entry{} +// TODO: UNDO +// func New(filePath string) (Entry, error) { +// ent, err := new(filePath) +// if err != nil { +// panic(fmt.Sprintf("%s: %v", filePath, err)) +// } +// log.Println("Creating new entry from", filePath, ent) +// return ent, err +// } + // filePath format: /foo/foobarbaz.something.here.txt.STAMP.{posted,queued} func New(filePath string) (Entry, error) { e := Entry{Path: filePath} diff --git a/internal/queue/queue.go b/internal/queue/queue.go index ae8e377..8d6350e 100644 --- a/internal/queue/queue.go +++ b/internal/queue/queue.go @@ -80,7 +80,7 @@ func queuePlatforms(args config.Args) error { // Queue ./db/queued/*.txt.STAMP.queued to ./db/platforms/PLATFORM/*.txt.STAMP.queued func queuePlatform(entryPath, gosDir, platform string) error { - destDir := filepath.Join(gosDir, "db/platform", strings.ToLower(platform)) + destDir := filepath.Join(gosDir, "db/platforms", strings.ToLower(platform)) destPath := filepath.Join(destDir, filepath.Base(entryPath)) postedFile := fmt.Sprintf("%s.posted", strings.TrimSuffix(destPath, ".queued")) diff --git a/internal/run.go b/internal/run.go index 51573f5..4d600f0 100644 --- a/internal/run.go +++ b/internal/run.go @@ -20,8 +20,10 @@ func Run(ctx context.Context, args config.Args) error { switch { case errors.Is(err, schedule.ErrNothingToSchedule): log.Println("Nothing to be scheduled for", platform) + return nil case errors.Is(err, schedule.ErrNothingQueued): log.Println("Nothing queued for", platform) + return nil case err != nil: return err } diff --git a/internal/schedule/schedule.go b/internal/schedule/schedule.go index 171f208..b85e6a8 100644 --- a/internal/schedule/schedule.go +++ b/internal/schedule/schedule.go @@ -33,10 +33,12 @@ func Run(args config.Args, platform string) (entry.Entry, error) { // Schedule random qeued entry for platform ent, err := oi.ReadDirRandom(dir, func(file os.DirEntry) (entry.Entry, bool) { - if ent, err := entry.New(filepath.Join(dir, file.Name())); err != nil { - return ent, ent.State == entry.Queued + ent, err := entry.New(filepath.Join(dir, file.Name())) + if err != nil { + log.Println(err) + return entry.Zero, false } - return entry.Zero, false + return ent, ent.State == entry.Queued }) if err != nil { diff --git a/internal/schedule/stats.go b/internal/schedule/stats.go index 919d0a1..847aead 100644 --- a/internal/schedule/stats.go +++ b/internal/schedule/stats.go @@ -21,7 +21,7 @@ type stats struct { } func (s stats) String() string { - return fmt.Sprintf("posted:%d,queued:%d,sinceDays:%v,postsPerDay:%v >? %v", + return fmt.Sprintf("posted:%d,queued:%d,sinceDays:%v,postsPerDay:%v >? postsPerDayTarget:%v", s.posted, s.queued, s.sinceDays, s.postsPerDay, s.postsPerDayTarget, ) } @@ -40,7 +40,7 @@ func newStats(dir string, lookback time.Duration, target int) (stats, error) { } func (s stats) targetHit() bool { - return s.postsPerDayTarget <= s.postsPerDay + return s.postsPerDay >= s.postsPerDayTarget } func (s *stats) gatherPostedStats(dir string, lookbackTime time.Time) error { |
