about summary refs log tree commit diff
path: root/submitqueue/runner.go
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2019-11-21T15·12+0100
committerFlorian Klink <flokli@flokli.de>2019-11-21T15·13+0100
commit057294830e8e1915ee804d980d2b954ffbdff60a (patch)
treeb5143ce4629078d6c5c1decc540a05d3644d50fe /submitqueue/runner.go
parent43f8205e85a6c5aed79041715375d199414abf0a (diff)
frontend: show submittable status and URL, add runner, revamp logging
Diffstat (limited to 'submitqueue/runner.go')
-rw-r--r--submitqueue/runner.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/submitqueue/runner.go b/submitqueue/runner.go
new file mode 100644
index 000000000000..2c84a7d69b7f
--- /dev/null
+++ b/submitqueue/runner.go
@@ -0,0 +1,60 @@
+package submitqueue
+
+import (
+	"sync"
+	"time"
+)
+
+// Runner supervises the submit queue and records historical data about it
+type Runner struct {
+	mut              sync.Mutex
+	submitQueue      *SubmitQueue
+	currentlyRunning *time.Time
+	results          []*Result
+}
+
+func NewRunner(sq *SubmitQueue) *Runner {
+	return &Runner{
+		submitQueue: sq,
+		results:     []*Result{},
+	}
+}
+
+// For the frontend to consume the data
+// TODO: extend to return all the submitQueue results
+func (r *Runner) GetResults() (*time.Time, []*Result) {
+	r.mut.Lock()
+	defer r.mut.Unlock()
+	return r.currentlyRunning, r.results
+}
+
+// Trigger starts a new batch job
+// TODO: make sure only one batch job is started at the same time
+// if a batch job is already started, ignore the newest request
+// TODO: be more granular in dry-run mode
+func (r *Runner) Trigger(fetchOnly bool) {
+	r.mut.Lock()
+	if r.currentlyRunning != nil {
+		return
+	}
+	now := time.Now()
+	r.currentlyRunning = &now
+	r.mut.Unlock()
+
+	defer func() {
+		r.mut.Lock()
+		r.currentlyRunning = nil
+		r.mut.Unlock()
+	}()
+
+	result := r.submitQueue.Run(fetchOnly)
+
+	r.mut.Lock()
+	// drop tail if size > 10
+	if len(r.results) > 10 {
+		r.results = append([]*Result{result}, r.results[:9]...)
+	} else {
+		r.results = append([]*Result{result}, r.results...)
+	}
+	r.mut.Unlock()
+}