diff --git a/controller/build.go b/controller/build.go index 4a4659e80..dacd89565 100644 --- a/controller/build.go +++ b/controller/build.go @@ -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) } diff --git a/model/build.go b/model/build.go index 1562b8694..e21dff4b5 100644 --- a/model/build.go +++ b/model/build.go @@ -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 diff --git a/model/job.go b/model/job.go index 6f61d8a87..bd6802e93 100644 --- a/model/job.go +++ b/model/job.go @@ -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"` diff --git a/shared/database/mysql/1_init.sql b/shared/database/mysql/1_init.sql index 035c204fa..87a752645 100644 --- a/shared/database/mysql/1_init.sql +++ b/shared/database/mysql/1_init.sql @@ -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) diff --git a/shared/database/postgres/1_init.sql b/shared/database/postgres/1_init.sql index 610939074..01955e673 100644 --- a/shared/database/postgres/1_init.sql +++ b/shared/database/postgres/1_init.sql @@ -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) diff --git a/shared/database/sqlite3/1_init.sql b/shared/database/sqlite3/1_init.sql index 511ff78e3..906d2f96f 100644 --- a/shared/database/sqlite3/1_init.sql +++ b/shared/database/sqlite3/1_init.sql @@ -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