summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-09-28 12:08:58 +0300
committerPaul Buetow <paul@buetow.org>2024-09-28 12:08:58 +0300
commitc76ba11dc4ae23ab17115b87d0d2b9711ffdbf01 (patch)
tree86f33c1b22d0fc4be27357cc5f68006bfa8b321a
parent076c0d5afb299fedc5ee61a13bfec7f86055fc89 (diff)
fix this
-rw-r--r--internal/oi/oi.go4
-rw-r--r--internal/run.go5
-rw-r--r--internal/schedule/schedule.go15
3 files changed, 19 insertions, 5 deletions
diff --git a/internal/oi/oi.go b/internal/oi/oi.go
index 27112bf..ca5c8c6 100644
--- a/internal/oi/oi.go
+++ b/internal/oi/oi.go
@@ -11,6 +11,8 @@ import (
"golang.org/x/exp/rand"
)
+var ErrNotFound = errors.New("no file/entry found")
+
func EnsureDirExists(dir string) error {
if _, err := os.Stat(dir); os.IsNotExist(err) {
return os.MkdirAll(dir, os.ModePerm)
@@ -67,7 +69,7 @@ func ReadDirRandomEntry(dir string, filter func(file os.DirEntry) bool) (string,
return "", err
}
if len(files) == 0 {
- return "", errors.New("no entry/file found")
+ return "", ErrNotFound
}
rand.Seed(uint64(time.Now().UnixNano()))
diff --git a/internal/run.go b/internal/run.go
index 427384d..ea70bec 100644
--- a/internal/run.go
+++ b/internal/run.go
@@ -2,6 +2,7 @@ package internal
import (
"context"
+ "errors"
"log"
"codeberg.org/snonux/gos/internal/config"
@@ -20,8 +21,10 @@ func Run(ctx context.Context, args config.Args) error {
case nil:
log.Println("Scheduling", path)
// TODO: Implement action here to post it
- case schedule.NothingToSchedule:
+ case schedule.ErrNothingToSchedule:
log.Println("Nothing to be scheduled for", platform)
+ case schedule.ErrNothingQueued
+ log.Println("Nothing queued for", platform)
default:
return err
}
diff --git a/internal/schedule/schedule.go b/internal/schedule/schedule.go
index d8b7143..82afc18 100644
--- a/internal/schedule/schedule.go
+++ b/internal/schedule/schedule.go
@@ -11,7 +11,10 @@ import (
"codeberg.org/snonux/gos/internal/oi"
)
-var NothingToSchedule = errors.New("nothing to schedule")
+var (
+ ErrNothingToSchedule = errors.New("nothing to schedule")
+ ErrNothingQueued = errors.New("nothing queued")
+)
func Run(args config.Args, platform string) (string, error) {
dir := fmt.Sprintf("%s/db/platforms/%s", args.GosDir, strings.ToLower(platform))
@@ -23,11 +26,17 @@ func Run(args config.Args, platform string) (string, error) {
log.Println("For", platform, "stats:", stats)
if stats.targetHit() {
log.Println("Target hit, not posting at", platform)
- return "", NothingToSchedule
+ return "", ErrNothingToSchedule
}
// Schedule random qeued entry for platform
- return oi.ReadDirRandomEntry(dir, func(file os.DirEntry) bool {
+ randomEntry, err := oi.ReadDirRandomEntry(dir, func(file os.DirEntry) bool {
return strings.HasSuffix(file.Name(), ".queued")
})
+
+ if err != nil {
+ // TODO: FIX THIS
+ return randomEntry, fmt.Errorf("%w: %w", ErrNothingQueued, err)
+ }
+ return randomEntry, nil
}