mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-23 10:45:45 +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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/vmware/harbor/src/common/models"
|
"github.com/vmware/harbor/src/common/models"
|
||||||
"github.com/vmware/harbor/src/common/utils/log"
|
"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.
|
// WorkerPools is a map contains workerpools for different types of jobs.
|
||||||
var WorkerPools map[Type]*workerPool
|
var WorkerPools map[Type]*workerPool
|
||||||
|
|
||||||
|
// For WorkerPools initialization.
|
||||||
|
var once sync.Once
|
||||||
|
|
||||||
//TODO: remove the hard code?
|
//TODO: remove the hard code?
|
||||||
const maxScanWorker = 3
|
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.
|
// InitWorkerPools create worker pools for different types of jobs.
|
||||||
func InitWorkerPools() error {
|
func InitWorkerPools() error {
|
||||||
if len(WorkerPools) > 0 {
|
|
||||||
return fmt.Errorf("The WorkerPool map has been initialised")
|
|
||||||
}
|
|
||||||
maxRepWorker, err := config.MaxJobWorkers()
|
maxRepWorker, err := config.MaxJobWorkers()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
WorkerPools = make(map[Type]*workerPool)
|
once.Do(func() {
|
||||||
WorkerPools[ReplicationType] = createWorkerPool(maxRepWorker, ReplicationType)
|
WorkerPools = make(map[Type]*workerPool)
|
||||||
WorkerPools[ScanType] = createWorkerPool(maxScanWorker, ScanType)
|
WorkerPools[ReplicationType] = createWorkerPool(maxRepWorker, ReplicationType)
|
||||||
|
WorkerPools[ScanType] = createWorkerPool(maxScanWorker, ScanType)
|
||||||
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
initRouters()
|
initRouters()
|
||||||
job.InitWorkerPools()
|
if err := job.InitWorkerPools(); err != nil {
|
||||||
|
log.Fatalf("Failed to initialize worker pools, error: %v", err)
|
||||||
|
}
|
||||||
go job.Dispatch()
|
go job.Dispatch()
|
||||||
resumeJobs()
|
resumeJobs()
|
||||||
beego.Run()
|
beego.Run()
|
||||||
@ -71,6 +73,8 @@ func init() {
|
|||||||
configPath := os.Getenv("CONFIG_PATH")
|
configPath := os.Getenv("CONFIG_PATH")
|
||||||
if len(configPath) != 0 {
|
if len(configPath) != 0 {
|
||||||
log.Infof("Config path: %s", configPath)
|
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