added enqueued columns to build and job to track queue wait times

This commit is contained in:
Brad Rydzewski 2015-10-01 14:35:25 -07:00
parent f0cba925f0
commit fc4b106949
6 changed files with 14 additions and 1 deletions

View file

@ -6,6 +6,7 @@ import (
"os"
"strconv"
"strings"
"time"
log "github.com/Sirupsen/logrus"
"github.com/drone/drone/engine"
@ -186,11 +187,13 @@ func PostBuild(c *gin.Context) {
build.Status = model.StatusPending
build.Started = 0
build.Finished = 0
build.Enqueued = time.Now().UTC().Unix()
for _, job := range jobs {
job.Status = model.StatusPending
job.Started = 0
job.Finished = 0
job.ExitCode = 0
job.Enqueued = build.Enqueued
model.UpdateJob(db, job)
}

View file

@ -13,6 +13,7 @@ type Build struct {
Number int `json:"number" meddler:"build_number"`
Event string `json:"event" meddler:"build_event"`
Status string `json:"status" meddler:"build_status"`
Enqueued int64 `json:"enqueued_at" meddler:"build_enqueued"`
Created int64 `json:"created_at" meddler:"build_created"`
Started int64 `json:"started_at" meddler:"build_started"`
Finished int64 `json:"finished_at" meddler:"build_finished"`
@ -23,7 +24,7 @@ type Build struct {
Remote string `json:"remote" meddler:"build_remote"`
Title string `json:"title" meddler:"build_title"`
Message string `json:"message" meddler:"build_message"`
Timestamp string `json:"timestamp" meddler:"build_timestamp"`
Timestamp int64 `json:"timestamp" meddler:"build_timestamp"`
Author string `json:"author" meddler:"build_author"`
Avatar string `json:"author_avatar" meddler:"build_avatar"`
Email string `json:"author_email" meddler:"build_email"`
@ -76,6 +77,7 @@ func CreateBuild(db meddler.DB, build *Build, jobs ...*Job) error {
db.QueryRow(buildNumberLast, build.RepoID).Scan(&number)
build.Number = number + 1
build.Created = time.Now().UTC().Unix()
build.Enqueued = build.Created
err := meddler.Insert(db, buildTable, build)
if err != nil {
return err
@ -83,6 +85,7 @@ func CreateBuild(db meddler.DB, build *Build, jobs ...*Job) error {
for i, job := range jobs {
job.BuildID = build.ID
job.Number = i + 1
job.Enqueued = build.Created
err = InsertJob(db, job)
if err != nil {
return err

View file

@ -12,6 +12,7 @@ type Job struct {
Number int `json:"number" meddler:"job_number"`
Status string `json:"status" meddler:"job_status"`
ExitCode int `json:"exit_code" meddler:"job_exit_code"`
Enqueued int64 `json:"enqueued_at" meddler:"job_enqueued"`
Started int64 `json:"started_at" meddler:"job_started"`
Finished int64 `json:"finished_at" meddler:"job_finished"`

View file

@ -61,6 +61,7 @@ CREATE TABLE builds (
,build_number INTEGER
,build_event VARCHAR(500)
,build_status VARCHAR(500)
,build_enqueued INTEGER
,build_created INTEGER
,build_started INTEGER
,build_finished INTEGER
@ -90,6 +91,7 @@ CREATE TABLE jobs (
,job_status VARCHAR(500)
,job_exit_code INTEGER
,job_started INTEGER
,job_enqueued INTEGER
,job_finished INTEGER
,job_environment VARCHAR(2000)

View file

@ -61,6 +61,7 @@ CREATE TABLE builds (
,build_number INTEGER
,build_event VARCHAR(500)
,build_status VARCHAR(500)
,build_enqueued INTEGER
,build_created INTEGER
,build_started INTEGER
,build_finished INTEGER
@ -90,6 +91,7 @@ CREATE TABLE jobs (
,job_status VARCHAR(500)
,job_exit_code INTEGER
,job_started INTEGER
,job_enqueued INTEGER
,job_finished INTEGER
,job_environment VARCHAR(2000)

View file

@ -61,6 +61,7 @@ CREATE TABLE builds (
,build_number INTEGER
,build_event TEXT
,build_status TEXT
,build_enqueued INTEGER
,build_created INTEGER
,build_started INTEGER
,build_finished INTEGER
@ -89,6 +90,7 @@ CREATE TABLE jobs (
,job_number INTEGER
,job_status TEXT
,job_exit_code INTEGER
,job_enqueued INTEGER
,job_started INTEGER
,job_finished INTEGER
,job_environment TEXT