mirror of
https://github.com/jc21/nginx-proxy-manager.git
synced 2024-08-30 18:22:48 +00:00
37 lines
624 B
Go
37 lines
624 B
Go
|
package jobqueue
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"npm/internal/logger"
|
||
|
)
|
||
|
|
||
|
// Worker responsible for queue serving.
|
||
|
type Worker struct {
|
||
|
Queue *Queue
|
||
|
}
|
||
|
|
||
|
func newWorker(queue *Queue) *Worker {
|
||
|
return &Worker{
|
||
|
Queue: queue,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// doWork processes jobs from the queue (jobs channel).
|
||
|
func (w *Worker) doWork() bool {
|
||
|
for {
|
||
|
select {
|
||
|
// if context was canceled.
|
||
|
case <-w.Queue.ctx.Done():
|
||
|
logger.Info("JobQueue worker graceful shutdown")
|
||
|
return true
|
||
|
// if job received.
|
||
|
case job := <-w.Queue.jobs:
|
||
|
err := job.Run()
|
||
|
if err != nil {
|
||
|
logger.Error(fmt.Sprintf("%sError", job.Name), err)
|
||
|
continue
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|