Skip to content

Commit

Permalink
Log workerID
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy-max committed Jun 9, 2019
1 parent e2386f0 commit 76f0c30
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions internal/app/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func (di *Diun) StartDispatcher(workerCount int) Collector {
for i < workerCount {
i++
worker := worker{
id: i,
diun: di,
workerPool: workerChannel,
jobChannel: make(chan Job),
Expand Down
14 changes: 7 additions & 7 deletions internal/app/diun.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,18 @@ func (di *Diun) Run() {
wg.Wait()
}

func (di *Diun) analyze(job Job) error {
func (di *Diun) analyze(job Job, workerID int) error {
defer job.Wg.Done()
image, err := registry.ParseImage(job.ImageStr)
if err != nil {
return err
}

if !utl.IsIncluded(image.Tag, job.Item.IncludeTags) {
log.Warn().Str("image", image.String()).Msg("Tag not included")
log.Warn().Str("image", image.String()).Int("worker_id", workerID).Msg("Tag not included")
return nil
} else if utl.IsExcluded(image.Tag, job.Item.ExcludeTags) {
log.Warn().Str("image", image.String()).Msg("Tag excluded")
log.Warn().Str("image", image.String()).Int("worker_id", workerID).Msg("Tag excluded")
return nil
}

Expand All @@ -152,19 +152,19 @@ func (di *Diun) analyze(job Job) error {
status := model.ImageStatusUnchange
if dbManifest.Name == "" {
status = model.ImageStatusNew
log.Info().Str("image", image.String()).Msg("New image found")
log.Info().Str("image", image.String()).Int("worker_id", workerID).Msg("New image found")
} else if !liveManifest.Created.Equal(*dbManifest.Created) {
status = model.ImageStatusUpdate
log.Info().Str("image", image.String()).Msg("Image update found")
log.Info().Str("image", image.String()).Int("worker_id", workerID).Msg("Image update found")
} else {
log.Debug().Str("image", image.String()).Msg("No changes")
log.Debug().Str("image", image.String()).Int("worker_id", workerID).Msg("No changes")
return nil
}

if err := di.db.PutManifest(image, liveManifest); err != nil {
return err
}
log.Debug().Str("image", image.String()).Msg("Manifest saved to database")
log.Debug().Str("image", image.String()).Int("worker_id", workerID).Msg("Manifest saved to database")

di.notif.Send(model.NotifEntry{
Status: status,
Expand Down
8 changes: 6 additions & 2 deletions internal/app/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Job struct {
}

type worker struct {
id int
diun *Diun
workerPool chan chan Job
jobChannel chan Job
Expand All @@ -29,8 +30,11 @@ func (w *worker) Start() {
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")
if err := w.diun.analyze(job, w.id); err != nil {
log.Error().Err(err).
Str("image", job.ImageStr).
Int("worker_id", w.id).
Msg("Error analyzing image")
}
case <-w.end:
return
Expand Down

0 comments on commit 76f0c30

Please sign in to comment.