|
|
@ -18,7 +18,6 @@ func createJobTable(db *sql.DB) (err error) {
|
|
|
|
group_uuid TEXT,
|
|
|
|
group_uuid TEXT,
|
|
|
|
repo TEXT,
|
|
|
|
repo TEXT,
|
|
|
|
"commit" TEXT,
|
|
|
|
"commit" TEXT,
|
|
|
|
description TEXT,
|
|
|
|
|
|
|
|
config TEXT,
|
|
|
|
config TEXT,
|
|
|
|
target TEXT,
|
|
|
|
target TEXT,
|
|
|
|
created INT,
|
|
|
|
created INT,
|
|
|
@ -31,8 +30,8 @@ func createJobTable(db *sql.DB) (err error) {
|
|
|
|
|
|
|
|
|
|
|
|
func AddJob(db *sql.DB, job *api.Job) (err error) {
|
|
|
|
func AddJob(db *sql.DB, job *api.Job) (err error) {
|
|
|
|
stmt, err := db.Prepare(`INSERT INTO job (updated, uuid, group_uuid, repo, "commit", ` +
|
|
|
|
stmt, err := db.Prepare(`INSERT INTO job (updated, uuid, group_uuid, repo, "commit", ` +
|
|
|
|
`description, config, target, created, started, finished) ` +
|
|
|
|
`config, target, created, started, finished) ` +
|
|
|
|
`VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);`)
|
|
|
|
`VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);`)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -54,7 +53,7 @@ func AddJob(db *sql.DB, job *api.Job) (err error) {
|
|
|
|
target := tbuf.Bytes()
|
|
|
|
target := tbuf.Bytes()
|
|
|
|
|
|
|
|
|
|
|
|
res, err := stmt.Exec(time.Now().Unix(), job.UUID, job.Group,
|
|
|
|
res, err := stmt.Exec(time.Now().Unix(), job.UUID, job.Group,
|
|
|
|
job.RepoName, job.Commit, job.Description, config, target,
|
|
|
|
job.RepoName, job.Commit, config, target,
|
|
|
|
job.Created.Unix(), job.Started.Unix(),
|
|
|
|
job.Created.Unix(), job.Started.Unix(),
|
|
|
|
job.Finished.Unix(),
|
|
|
|
job.Finished.Unix(),
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -69,10 +68,10 @@ func AddJob(db *sql.DB, job *api.Job) (err error) {
|
|
|
|
func UpdateJob(db *sql.DB, job *api.Job) (err error) {
|
|
|
|
func UpdateJob(db *sql.DB, job *api.Job) (err error) {
|
|
|
|
stmt, err := db.Prepare(`UPDATE job ` +
|
|
|
|
stmt, err := db.Prepare(`UPDATE job ` +
|
|
|
|
`SET updated=$1, uuid=$2, group_uuid=$3, repo=$4, ` +
|
|
|
|
`SET updated=$1, uuid=$2, group_uuid=$3, repo=$4, ` +
|
|
|
|
`"commit"=$5, description=$6, config=$7, target=$8, ` +
|
|
|
|
`"commit"=$5, config=$6, target=$7, ` +
|
|
|
|
`created=$9, started=$10, finished=$11, ` +
|
|
|
|
`created=$8, started=$9, finished=$10, ` +
|
|
|
|
`status=$12 ` +
|
|
|
|
`status=$11 ` +
|
|
|
|
`WHERE id=$13`)
|
|
|
|
`WHERE id=$12`)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -93,7 +92,7 @@ func UpdateJob(db *sql.DB, job *api.Job) (err error) {
|
|
|
|
target := tbuf.Bytes()
|
|
|
|
target := tbuf.Bytes()
|
|
|
|
|
|
|
|
|
|
|
|
_, err = stmt.Exec(time.Now().Unix(), job.UUID, job.Group,
|
|
|
|
_, err = stmt.Exec(time.Now().Unix(), job.UUID, job.Group,
|
|
|
|
job.RepoName, job.Commit, job.Description,
|
|
|
|
job.RepoName, job.Commit,
|
|
|
|
config, target,
|
|
|
|
config, target,
|
|
|
|
job.Created.Unix(), job.Started.Unix(),
|
|
|
|
job.Created.Unix(), job.Started.Unix(),
|
|
|
|
job.Finished.Unix(), job.Status, job.ID)
|
|
|
|
job.Finished.Unix(), job.Status, job.ID)
|
|
|
@ -104,8 +103,7 @@ func scanJob(scan func(dest ...any) error) (job api.Job, err error) {
|
|
|
|
var config, target []byte
|
|
|
|
var config, target []byte
|
|
|
|
var updated, created, started, finished int64
|
|
|
|
var updated, created, started, finished int64
|
|
|
|
err = scan(&job.ID, &updated, &job.UUID, &job.Group,
|
|
|
|
err = scan(&job.ID, &updated, &job.UUID, &job.Group,
|
|
|
|
&job.RepoName, &job.Commit, &job.Description,
|
|
|
|
&job.RepoName, &job.Commit, &config, &target,
|
|
|
|
&config, &target,
|
|
|
|
|
|
|
|
&created, &started, &finished, &job.Status)
|
|
|
|
&created, &started, &finished, &job.Status)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
return
|
|
|
@ -132,7 +130,7 @@ func scanJob(scan func(dest ...any) error) (job api.Job, err error) {
|
|
|
|
|
|
|
|
|
|
|
|
func Jobs(db *sql.DB, where string, args ...any) (jobs []api.Job, err error) {
|
|
|
|
func Jobs(db *sql.DB, where string, args ...any) (jobs []api.Job, err error) {
|
|
|
|
q := `SELECT id, updated, uuid, group_uuid, ` +
|
|
|
|
q := `SELECT id, updated, uuid, group_uuid, ` +
|
|
|
|
`repo, "commit", description, config, target, created, ` +
|
|
|
|
`repo, "commit", config, target, created, ` +
|
|
|
|
`started, finished, status FROM job`
|
|
|
|
`started, finished, status FROM job`
|
|
|
|
if len(where) != 0 {
|
|
|
|
if len(where) != 0 {
|
|
|
|
q += ` WHERE ` + where
|
|
|
|
q += ` WHERE ` + where
|
|
|
@ -165,7 +163,7 @@ func Jobs(db *sql.DB, where string, args ...any) (jobs []api.Job, err error) {
|
|
|
|
func Job(db *sql.DB, uuid string) (job api.Job, err error) {
|
|
|
|
func Job(db *sql.DB, uuid string) (job api.Job, err error) {
|
|
|
|
stmt, err := db.Prepare(`SELECT id, updated, uuid, ` +
|
|
|
|
stmt, err := db.Prepare(`SELECT id, updated, uuid, ` +
|
|
|
|
`group_uuid, ` +
|
|
|
|
`group_uuid, ` +
|
|
|
|
`repo, "commit", description, config, target, ` +
|
|
|
|
`repo, "commit", config, target, ` +
|
|
|
|
`created, started, finished, status ` +
|
|
|
|
`created, started, finished, status ` +
|
|
|
|
`FROM job WHERE uuid=$1`)
|
|
|
|
`FROM job WHERE uuid=$1`)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|