summaryrefslogtreecommitdiff
path: root/internal/schedule
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-11-04 23:17:50 +0200
committerPaul Buetow <paul@buetow.org>2024-11-04 23:17:50 +0200
commitc3f0011ec9f09ba5481b54ba7edbc71cdd8ff33f (patch)
tree98935b3d030c4dc0d5c49be94857c8355cb8e1a7 /internal/schedule
parent5c557a08db23b01e5a953f0503db1f705de666fa (diff)
increase rate when there are soo posts scheduled
Diffstat (limited to 'internal/schedule')
-rw-r--r--internal/schedule/schedule.go3
-rw-r--r--internal/schedule/stats.go35
2 files changed, 22 insertions, 16 deletions
diff --git a/internal/schedule/schedule.go b/internal/schedule/schedule.go
index 3828b07..7144a4d 100644
--- a/internal/schedule/schedule.go
+++ b/internal/schedule/schedule.go
@@ -20,7 +20,6 @@ var (
ErrNothingQueued = errors.New("nothing queued")
)
-// TODO: Schedule more than N entries per week when the backlog of queued items is large enough.
func Run(args config.Args, platform string) (entry.Entry, error) {
dir := fmt.Sprintf("%s/db/platforms/%s", args.GosDir, strings.ToLower(platform))
stats, err := newStats(dir, args.Lookback, args.Target)
@@ -40,7 +39,7 @@ func Run(args config.Args, platform string) (entry.Entry, error) {
if err != nil && !errors.Is(err, oi.ErrNotFound) {
return en, nil // Unknown error
}
- if !en.HasTag("now") && stats.targetHit(args.PauseDays) {
+ if !en.HasTag("now") && stats.targetHit(args.PauseDays, args.MaxDaysQueued) {
return entry.Zero, ErrNothingToSchedule
}
return en, nil
diff --git a/internal/schedule/stats.go b/internal/schedule/stats.go
index 4672f0e..0966efe 100644
--- a/internal/schedule/stats.go
+++ b/internal/schedule/stats.go
@@ -19,12 +19,26 @@ import (
type stats struct {
posted int
queued int
+ queuedForDays float64
sinceDays float64
postsPerDay float64
postsPerDayTarget float64
lastPostDaysAgo float64
}
+func newStats(dir string, lookback time.Duration, target int) (stats, error) {
+ s := stats{postsPerDayTarget: float64(target) / 7}
+
+ if err := s.gatherPostedStats(dir, pastTime(lookback)); err != nil {
+ return s, err
+ }
+ if err := s.gatherQueuedStats(dir); err != nil {
+ return s, err
+ }
+
+ return s, nil
+}
+
func (s stats) String() string {
return fmt.Sprintf("posted:%d,queued:%d,sinceDays:%v,postsPerDayTarget:%v>?%v,lastPostDaysAgo:%v",
s.posted, s.queued, s.sinceDays, s.postsPerDay, s.postsPerDayTarget, s.lastPostDaysAgo,
@@ -47,7 +61,7 @@ func (s stats) Render(platform string) {
sb.WriteString("\n")
sb.WriteString(colour.Sstatsf("| %-20s | %-11s |", "#Queued entries", strconv.Itoa(s.queued)))
sb.WriteString("\n")
- sb.WriteString(colour.Sstatsf("| %-20s | %-11s |", "Enough for (days)", fmt.Sprintf("%.02f", float64(s.queued)/s.postsPerDayTarget)))
+ sb.WriteString(colour.Sstatsf("| %-20s | %-11s |", "Enough for (days)", fmt.Sprintf("%.02f", s.queuedForDays)))
sb.WriteString("\n")
sb.WriteString(colour.Sstatsf("| %-20s | %-11s |", "Last post (days ago)", fmt.Sprintf("%.02f", s.lastPostDaysAgo)))
sb.WriteString("\n")
@@ -61,20 +75,11 @@ func (s stats) Render(platform string) {
fmt.Print(sb.String())
}
-func newStats(dir string, lookback time.Duration, target int) (stats, error) {
- stats := stats{postsPerDayTarget: float64(target) / 7}
-
- if err := stats.gatherPostedStats(dir, pastTime(lookback)); err != nil {
- return stats, err
+func (s stats) targetHit(pauseDays, maxQueuedDays int) bool {
+ if s.queuedForDays > float64(maxQueuedDays) {
+ s.postsPerDayTarget++
+ pauseDays--
}
- if err := stats.gatherQueuedStats(dir); err != nil {
- return stats, err
- }
-
- return stats, nil
-}
-
-func (s stats) targetHit(pauseDays int) bool {
if s.postsPerDay >= s.postsPerDayTarget {
log.Println("Posts per day target hit")
return true
@@ -146,6 +151,8 @@ func (s *stats) gatherQueuedStats(dir string) error {
return nil
})
+ s.queuedForDays = float64(s.queued) / s.postsPerDayTarget
+
return err
}