// Runner waits for jobs to be pushed on RunQueue and runs all commands. It also // creates the command logs and sends the necessary notifications. func Runner() { for { queueJob := <-runQueue job := database.GetJob(queueJob.JobID) repository, err := database.GetRepositoryByID(job.RepositoryID) if job.Cancelled == true { log.Println("Job cancelled, not running commands", job.ID) continue } if err != nil { log.Println("Could not find repository for", job.Repository.URL) return } job.Started() run(job, repository, database.CommandKindTest) notification.Notify(job, notification.EventTest) if job.Passed() && job.ShouldBuild() { run(job, repository, database.CommandKindBuild) notification.Notify(job, notification.EventBuild) } job.TasksDone() if queueJob.Status != nil { queueJob.Status <- true } if job.Passed() && job.ShouldDeploy() { go deploy(job, repository) } } }
// deploy is a wrapper around the run commnad to make running the deploy commands // in a separate go routine more convenient. func deploy(job *database.Job, repository *database.Repository) { notification.Notify(job, notification.EventDeployStart) run(job, repository, database.CommandKindDeploy) job.DeployDone() notification.Notify(job, notification.EventDeployEnd) }