Merge remote-tracking branch 'origin/main' into feat/audiobooks
# Conflicts: # go.sum
This commit is contained in:
@@ -77,7 +77,7 @@ func (m *TaskManager) Start(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
w.setTriggers(configs, m.triggerFactory, w.lastResult)
|
||||
w.setTriggers(configs, m.triggerFactory, w.lastResult, false)
|
||||
|
||||
go m.triggerLoop(ctx, w)
|
||||
}
|
||||
@@ -261,7 +261,7 @@ func (m *TaskManager) UpdateTriggers(key string, triggerConfigs []TriggerConfig)
|
||||
return err
|
||||
}
|
||||
|
||||
w.setTriggers(triggerConfigs, m.triggerFactory, nil)
|
||||
w.setTriggers(triggerConfigs, m.triggerFactory, nil, true)
|
||||
m.notifyTaskUpdated(w.info())
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ func (w *taskWorker) info() TaskInfo {
|
||||
// setTriggers replaces active triggers. Stops old triggers, starts new ones.
|
||||
// Pass lastResult to resume scheduling from the last execution, or nil to
|
||||
// start the interval fresh from now (e.g. when the user edits the schedule).
|
||||
func (w *taskWorker) setTriggers(configs []TriggerConfig, factory func(TriggerConfig) Trigger, lastResult *ExecutionResult) {
|
||||
func (w *taskWorker) setTriggers(configs []TriggerConfig, factory func(TriggerConfig) Trigger, lastResult *ExecutionResult, notify bool) {
|
||||
w.mu.Lock()
|
||||
|
||||
for _, tr := range w.triggers {
|
||||
@@ -90,8 +90,12 @@ func (w *taskWorker) setTriggers(configs []TriggerConfig, factory func(TriggerCo
|
||||
|
||||
w.mu.Unlock()
|
||||
|
||||
w.triggerChanged.Store(true)
|
||||
if !notify {
|
||||
w.notify()
|
||||
return
|
||||
}
|
||||
|
||||
w.triggerChanged.Store(true)
|
||||
select {
|
||||
case w.triggerUpdate <- struct{}{}:
|
||||
default:
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package taskmanager
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type testTask struct{}
|
||||
|
||||
func (testTask) Key() string { return "test" }
|
||||
func (testTask) Name() string { return "test" }
|
||||
func (testTask) Description() string { return "test" }
|
||||
func (testTask) Category() TaskCategory { return TaskCategorySystem }
|
||||
func (testTask) IsHidden() bool { return false }
|
||||
func (testTask) DefaultTriggers() []TriggerConfig { return nil }
|
||||
func (testTask) Execute(context.Context, ProgressReporter) error { return nil }
|
||||
|
||||
type testTrigger struct {
|
||||
ch chan struct{}
|
||||
}
|
||||
|
||||
func newTestTrigger(TriggerConfig) Trigger {
|
||||
return &testTrigger{ch: make(chan struct{}, 1)}
|
||||
}
|
||||
|
||||
func (t *testTrigger) Start(*ExecutionResult) {
|
||||
t.ch <- struct{}{}
|
||||
}
|
||||
|
||||
func (t *testTrigger) Stop() {}
|
||||
func (t *testTrigger) NextRunTime() time.Time { return time.Time{} }
|
||||
func (t *testTrigger) Config() TriggerConfig { return TriggerConfig{} }
|
||||
func (t *testTrigger) C() <-chan struct{} { return t.ch }
|
||||
|
||||
func TestInitialSetTriggersDoesNotMarkTriggerChanged(t *testing.T) {
|
||||
worker := newTaskWorker(testTask{}, nil)
|
||||
worker.setTriggers([]TriggerConfig{{Type: TriggerTypeInterval, IntervalMs: 1}}, newTestTrigger, nil, false)
|
||||
|
||||
if worker.triggerChanged.Load() {
|
||||
t.Fatal("initial trigger setup should not mark triggers changed")
|
||||
}
|
||||
select {
|
||||
case <-worker.triggerUpdate:
|
||||
t.Fatal("initial trigger setup should not queue a trigger update")
|
||||
default:
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user