From b2686ea602119d674a6c074e629bdd592ebdf933 Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Fri, 3 Apr 2026 14:03:45 +0200 Subject: [PATCH] polling on file changes should work now --- cmd/pm/tasks/codingTask.go | 26 +++++++++++++++++++++++++- cmd/pm/tasks/gitTask.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/cmd/pm/tasks/codingTask.go b/cmd/pm/tasks/codingTask.go index 381b6d4..f9db043 100644 --- a/cmd/pm/tasks/codingTask.go +++ b/cmd/pm/tasks/codingTask.go @@ -104,10 +104,34 @@ func (t *CodingTask) Setup(ctx context.Context) error { return err } + go func() { + ticker := time.NewTicker(1 * time.Second) + defer ticker.Stop() + lastMod := t.lastModified + + for { + select { + case <-ticker.C: + if stat, err := os.Stat("./code.txt"); err == nil { + if stat.ModTime().After(lastMod) { + lastMod = stat.ModTime() + if t.app.SubmitChan != nil { + select { + case t.app.SubmitChan <- models.ValidationTrigger{Source: models.ValidationTriggerAutoPoll}: + default: + } + } + } + } + case <-ctx.Done(): + return + } + } + }() + return nil } - func (t *CodingTask) Validate(ctx context.Context) ValidationFeedback { expect := check.NewExpector() diff --git a/cmd/pm/tasks/gitTask.go b/cmd/pm/tasks/gitTask.go index 92450f3..efeb3e7 100644 --- a/cmd/pm/tasks/gitTask.go +++ b/cmd/pm/tasks/gitTask.go @@ -104,6 +104,35 @@ func (t *GitTask) Setup(ctx context.Context) error { return err } + go func() { + ticker := time.NewTicker(1 * time.Second) + defer ticker.Stop() + var lastMod time.Time + + if stat, err := os.Stat("./task/.git/index"); err == nil { + lastMod = stat.ModTime() + } + + for { + select { + case <-ticker.C: + if stat, err := os.Stat("./task/.git/index"); err == nil { + if stat.ModTime().After(lastMod) { + lastMod = stat.ModTime() + if t.app.SubmitChan != nil { + select { + case t.app.SubmitChan <- models.ValidationTrigger{Source: models.ValidationTriggerAutoPoll}: + default: + } + } + } + } + case <-ctx.Done(): + return + } + } + }() + return nil }