2016-04-20 06:24:17 +00:00
|
|
|
package job
|
|
|
|
|
|
|
|
import (
|
2016-05-10 11:38:50 +00:00
|
|
|
"github.com/vmware/harbor/dao"
|
2016-04-20 06:24:17 +00:00
|
|
|
"github.com/vmware/harbor/models"
|
|
|
|
"github.com/vmware/harbor/utils/log"
|
|
|
|
)
|
|
|
|
|
2016-05-12 08:11:28 +00:00
|
|
|
var JobQueue chan int64 = make(chan int64)
|
|
|
|
|
2016-05-10 11:38:50 +00:00
|
|
|
func Schedule(jobID int64) {
|
2016-05-12 08:11:28 +00:00
|
|
|
JobQueue <- jobID
|
2016-05-10 11:38:50 +00:00
|
|
|
}
|
2016-05-03 07:51:52 +00:00
|
|
|
|
2016-05-10 11:38:50 +00:00
|
|
|
func HandleRepJob(id int64) {
|
|
|
|
sm := &JobSM{JobID: id}
|
|
|
|
err := sm.Init()
|
2016-05-03 07:51:52 +00:00
|
|
|
if err != nil {
|
2016-05-10 11:38:50 +00: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 07:51:52 +00:00
|
|
|
}
|
2016-04-20 06:24:17 +00:00
|
|
|
}
|