harbor/src/jobservice/main.go

81 lines
2.3 KiB
Go
Raw Normal View History

2017-04-13 12:54:58 +02:00
// Copyright (c) 2017 VMware, Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2016-06-16 08:57:45 +02:00
2016-04-20 08:24:17 +02:00
package main
import (
2017-01-12 11:29:02 +01:00
"os"
2016-04-20 08:24:17 +02:00
"github.com/astaxie/beego"
2016-10-19 08:32:00 +02:00
"github.com/vmware/harbor/src/common/dao"
"github.com/vmware/harbor/src/common/models"
"github.com/vmware/harbor/src/common/utils/log"
2016-12-30 11:04:01 +01:00
"github.com/vmware/harbor/src/jobservice/config"
"github.com/vmware/harbor/src/jobservice/job"
2016-04-20 08:24:17 +02:00
)
func main() {
2016-12-30 11:04:01 +01:00
log.Info("initializing configurations...")
if err := config.Init(); err != nil {
log.Fatalf("failed to initialize configurations: %v", err)
}
log.Info("configurations initialization completed")
database, err := config.Database()
if err != nil {
log.Fatalf("failed to get database configurations: %v", err)
}
if err := dao.InitDatabase(database); err != nil {
log.Fatalf("failed to initialize database: %v", err)
}
2016-04-20 08:24:17 +02:00
initRouters()
2017-07-25 15:12:03 +02:00
if err := job.InitWorkerPools(); err != nil {
log.Fatalf("Failed to initialize worker pools, error: %v", err)
}
go job.Dispatch()
resumeJobs()
2016-04-20 08:24:17 +02:00
beego.Run()
}
func resumeJobs() {
2017-05-23 07:33:20 +02:00
//TODO: may need to resume scan jobs also?
log.Debugf("Trying to resume halted jobs...")
err := dao.ResetRunningJobs()
if err != nil {
log.Warningf("Failed to reset all running jobs to pending, error: %v", err)
}
jobs, err := dao.GetRepJobByStatus(models.JobPending, models.JobRetrying)
if err == nil {
for _, j := range jobs {
2017-05-23 07:33:20 +02:00
rj := job.NewRepJob(j.ID)
log.Debugf("Resuming job: %v", rj)
job.Schedule(rj)
}
} else {
log.Warningf("Failed to jobs to resume, error: %v", err)
}
}
2016-12-30 11:04:01 +01:00
func init() {
configPath := os.Getenv("CONFIG_PATH")
if len(configPath) != 0 {
log.Infof("Config path: %s", configPath)
2017-07-25 15:12:03 +02:00
if err := beego.LoadAppConfig("ini", configPath); err != nil {
log.Fatalf("Failed to load config file: %s, error: %v", configPath, err)
}
2016-12-30 11:04:01 +01:00
}
}