2016-04-20 08:24:17 +02:00
|
|
|
package job
|
|
|
|
|
|
|
|
import (
|
2016-05-10 13:38:50 +02:00
|
|
|
"github.com/vmware/harbor/dao"
|
2016-04-20 08:24:17 +02:00
|
|
|
"github.com/vmware/harbor/models"
|
|
|
|
"github.com/vmware/harbor/utils/log"
|
|
|
|
)
|
|
|
|
|
2016-05-10 13:38:50 +02:00
|
|
|
func Schedule(jobID int64) {
|
|
|
|
//TODO: introduce jobqueue to better control concurrent job numbers
|
|
|
|
go HandleRepJob(jobID)
|
|
|
|
}
|
2016-05-03 09:51:52 +02:00
|
|
|
|
2016-05-10 13:38:50 +02:00
|
|
|
func HandleRepJob(id int64) {
|
|
|
|
sm := &JobSM{JobID: id}
|
|
|
|
err := sm.Init()
|
2016-05-03 09:51:52 +02:00
|
|
|
if err != nil {
|
2016-05-10 13:38:50 +02:00
|
|
|
log.Errorf("Failed to initialize statemachine, error: %v")
|
|
|
|
err2 := dao.UpdateRepJobStatus(id, models.JobError)
|
|
|
|
if err2 != nil {
|
|
|
|
log.Errorf("Failed to update job status to ERROR, error:%v", err2)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if sm.Parms.Enabled == 0 {
|
|
|
|
log.Debugf("The policy of job:%d is disabled, will cancel the job")
|
|
|
|
_ = dao.UpdateRepJobStatus(id, models.JobCanceled)
|
|
|
|
} else {
|
|
|
|
sm.Start(models.JobRunning)
|
2016-05-03 09:51:52 +02:00
|
|
|
}
|
2016-04-20 08:24:17 +02:00
|
|
|
}
|