woj-server/pkg/pool/worker.go
Paul Pan 6956fe4ee1
feat: capture runtime status from cgroups
pkg/pool: task is now available to return interface{} as result
pkg/pool: use atomic instead of mutex
service/runner: ContainerRun will return metrics
2024-02-15 12:53:57 +08:00

25 lines
440 B
Go

package pool
import (
"sync"
)
type Worker struct {
id int
queue chan Task
pool *TaskPool // back reference to the pool
}
func NewWorker(id int, queue chan Task, pool *TaskPool) *Worker {
return &Worker{id: id, queue: queue, pool: pool}
}
func (w *Worker) Start(wg *sync.WaitGroup) {
defer wg.Done()
for task := range w.queue {
val, err := task.f()
w.pool.markTaskComplete(task.id, WaitBuf{Value: val, Error: err})
}
}