Compare commits
No commits in common. "ff2dc9f7da03d6628e81d86b00fde250ef13a30b" and "d6c3a1a2c3884df2a81e346e3707872f4f31fcf5" have entirely different histories.
ff2dc9f7da
...
d6c3a1a2c3
2
go.mod
2
go.mod
@ -1,3 +1,3 @@
|
|||||||
module git.canoozie.net/jer/task
|
module git.canoozie.net/jer/task.git
|
||||||
|
|
||||||
go 1.23.2
|
go 1.23.2
|
||||||
|
7
task.go
7
task.go
@ -44,12 +44,11 @@ func (te *TaskExecutor) AddTask(task Task, interval time.Duration) {
|
|||||||
case te.taskChan <- st:
|
case te.taskChan <- st:
|
||||||
log.Printf("Task %T queued up with interval %v\n", task, interval)
|
log.Printf("Task %T queued up with interval %v\n", task, interval)
|
||||||
default:
|
default:
|
||||||
log.Printf("Failed to add task %T with interval %v, channel full\n", task, interval)
|
log.Printf("Failed to add task $T with interval %v, channel full\n", task, interval)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (te *TaskExecutor) Start() {
|
func (te *TaskExecutor) Start() {
|
||||||
// Launch the task processor goroutine
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
@ -79,10 +78,6 @@ func (te *TaskExecutor) Start() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Process any tasks already in the channel before returning
|
|
||||||
// This ensures that when Start() returns, all queued tasks are in the tasks slice
|
|
||||||
time.Sleep(10 * time.Millisecond)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (te *TaskExecutor) shouldRun(st *ScheduledTask, t time.Time) bool {
|
func (te *TaskExecutor) shouldRun(st *ScheduledTask, t time.Time) bool {
|
||||||
|
@ -16,8 +16,6 @@ func (m *mockTask) Execute() error {
|
|||||||
func TestAddTask(t *testing.T) {
|
func TestAddTask(t *testing.T) {
|
||||||
te := NewTaskExecutor(10)
|
te := NewTaskExecutor(10)
|
||||||
te.AddTask(&mockTask{}, 1*time.Second)
|
te.AddTask(&mockTask{}, 1*time.Second)
|
||||||
te.Start()
|
|
||||||
// No need for explicit sleep now, as Start() ensures tasks are processed
|
|
||||||
if te.Len() != 1 {
|
if te.Len() != 1 {
|
||||||
t.Errorf("expected 1 task, got %d", te.Len())
|
t.Errorf("expected 1 task, got %d", te.Len())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user