summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Schlachter <t480-debian-git@schlachter.ca>2025-11-10 00:24:57 -0500
committerDavid Schlachter <t480-debian-git@schlachter.ca>2025-11-10 00:24:57 -0500
commitb78ce8899f0776db7a08d1f054e017c43ff08821 (patch)
tree99e0792cea4e64a78f32a635cc6db680d253d137
parent282df9321e7911285aa18673fdeb562298890b41 (diff)
Fix change detection
-rw-r--r--main.go34
1 files changed, 24 insertions, 10 deletions
diff --git a/main.go b/main.go
index f837340..8d104b7 100644
--- a/main.go
+++ b/main.go
@@ -17,6 +17,10 @@ import (
"github.com/robfig/cron/v3"
)
+type InputLine struct {
+ RawSchedule, RawTask string
+}
+
type TaskAddingJob struct {
Schedule cron.Schedule
Task cron.Job
@@ -30,7 +34,7 @@ func (t Task) Run() {
createTask(t.Name)
}
-var lastSeenInput = map[TaskAddingJob]struct{}{}
+var lastSeenInput = map[InputLine]TaskAddingJob{}
var todoistToken string
var httpClient = http.Client{
Timeout: 10 * time.Second,
@@ -99,8 +103,8 @@ func inputFilePath() (string, error) {
var inputFileRe = regexp.MustCompile(`([^\s]+\s+[^\s]+\s+[^\s]+\s+[^\s]+\s+[^\s]+)\s+(.*)`)
-func readInput(p string) (map[TaskAddingJob]struct{}, error) {
- input := map[TaskAddingJob]struct{}{}
+func readInput(p string) (map[InputLine]TaskAddingJob, error) {
+ input := map[InputLine]TaskAddingJob{}
f, err := os.Open(p)
if err != nil {
@@ -121,14 +125,24 @@ func readInput(p string) (map[TaskAddingJob]struct{}, error) {
continue
}
- schedule, err := cron.ParseStandard(matches[1])
+ inputLine := InputLine{
+ RawSchedule: matches[1],
+ RawTask: matches[2],
+ }
+
+ schedule, err := cron.ParseStandard(inputLine.RawSchedule)
if err != nil {
- log.Printf("Failed to add '%s' with recurrence '%s': %s", matches[2], matches[1], err)
+ log.Printf("Failed to add '%s' with recurrence '%s': %s", inputLine.RawTask, inputLine.RawSchedule, err)
continue
}
- job := Task{Name: matches[2]}
+ job := Task{Name: inputLine.RawTask}
+
+ taskAddingJob := TaskAddingJob{
+ Schedule: schedule,
+ Task: job,
+ }
- input[TaskAddingJob{Schedule: schedule, Task: job}] = struct{}{}
+ input[inputLine] = taskAddingJob
}
if err := scanner.Err(); err != nil {
@@ -138,7 +152,7 @@ func readInput(p string) (map[TaskAddingJob]struct{}, error) {
return input, nil
}
-func inputChanged(old, new map[TaskAddingJob]struct{}) bool {
+func inputChanged(old, new map[InputLine]TaskAddingJob) bool {
if len(new) != len(old) {
return true
}
@@ -183,8 +197,8 @@ func createTask(task string) {
}
}
-func addJobs(c *cron.Cron, tasks map[TaskAddingJob]struct{}) {
- for task := range tasks {
+func addJobs(c *cron.Cron, tasks map[InputLine]TaskAddingJob) {
+ for _, task := range tasks {
_ = c.Schedule(task.Schedule, task.Task)
}
log.Printf("Added %d jobs", len(tasks))