2015-09-30 01:21:17 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/drone/drone/shared/database"
|
|
|
|
"github.com/russross/meddler"
|
|
|
|
)
|
2015-06-23 03:45:08 +00:00
|
|
|
|
|
|
|
type Job struct {
|
2015-09-30 01:21:17 +00:00
|
|
|
ID int64 `json:"id" meddler:"job_id,pk"`
|
|
|
|
BuildID int64 `json:"-" meddler:"job_build_id"`
|
|
|
|
NodeID int64 `json:"-" meddler:"job_node_id"`
|
|
|
|
Number int `json:"number" meddler:"job_number"`
|
|
|
|
Status string `json:"status" meddler:"job_status"`
|
|
|
|
ExitCode int `json:"exit_code" meddler:"job_exit_code"`
|
|
|
|
Started int64 `json:"started_at" meddler:"job_started"`
|
|
|
|
Finished int64 `json:"finished_at" meddler:"job_finished"`
|
|
|
|
|
|
|
|
Environment map[string]string `json:"environment" meddler:"job_environment,json"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetJob(db meddler.DB, id int64) (*Job, error) {
|
|
|
|
var job = new(Job)
|
|
|
|
var err = meddler.Load(db, jobTable, job, id)
|
|
|
|
return job, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetJobNumber(db meddler.DB, build *Build, number int) (*Job, error) {
|
|
|
|
var job = new(Job)
|
|
|
|
var err = meddler.QueryRow(db, job, database.Rebind(jobNumberQuery), build.ID, number)
|
|
|
|
return job, err
|
|
|
|
}
|
2015-06-23 03:45:08 +00:00
|
|
|
|
2015-09-30 01:21:17 +00:00
|
|
|
func GetJobList(db meddler.DB, build *Build) ([]*Job, error) {
|
|
|
|
var jobs = []*Job{}
|
|
|
|
var err = meddler.QueryAll(db, &jobs, database.Rebind(jobListQuery), build.ID)
|
|
|
|
return jobs, err
|
2015-06-23 03:45:08 +00:00
|
|
|
}
|
2015-09-30 01:21:17 +00:00
|
|
|
|
|
|
|
func InsertJob(db meddler.DB, job *Job) error {
|
|
|
|
return meddler.Insert(db, jobTable, job)
|
|
|
|
}
|
|
|
|
|
|
|
|
func UpdateJob(db meddler.DB, job *Job) error {
|
|
|
|
return meddler.Update(db, jobTable, job)
|
|
|
|
}
|
|
|
|
|
|
|
|
const jobTable = "jobs"
|
|
|
|
|
|
|
|
const jobListQuery = `
|
|
|
|
SELECT *
|
|
|
|
FROM jobs
|
|
|
|
WHERE job_build_id = ?
|
|
|
|
ORDER BY job_number ASC
|
|
|
|
`
|
|
|
|
|
|
|
|
const jobNumberQuery = `
|
|
|
|
SELECT *
|
|
|
|
FROM jobs
|
|
|
|
WHERE job_build_id = ?
|
|
|
|
AND job_number = ?
|
|
|
|
LIMIT 1
|
|
|
|
`
|