summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/gos/main.go2
-rw-r--r--internal/config/args.go3
-rw-r--r--internal/schedule/schedule.go2
-rw-r--r--internal/schedule/stats.go21
4 files changed, 20 insertions, 8 deletions
diff --git a/cmd/gos/main.go b/cmd/gos/main.go
index 67f3351..1248239 100644
--- a/cmd/gos/main.go
+++ b/cmd/gos/main.go
@@ -19,12 +19,14 @@ func main() {
version := flag.Bool("version", false, "Display version")
gosDir := flag.String("gosDir", "./gosdir", "Gos' directory")
platforms := flag.String("platforms", "Mastodon,LinkedIn", "Platforms enabled")
+ lookback := flag.Int("lookback", 30, "How many days look back in time for posting history")
flag.Parse()
args := config.Args{
DryRun: *dry,
GosDir: *gosDir,
Platforms: strings.Split(*platforms, ","),
+ Lookback: time.Duration(*lookback) * time.Hour * 24,
}
if *version {
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!