1
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
2
// source code is governed by a MIT license that can be found in the LICENSE
3
// file.
4
//
5
// The aurora is a web-based beanstalkd queue server console written in Go
6
// and works on macOS, Linux and Windows machines. Main idea behind using Go
7
// for backend development is to utilize ability of the compiler to produce
8
// zero-dependency binaries for multiple platforms. aurora was created as an
9
// attempt to build very simple and portable application to work with local or
10
// remote beanstalkd server.
11

12
package main
13

14
import (
15
	"net/url"
16
	"strings"
17

18
	"github.com/xuri/aurora/beanstalk"
19
)
20

21
// currentTubeJobsSummaryTable constructs a tube job table based on the given
22
// server and tube conf.
23
func currentTubeJobsSummaryTable(server string, tube string) string {
24 10
	var err error
25 10
	var th, tr, td, template strings.Builder
26 10
	var bstkConn *beanstalk.Conn
27 10
	if bstkConn, err = beanstalk.Dial("tcp", server); err != nil {
28
		for _, v := range selfConf.TubeFilters {
29 10
			th.WriteString(`<th>`)
30 10
			th.WriteString(v)
31 10
			th.WriteString(`</th>`)
32
		}
33 10
		if currentTubeStatisticCheck(server, tube) {
34 0
			th.WriteString(`<th> </th>`)
35
		}
36 10
		buf := strings.Builder{}
37 10
		buf.WriteString(`<section id="summaryTable"><div class="row"><div class="col-sm-12"><table class="table table-striped table-hover"><thead><tr><th>name</th>`)
38 10
		buf.WriteString(th.String())
39 10
		buf.WriteString(`</tr></thead><tbody></tbody></table></div></div></section>`)
40 10
		return buf.String()
41
	}
42 10
	tubes, _ := bstkConn.ListTubes()
43
	for _, v := range selfConf.TubeFilters {
44 10
		th.WriteString(`<th>`)
45 10
		th.WriteString(v)
46 10
		th.WriteString(`</th>`)
47
	}
48 10
	if currentTubeStatisticCheck(server, tube) {
49 10
		th.WriteString(`<th> </th>`)
50
	}
51
	for _, v := range tubes {
52 10
		if v != tube {
53 10
			continue
54
		}
55 10
		tubeStats := &beanstalk.Tube{Conn: bstkConn, Name: v}
56 10
		statsMap, err := tubeStats.Stats()
57 10
		if err != nil {
58 0
			continue
59
		}
60
		for _, stats := range selfConf.TubeFilters {
61 10
			td.WriteString(`<td>`)
62 10
			td.WriteString(statsMap[stats])
63 10
			td.WriteString(`</td>`)
64
		}
65 10
		tr.WriteString(`<tr><td>`)
66 10
		tr.WriteString(v)
67 10
		tr.WriteString(`</td>`)
68 10
		if currentTubeStatisticCheck(server, tube) {
69 10
			td.WriteString(`<td><a class="btn btn-xs btn-default" title="Statistics overview" href="./statistics?server=`)
70 10
			td.WriteString(server)
71 10
			td.WriteString(`&tube=`)
72 10
			td.WriteString(url.QueryEscape(v))
73 10
			td.WriteString(`"><span class="glyphicon glyphicon-stats"> </span></a></td>`)
74
		}
75 10
		tr.WriteString(td.String())
76 10
		tr.WriteString(`</tr>`)
77 10
		td.Reset()
78
	}
79 10
	bstkConn.Close()
80 10
	template.WriteString(`<section id="summaryTable"><div class="row"><div class="col-sm-12"><table class="table table-striped table-hover"><thead><tr><th>name</th>`)
81 10
	template.WriteString(th.String())
82 10
	template.WriteString(`</tr></thead><tbody> `)
83 10
	template.WriteString(tr.String())
84 10
	template.WriteString(`</tbody></table></div></div></section>`)
85 10
	if tr.String() == `` {
86 10
		return ``
87
	}
88 10
	return template.String()
89
}
90

91
// currentTubeStatisticCheck provide a method to confirm that the current tube
92
// statistics are available.
93
func currentTubeStatisticCheck(server string, tube string) bool {
94 10
	if selfConf.StatisticsCollection == 0 {
95 10
		return false
96
	}
97 10
	s, ok := statisticsData.Server[server]
98 10
	if !ok {
99 0
		return false
100
	}
101 10
	_, ok = s[tube]
102 10
	return ok
103
}

Read our documentation on viewing source code .

Loading