diff options
author | Florian Klink <flokli@flokli.de> | 2019-12-02T09·00+0100 |
---|---|---|
committer | Florian Klink <flokli@flokli.de> | 2019-12-02T09·00+0100 |
commit | 04a24a0c601c28d01e1110fb82f57c7a7c3f5d74 (patch) | |
tree | abe8872d565a82db38167b07b0a4526883031983 /main.go | |
parent | 7bafef7a848cc80c79551441630210e947b2481b (diff) |
Use Runner
This revamps code quite a bit. Series handling has been moved into the gerrit client, it also handles caching. The Runner logic itself has been greatly simplified. The runner logic has been moved into the runner.go, submitqueue.go is gone. The "per-run result object" concept has been dropped - we instead just use annotated logs. Also, we switched to apex/log
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 49 |
1 files changed, 21 insertions, 28 deletions
diff --git a/main.go b/main.go index 14320276377f..1be379904b29 100644 --- a/main.go +++ b/main.go @@ -14,16 +14,13 @@ import ( "github.com/urfave/cli" - log "github.com/sirupsen/logrus" + "github.com/apex/log" + "github.com/apex/log/handlers/memory" + "github.com/apex/log/handlers/multi" + "github.com/apex/log/handlers/text" ) func main() { - // configure logging - log.SetFormatter(&log.TextFormatter{}) - //log.SetFormatter(&log.JSONFormatter{}) - log.SetOutput(os.Stdout) - log.SetLevel(log.DebugLevel) - var URL, username, password, projectName, branchName, submitQueueTag string var fetchOnly bool @@ -81,25 +78,33 @@ func main() { }, } + memoryLogHandler := memory.New() + l := &log.Logger{ + Handler: multi.New( + text.New(os.Stderr), + memoryLogHandler, + ), + Level: log.DebugLevel, + } + app.Action = func(c *cli.Context) error { - gerritClient, err := gerrit.NewClient(URL, username, password) + gerrit, err := gerrit.NewClient(l, URL, username, password, projectName, branchName) if err != nil { return err } - log.Printf("Successfully connected to gerrit at %s", URL) + log.Infof("Successfully connected to gerrit at %s", URL) - submitQueue := submitqueue.MakeSubmitQueue(gerritClient, projectName, branchName, submitQueueTag) - runner := submitqueue.NewRunner(submitQueue) + runner := submitqueue.NewRunner(l, gerrit, submitQueueTag) - handler := frontend.MakeFrontend(runner) + handler := frontend.MakeFrontend(memoryLogHandler, gerrit, runner) // fetch only on first run - runner.Trigger(true) + runner.Trigger(fetchOnly) // ticker go func() { for { - time.Sleep(time.Minute * 10) + time.Sleep(time.Minute * 5) runner.Trigger(fetchOnly) } }() @@ -111,7 +116,7 @@ func main() { server.ListenAndServe() if err != nil { - log.Fatal(err) + log.Fatalf(err.Error()) } return nil @@ -119,21 +124,9 @@ func main() { err := app.Run(os.Args) if err != nil { - log.Fatal(err) + log.Fatal(err.Error()) } - // mux := http.NewServeMux() - - // options := &gerrit.EventsLogOptions{} - // events, _, _, err := gerritClient.EventsLog.GetEvents(options) - // TODOS: - // - create submit queue user // - handle event log, either by accepting webhooks, or by streaming events? - - //n := negroni.Classic() - //n.UseHandler(mux) - - //fmt.Println("Listening on :3000…") - //http.ListenAndServe(":3000", n) } |