mirror of
https://github.com/kevin-DL/revel-cmd.git
synced 2026-01-12 02:55:16 +00:00
Added mutex lock on Refresh, removed check for app existence
This commit is contained in:
@@ -29,6 +29,7 @@ import (
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/revel/revel"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -45,6 +46,7 @@ type Harness struct {
|
||||
port int
|
||||
proxy *httputil.ReverseProxy
|
||||
watcher *revel.Watcher
|
||||
mutex *sync.Mutex
|
||||
}
|
||||
|
||||
func renderError(iw http.ResponseWriter, ir *http.Request, err error) {
|
||||
@@ -63,19 +65,17 @@ func (h *Harness) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// If app did not start when harness was run then trigger the build to capture the error
|
||||
if h.app == nil {
|
||||
// Flush any change events and rebuild app if necessary.
|
||||
// Render an error page if the rebuild / restart failed.
|
||||
err := h.watcher.Notify()
|
||||
if err != nil {
|
||||
// In a thread safe manner update the flag so that a request for
|
||||
// /favicon.ico does not trigger a rebuild
|
||||
atomic.CompareAndSwapInt32(&lastRequestHadError, 0, 1)
|
||||
renderError(w, r, err)
|
||||
return
|
||||
}
|
||||
// Flush any change events and rebuild app if necessary.
|
||||
// Render an error page if the rebuild / restart failed.
|
||||
err := h.watcher.Notify()
|
||||
if err != nil {
|
||||
// In a thread safe manner update the flag so that a request for
|
||||
// /favicon.ico does not trigger a rebuild
|
||||
atomic.CompareAndSwapInt32(&lastRequestHadError, 0, 1)
|
||||
renderError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
// In a thread safe manner update the flag so that a request for
|
||||
// /favicon.ico is allowed
|
||||
atomic.CompareAndSwapInt32(&lastRequestHadError, 1, 0)
|
||||
@@ -122,6 +122,7 @@ func NewHarness() *Harness {
|
||||
port: port,
|
||||
serverHost: serverURL.String()[len(scheme+"://"):],
|
||||
proxy: httputil.NewSingleHostReverseProxy(serverURL),
|
||||
mutex: &sync.Mutex{},
|
||||
}
|
||||
|
||||
if revel.HTTPSsl {
|
||||
@@ -134,6 +135,10 @@ func NewHarness() *Harness {
|
||||
|
||||
// Refresh method rebuilds the Revel application and run it on the given port.
|
||||
func (h *Harness) Refresh() (err *revel.Error) {
|
||||
// Allow only one thread to rebuild the process
|
||||
h.mutex.Lock()
|
||||
defer h.mutex.Unlock()
|
||||
|
||||
if h.app != nil {
|
||||
h.app.Kill()
|
||||
}
|
||||
@@ -162,7 +167,7 @@ func (h *Harness) WatchDir(info os.FileInfo) bool {
|
||||
}
|
||||
|
||||
// WatchFile method returns true given filename HasSuffix of ".go"
|
||||
// otheriwse false
|
||||
// otheriwse false - implements revel.DiscerningListener
|
||||
func (h *Harness) WatchFile(filename string) bool {
|
||||
return strings.HasSuffix(filename, ".go")
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func parseRunArgs(args []string) *RunArgs {
|
||||
}
|
||||
switch len(args) {
|
||||
case 3:
|
||||
// Possibile combinations
|
||||
// Possible combinations
|
||||
// revel run [import-path] [run-mode] [port]
|
||||
port, err := strconv.Atoi(args[2])
|
||||
if err != nil {
|
||||
@@ -61,7 +61,7 @@ func parseRunArgs(args []string) *RunArgs {
|
||||
inputArgs.Mode = args[1]
|
||||
inputArgs.Port = port
|
||||
case 2:
|
||||
// Possibile combinations
|
||||
// Possible combinations
|
||||
// 1. revel run [import-path] [run-mode]
|
||||
// 2. revel run [import-path] [port]
|
||||
// 3. revel run [run-mode] [port]
|
||||
@@ -85,7 +85,7 @@ func parseRunArgs(args []string) *RunArgs {
|
||||
inputArgs.Port = port
|
||||
}
|
||||
case 1:
|
||||
// Possibile combinations
|
||||
// Possible combinations
|
||||
// 1. revel run [import-path]
|
||||
// 2. revel run [port]
|
||||
// 3. revel run [run-mode]
|
||||
|
||||
Reference in New Issue
Block a user