示例#1
0
// createJob adds a new job to the database.
func (p *pushCallback) createJob() error {
	if p.shouldRun() == false {
		log.Println("Not adding", p.repositoryURL(), p.branch())
		return nil
	}

	repo := database.GetRepository(p.repositoryURL())

	job := database.CreateJob(
		repo,
		p.branch(),
		p.commit(),
		p.commitURL(),
		p.name(),
		p.email(),
	)

	status := make(chan bool, 1)

	queueJob := runner.QueueJob{
		JobID:  job.ID,
		Status: status,
	}

	queueJob.Enqueue()

	if repo.StatusPR {
		<-status
		job = database.GetJob(job.ID)
		postStatus(job, repo, p.statusURL())
	}

	return nil
}
示例#2
0
// viewCancelJob cancels a job.
func viewCancelJob(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	jobID, _ := strconv.Atoi(vars["jid"])

	job := database.GetJob(int64(jobID))
	job.Cancel()

	http.Redirect(w, r, "/", 302)
}
示例#3
0
// viewJobDetail shows a specific job with all related information.
func viewDetailJob(w http.ResponseWriter, r *http.Request) {
	template := "job/detail.html"
	ctx := make(responseContext)

	vars := mux.Vars(r)
	jobID, _ := strconv.Atoi(vars["jid"])

	job := database.GetJob(int64(jobID))
	ctx["job"] = job

	render(w, r, template, ctx)
}
示例#4
0
// viewRerunJob resets a job status and enqueues it agian.
func viewRerunJob(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	jobID, _ := strconv.Atoi(vars["jid"])

	old := database.GetJob(int64(jobID))
	job := database.CreateJob(
		&old.Repository,
		old.Branch,
		old.Commit,
		old.CommitURL,
		old.Name,
		old.Email,
	)

	queueJob := runner.QueueJob{
		JobID: job.ID,
	}

	queueJob.Enqueue()

	http.Redirect(w, r, "/", 302)
}
示例#5
0
// 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)
		}
	}
}