mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-27 04:35:16 +01:00
Merge pull request #2866 from reasonerjt/master
fix #1953, fail jobservice when configuration init encounters errors.
This commit is contained in:
commit
9d02fc1c70
@ -16,6 +16,7 @@ package job
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/vmware/harbor/src/common/models"
|
||||
"github.com/vmware/harbor/src/common/utils/log"
|
||||
@ -33,6 +34,9 @@ type workerPool struct {
|
||||
// WorkerPools is a map contains workerpools for different types of jobs.
|
||||
var WorkerPools map[Type]*workerPool
|
||||
|
||||
// For WorkerPools initialization.
|
||||
var once sync.Once
|
||||
|
||||
//TODO: remove the hard code?
|
||||
const maxScanWorker = 3
|
||||
|
||||
@ -118,16 +122,15 @@ func NewWorker(id int, t Type, wp *workerPool) *Worker {
|
||||
|
||||
// InitWorkerPools create worker pools for different types of jobs.
|
||||
func InitWorkerPools() error {
|
||||
if len(WorkerPools) > 0 {
|
||||
return fmt.Errorf("The WorkerPool map has been initialised")
|
||||
}
|
||||
maxRepWorker, err := config.MaxJobWorkers()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
WorkerPools = make(map[Type]*workerPool)
|
||||
WorkerPools[ReplicationType] = createWorkerPool(maxRepWorker, ReplicationType)
|
||||
WorkerPools[ScanType] = createWorkerPool(maxScanWorker, ScanType)
|
||||
once.Do(func() {
|
||||
WorkerPools = make(map[Type]*workerPool)
|
||||
WorkerPools[ReplicationType] = createWorkerPool(maxRepWorker, ReplicationType)
|
||||
WorkerPools[ScanType] = createWorkerPool(maxScanWorker, ScanType)
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,9 @@ func main() {
|
||||
}
|
||||
|
||||
initRouters()
|
||||
job.InitWorkerPools()
|
||||
if err := job.InitWorkerPools(); err != nil {
|
||||
log.Fatalf("Failed to initialize worker pools, error: %v", err)
|
||||
}
|
||||
go job.Dispatch()
|
||||
resumeJobs()
|
||||
beego.Run()
|
||||
@ -71,6 +73,8 @@ func init() {
|
||||
configPath := os.Getenv("CONFIG_PATH")
|
||||
if len(configPath) != 0 {
|
||||
log.Infof("Config path: %s", configPath)
|
||||
beego.LoadAppConfig("ini", configPath)
|
||||
if err := beego.LoadAppConfig("ini", configPath); err != nil {
|
||||
log.Fatalf("Failed to load config file: %s, error: %v", configPath, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user