| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Package handlers implements HTTP handlers for the gerrit-poller module. | 5 // Package handlers implements HTTP handlers for the gerrit-poller module. |
| 6 package handlers | 6 package handlers |
| 7 | 7 |
| 8 import ( | 8 import ( |
| 9 "html/template" | |
| 10 "net/http" | 9 "net/http" |
| 11 | 10 |
| 12 "google.golang.org/appengine" | 11 "google.golang.org/appengine" |
| 13 "google.golang.org/appengine/taskqueue" | 12 "google.golang.org/appengine/taskqueue" |
| 13 |
| 14 "infra/tricium/service/common" |
| 14 ) | 15 ) |
| 15 | 16 |
| 16 func init() { | 17 func init() { |
| 17 http.HandleFunc("/gerrit-poller/status", statusPageHandler) | 18 http.HandleFunc("/gerrit-poller/status", statusPageHandler) |
| 18 http.HandleFunc("/gerrit-poller/poll", pollHandler) | 19 http.HandleFunc("/gerrit-poller/poll", pollHandler) |
| 19 } | 20 } |
| 20 | 21 |
| 21 var basePage = template.Must(template.ParseFiles("templates/base.html")) | |
| 22 | |
| 23 func statusPageHandler(w http.ResponseWriter, r *http.Request) { | 22 func statusPageHandler(w http.ResponseWriter, r *http.Request) { |
| 24 // TODO(emso): Add Gerrit poller stats | 23 // TODO(emso): Add Gerrit poller stats |
| 25 » data := map[string]interface{}{ | 24 » d := map[string]interface{}{ |
| 26 "Msg": "Status of the Gerrit Poller ...", | 25 "Msg": "Status of the Gerrit Poller ...", |
| 27 } | 26 } |
| 28 » basePage.Execute(w, data) | 27 » common.ShowBasePage(w, d) |
| 29 } | 28 } |
| 30 | 29 |
| 31 func pollHandler(w http.ResponseWriter, r *http.Request) { | 30 func pollHandler(w http.ResponseWriter, r *http.Request) { |
| 32 ctx := appengine.NewContext(r) | 31 ctx := appengine.NewContext(r) |
| 33 | 32 |
| 34 // TODO(emso): Poll Gerrit and convert changes to workflow event tasks. | 33 // TODO(emso): Poll Gerrit and convert changes to workflow event tasks. |
| 35 | 34 |
| 36 // Enqueue workflow event task. | 35 // Enqueue workflow event task. |
| 37 t := taskqueue.NewPOSTTask("/workflow-launcher/queue-handler", map[strin
g][]string{"name": {"Analysis Request"}}) | 36 t := taskqueue.NewPOSTTask("/workflow-launcher/queue-handler", map[strin
g][]string{"name": {"Analysis Request"}}) |
| 38 » if _, err := taskqueue.Add(ctx, t, "workflow-launcher-queue"); err != ni
l { | 37 » if _, e := taskqueue.Add(ctx, t, "workflow-launcher-queue"); e != nil { |
| 39 » » http.Error(w, err.Error(), http.StatusInternalServerError) | 38 » » http.Error(w, e.Error(), http.StatusInternalServerError) |
| 40 return | 39 return |
| 41 } | 40 } |
| 42 } | 41 } |
| OLD | NEW |