about summary refs log tree commit diff
path: root/main.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 /main.go
parent43f8205e85a6c5aed79041715375d199414abf0a (diff)
frontend: show submittable status and URL, add runner, revamp logging
Diffstat (limited to 'main.go')
-rw-r--r--main.go42
1 files changed, 20 insertions, 22 deletions
diff --git a/main.go b/main.go
index 9bd8cd1feab1..1f64c7759132 100644
--- a/main.go
+++ b/main.go
@@ -4,16 +4,16 @@ package main
 
 import (
 	"os"
+	"time"
+
+	"net/http"
 
 	"github.com/tweag/gerrit-queue/frontend"
 	"github.com/tweag/gerrit-queue/gerrit"
 	"github.com/tweag/gerrit-queue/submitqueue"
 
-	"github.com/gin-gonic/gin"
 	"github.com/urfave/cli"
 
-	"fmt"
-
 	log "github.com/sirupsen/logrus"
 )
 
@@ -88,31 +88,29 @@ func main() {
 		log.Printf("Successfully connected to gerrit at %s", URL)
 
 		submitQueue := submitqueue.MakeSubmitQueue(gerritClient, projectName, branchName, submitQueueTag)
+		runner := submitqueue.NewRunner(submitQueue)
 
-		router := gin.Default()
-		frontend := frontend.MakeFrontend(router, &submitQueue)
+		handler := frontend.MakeFrontend(runner, submitQueue)
 
-		err = submitQueue.LoadSeries()
-		if err != nil {
-			log.Errorf("Error loading submit queue: %s", err)
-		}
+		// fetch only on first run
+		runner.Trigger(true)
 
-		fmt.Println()
-		fmt.Println()
-		fmt.Println()
-		fmt.Println()
-		for _, serie := range submitQueue.Series {
-			fmt.Println(fmt.Sprintf("%s", serie))
-			for _, changeset := range serie.ChangeSets {
-				fmt.Println(fmt.Sprintf(" - %s", changeset.String()))
+		// ticker
+		go func() {
+			for {
+				time.Sleep(time.Minute * 10)
+				runner.Trigger(fetchOnly)
 			}
-			fmt.Println()
-		}
+		}()
 
-		frontend.Run(":8080")
+		server := http.Server{
+			Addr:    ":8080",
+			Handler: handler,
+		}
 
-		if fetchOnly {
-			//return backlog.Run()
+		server.ListenAndServe()
+		if err != nil {
+			log.Fatal(err)
 		}
 
 		return nil