summaryrefslogtreecommitdiff
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
parent5c557a08db23b01e5a953f0503db1f705de666fa (diff)
increase rate when there are soo posts scheduled
-rw-r--r--cmd/gos/main.go2
-rw-r--r--internal/colour/colour.go5
-rw-r--r--internal/config/args.go1
-rw-r--r--internal/schedule/schedule.go3
-rw-r--r--internal/schedule/stats.go35
5 files changed, 29 insertions, 17 deletions
diff --git a/cmd/gos/main.go b/cmd/gos/main.go
index a14ba57..8e9e4e8 100644
--- a/cmd/gos/main.go
+++ b/cmd/gos/main.go
@@ -25,6 +25,7 @@ func main() {
platforms := flag.String("platforms", "Mastodon:500,LinkedIn:1000", "Platforms enabled plus their post size limits")
target := flag.Int("target", 2, "How many posts per week are the target?")
minQueued := flag.Int("minQueued", 4, "Minimum of queued items until printing a warn message!")
+ maxDaysQueued := flag.Int("maxDaysQueued", 365, "Maximum days worth of queued posts until target++ and pauseDays--")
pauseDays := flag.Int("pauseDays", 3, "How many days until next post can be posted?")
lookback := flag.Int("lookback", 30, "How many days look back in time for posting history")
flag.Parse()
@@ -40,6 +41,7 @@ func main() {
Platforms: make(map[string]int),
Target: *target,
MinQueued: *minQueued,
+ MaxDaysQueued: *maxDaysQueued,
PauseDays: *pauseDays,
Lookback: time.Duration(*lookback) * time.Hour * 24,
SecretsConfigPath: secretsConfigPath,
diff --git a/internal/colour/colour.go b/internal/colour/colour.go
index 03ae8c4..d003f65 100644
--- a/internal/colour/colour.go
+++ b/internal/colour/colour.go
@@ -3,9 +3,12 @@ package colour
import "github.com/fatih/color"
var (
+ // Printf function(s)
Info1f = color.New(color.FgCyan, color.BgBlue, color.Bold).PrintfFunc()
Info2f = color.New(color.FgHiYellow, color.BgHiBlack, color.Bold).PrintfFunc()
- Sstatsf = color.New(color.FgHiYellow, color.BgBlue).SprintfFunc()
Ackf = color.New(color.FgBlack, color.BgHiYellow, color.Bold).PrintfFunc()
Successf = color.New(color.FgWhite, color.BgGreen).PrintfFunc()
+
+ // Sprintf function(s)
+ Sstatsf = color.New(color.FgHiYellow, color.BgBlue).SprintfFunc()
)
diff --git a/internal/config/args.go b/internal/config/args.go
index b22ff95..4d65297 100644
--- a/internal/config/args.go
+++ b/internal/config/args.go
@@ -17,6 +17,7 @@ type Args struct {
Platforms map[string]int // Platform name and post size limits
Target int
MinQueued int
+ MaxDaysQueued int
PauseDays int
Lookback time.Duration
SecretsConfigPath string
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
}