Exemple #1
0
func (h *Handler) listJobs(w http.ResponseWriter, r *http.Request) {
	if list, err := h.jobService.AllLatestBuilds(); err == nil {
		type cell struct {
			ID     string
			Name   string
			Status string
		}

		cells := [][]cell{}
		for _, buildRow := range helpers.JobGrid(list) {
			cellRow := []cell{}
			for _, build := range buildRow {
				cellRow = append(cellRow, cell{
					ID:     build.ID,
					Name:   build.Name,
					Status: helpers.Classes(build),
				})
			}
			cells = append(cells, cellRow)
		}

		p := struct {
			BuildRows [][]cell
		}{
			BuildRows: cells,
		}
		h.renderTemplate("list_jobs", p, w)
	} else {
		h.renderErrPage("listing jobs", err, w, r)
	}
}
Exemple #2
0
func (h *Handler) listJobStatuses(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/event-stream\n\n")

	for {
		list, err := h.jobService.AllLatestBuilds()
		must(err)

		statuses := make(map[string]string)
		for _, build := range list {
			statuses[build.ID] = helpers.Classes(build)
			msg, err := json.Marshal(statuses)
			must(err)
			if _, err := w.Write([]byte(eventMessage("jobs", string(msg)))); err != nil {
				log.Printf("trying to write job statuses JSON. assuming remote end hung up. Cause: %v\n", err)
				return
			}

			w.(http.Flusher).Flush()
			time.Sleep(time.Millisecond * 100)
		}
	}
}
		It("returns running when the build is not finished", func() {
			Expect(helpers.Message(jobs.Build{
				Finished: false,
			})).To(Equal("Running"))
		})
	})

	Describe("build classes", func() {
		var (
			b       jobs.Build
			classes string
		)

		JustBeforeEach(func() {
			classes = helpers.Classes(b)
		})

		Context("when the build is running", func() {
			BeforeEach(func() {
				b = jobs.Build{Finished: false}
			})

			It("returns empty string", func() {
				Expect(classes).To(BeEmpty())
			})
		})

		Context("when the build was successful", func() {
			BeforeEach(func() {
				b = jobs.Build{Finished: true, ExitStatus: 0}