removed unused build package from /queue

This commit is contained in:
Brad
2014-06-07 13:46:05 -07:00
parent 5a8eeb9c29
commit b0255af7a9
2 changed files with 15 additions and 39 deletions

View File

@@ -1,7 +1,6 @@
package queue package queue
import ( import (
"github.com/drone/drone/server/resource/build"
"github.com/drone/drone/server/resource/commit" "github.com/drone/drone/server/resource/commit"
"github.com/drone/drone/server/resource/repo" "github.com/drone/drone/server/resource/repo"
"github.com/drone/drone/server/resource/user" "github.com/drone/drone/server/resource/user"
@@ -17,10 +16,9 @@ type Queue struct {
// BuildTasks represents a build that is pending // BuildTasks represents a build that is pending
// execution. // execution.
type BuildTask struct { type BuildTask struct {
User *user.User
Repo *repo.Repo Repo *repo.Repo
Commit *commit.Commit Commit *commit.Commit
Build *build.Build
User *user.User
// Build instructions from the .drone.yml // Build instructions from the .drone.yml
// file, unmarshalled. // file, unmarshalled.

View File

@@ -11,13 +11,11 @@ import (
"path/filepath" "path/filepath"
"time" "time"
"github.com/drone/drone/server/resource/build"
"github.com/drone/drone/server/resource/commit" "github.com/drone/drone/server/resource/commit"
"github.com/drone/drone/server/resource/repo" "github.com/drone/drone/server/resource/repo"
) )
type worker struct { type worker struct {
builds build.BuildManager
commits commit.CommitManager commits commit.CommitManager
runner BuildRunner runner BuildRunner
@@ -48,21 +46,15 @@ func (w *worker) execute(task *BuildTask) error {
// to avoid brining down the entire application // to avoid brining down the entire application
defer func() { defer func() {
if e := recover(); e != nil { if e := recover(); e != nil {
task.Build.Finished = time.Now().Unix()
task.Commit.Finished = time.Now().Unix() task.Commit.Finished = time.Now().Unix()
task.Build.Duration = task.Build.Finished - task.Build.Started task.Commit.Duration = task.Commit.Finished - task.Commit.Started
task.Commit.Duration = task.Build.Finished - task.Build.Started task.Commit.Status = commit.StatusError
task.Commit.Status = "Error"
task.Build.Status = "Error"
w.builds.Update(task.Build)
w.commits.Update(task.Commit) w.commits.Update(task.Commit)
} }
}() }()
// update commit and build status // update commit and build status
task.Commit.Status = "Started" task.Commit.Status = commit.StatusStarted
task.Build.Status = "Started"
task.Build.Started = time.Now().Unix()
task.Commit.Started = time.Now().Unix() task.Commit.Started = time.Now().Unix()
// persist the commit to the database // persist the commit to the database
@@ -70,11 +62,6 @@ func (w *worker) execute(task *BuildTask) error {
return err return err
} }
// persist the build to the database
if err := w.builds.Update(task.Build); err != nil {
return err
}
// get settings // get settings
//settings, _ := database.GetSettings() //settings, _ := database.GetSettings()
@@ -97,16 +84,16 @@ func (w *worker) execute(task *BuildTask) error {
// make sure a channel exists for the repository, // make sure a channel exists for the repository,
// the commit, and the commit output (TODO) // the commit, and the commit output (TODO)
reposlug := fmt.Sprintf("%s/%s/%s", task.Repo.Remote, task.Repo.Owner, task.Repo.Name) reposlug := fmt.Sprintf("%s/%s/%s", task.Repo.Host, task.Repo.Owner, task.Repo.Name)
commitslug := fmt.Sprintf("%s/%s/%s/commit/%s/%s", task.Repo.Remote, task.Repo.Owner, task.Repo.Name, task.Commit.Branch, task.Commit.Sha) commitslug := fmt.Sprintf("%s/%s/%s/commit/%s/%s", task.Repo.Host, task.Repo.Owner, task.Repo.Name, task.Commit.Branch, task.Commit.Sha)
consoleslug := fmt.Sprintf("%s/%s/%s/commit/%s/%s/builds/%d", task.Repo.Remote, task.Repo.Owner, task.Repo.Name, task.Commit.Branch, task.Commit.Sha, task.Build.Number) consoleslug := fmt.Sprintf("%s/%s/%s/commit/%s/%s/console", task.Repo.Host, task.Repo.Owner, task.Repo.Name, task.Commit.Branch, task.Commit.Sha)
channel.Create(reposlug) channel.Create(reposlug)
channel.Create(commitslug) channel.Create(commitslug)
channel.CreateStream(consoleslug) channel.CreateStream(consoleslug)
// notify the channels that the commit and build started // notify the channels that the commit and build started
channel.SendJSON(reposlug, task.Commit) channel.SendJSON(reposlug, task.Commit)
channel.SendJSON(commitslug, task.Build) channel.SendJSON(commitslug, task.Commit)
var buf = &bufferWrapper{channel: consoleslug} var buf = &bufferWrapper{channel: consoleslug}
@@ -130,33 +117,24 @@ func (w *worker) execute(task *BuildTask) error {
// execute the build // execute the build
passed, buildErr := w.runBuild(task, buf) passed, buildErr := w.runBuild(task, buf)
task.Build.Finished = time.Now().Unix()
task.Commit.Finished = time.Now().Unix() task.Commit.Finished = time.Now().Unix()
task.Build.Duration = task.Build.Finished - task.Build.Started task.Commit.Duration = task.Commit.Finished - task.Commit.Started
task.Commit.Duration = task.Build.Finished - task.Build.Started task.Commit.Status = commit.StatusSuccess
task.Commit.Status = "Success"
task.Build.Status = "Success"
// capture build output // capture build output
stdout := buf.buf.String() stdout := buf.buf.String()
// if exit code != 0 set to failure // if exit code != 0 set to failure
if passed { if passed {
task.Commit.Status = "Failure" task.Commit.Status = commit.StatusFailure
task.Build.Status = "Failure"
if buildErr != nil && len(stdout) == 0 { if buildErr != nil && len(stdout) == 0 {
// TODO: If you wanted to have very friendly error messages, you could do that here // TODO: If you wanted to have very friendly error messages, you could do that here
stdout = fmt.Sprintf("%s\n", buildErr.Error()) stdout = fmt.Sprintf("%s\n", buildErr.Error())
} }
} }
// persist the build to the database
if err := w.builds.Update(task.Build); err != nil {
return err
}
// persist the build output // persist the build output
if err := w.builds.UpdateOutput(task.Build, []byte(stdout)); err != nil { if err := w.commits.UpdateOutput(task.Commit, []byte(stdout)); err != nil {
return nil return nil
} }
@@ -167,7 +145,7 @@ func (w *worker) execute(task *BuildTask) error {
// notify the channels that the commit and build finished // notify the channels that the commit and build finished
channel.SendJSON(reposlug, task.Commit) channel.SendJSON(reposlug, task.Commit)
channel.SendJSON(commitslug, task.Build) channel.SendJSON(commitslug, task.Commit)
channel.Close(consoleslug) channel.Close(consoleslug)
// send all "finished" notifications // send all "finished" notifications
@@ -180,13 +158,13 @@ func (w *worker) execute(task *BuildTask) error {
func (w *worker) runBuild(task *BuildTask, buf io.Writer) (bool, error) { func (w *worker) runBuild(task *BuildTask, buf io.Writer) (bool, error) {
repo := &r.Repo{ repo := &r.Repo{
Name: task.Repo.FullName, Name: task.Repo.Host + task.Repo.Owner + task.Repo.Name,
Path: task.Repo.URL, Path: task.Repo.URL,
Branch: task.Commit.Branch, Branch: task.Commit.Branch,
Commit: task.Commit.Sha, Commit: task.Commit.Sha,
PR: task.Commit.PullRequest, PR: task.Commit.PullRequest,
//TODO the builder should handle this //TODO the builder should handle this
Dir: filepath.Join("/var/cache/drone/src", task.Repo.FullName), Dir: filepath.Join("/var/cache/drone/src", task.Repo.Host, task.Repo.Owner, task.Repo.Name),
Depth: git.GitDepth(task.Script.Git), Depth: git.GitDepth(task.Script.Git),
} }