mirror of
https://github.com/crazy-max/diun.git
synced 2025-12-21 13:23:09 +01:00
46 lines
838 B
Go
46 lines
838 B
Go
package app
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/crazy-max/diun/internal/model"
|
|
"github.com/crazy-max/diun/pkg/docker"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
type Job struct {
|
|
ImageStr string
|
|
Item model.Item
|
|
Reg *docker.RegistryClient
|
|
Wg *sync.WaitGroup
|
|
}
|
|
|
|
type worker struct {
|
|
diun *Diun
|
|
workerPool chan chan Job
|
|
jobChannel chan Job
|
|
end chan bool
|
|
}
|
|
|
|
// Start method starts the run loop for the worker
|
|
func (w *worker) Start() {
|
|
go func() {
|
|
for {
|
|
w.workerPool <- w.jobChannel
|
|
select {
|
|
case job := <-w.jobChannel:
|
|
if err := w.diun.analyze(job); err != nil {
|
|
log.Error().Err(err).Str("image", job.ImageStr).Msg("Error analyzing image")
|
|
}
|
|
case <-w.end:
|
|
return
|
|
}
|
|
}
|
|
}()
|
|
}
|
|
|
|
// Stop signals the worker to stop listening for work requests.
|
|
func (w *worker) Stop() {
|
|
w.end <- true
|
|
}
|