Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #41 from vania-pooh/master
Browse files Browse the repository at this point in the history
Added ability to watch quota files for changes (fixes #40)
  • Loading branch information
aandryashin authored Feb 18, 2019
2 parents ca8a8cc + 52df8b9 commit 236d258
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:

script:
- export GO111MODULE="on"
- go test -v -race -coverprofile=coverage.txt -covermode=atomic
- go test -tags 'watch' -v -race -coverprofile=coverage.txt -covermode=atomic
- GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.gitRevision=`git describe --tags || git rev-parse HEAD` -s -w"
- gox -os "linux darwin windows" -arch "amd64" -osarch="windows/386" -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}" -ldflags "-X main.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.gitRevision=`git describe --tags || git rev-parse HEAD` -s -w"

Expand Down
4 changes: 2 additions & 2 deletions ggr-ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func status(w http.ResponseWriter, r *http.Request) {
ch := make(chan struct{}, limit)
rslt := make(chan *result)
done := make(chan Status)
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(r.Context())
defer cancel()
go func(ctx context.Context) {
for sum, u := range hosts {
Expand Down Expand Up @@ -113,7 +113,7 @@ func status(w http.ResponseWriter, r *http.Request) {
case s := <-done:
w.Header().Add("Content-Type", "application/json")
json.NewEncoder(w).Encode(s)
case <-w.(http.CloseNotifier).CloseNotify():
case <-r.Context().Done():
}
}

Expand Down
2 changes: 1 addition & 1 deletion ggr-ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func TestResponseTime(t *testing.T) {

var (
silent = http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
<-w.(http.CloseNotifier).CloseNotify()
<-r.Context().Done()
}))
empty = http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `{"total":1,"used":0,"queued":0,"pending":0,"browsers":{"chrome":{"60.0":{}},"firefox":{"59.0":{}}}}`)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module github.com/aerokube/ggr-ui

require (
github.com/aandryashin/reloader v0.0.0-20161127125235-da4f1b43ce40
github.com/aerokube/ggr v0.0.0-20181018070727-08e778c741ca
github.com/aerokube/util v0.0.0-20181001032247-3a9b3f70da09
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
github.com/aandryashin/matchers v0.0.0-20160729131923-5eb67beb188b h1:2hJ49uel4j48uteFY3ybBiSB35Ml86IZkSXAb+rj0lQ=
github.com/aandryashin/matchers v0.0.0-20160729131923-5eb67beb188b/go.mod h1:cbmYNkm9xeQlNoWEPtOUcvNok2gSD7ErMnYkRW+eHi8=
github.com/aandryashin/reloader v0.0.0-20161127125235-da4f1b43ce40 h1:zSKVi4h3Kv0HvNGjWPOsOEJIxtvd3PRMlVA/fcCB45g=
github.com/aandryashin/reloader v0.0.0-20161127125235-da4f1b43ce40/go.mod h1:gvg2/m9OQ4ZwK4Qk/mnfgokCb4qDN4BGyle+QGw4VOc=
github.com/abbot/go-http-auth v0.0.0-20161224193827-d45c47bedec7/go.mod h1:Cz6ARTIzApMJDzh5bRMSUou6UMSp0IEXg9km/ci7TJM=
github.com/aerokube/ggr v0.0.0-20181018070727-08e778c741ca h1:Ll5yx9I9tlk4naUHDbizEH8eouBXtV+e3C49dkpxFZs=
Expand All @@ -8,6 +9,7 @@ github.com/aerokube/util v0.0.0-20181001032247-3a9b3f70da09 h1:T3Y7aciF+tYzT5wXH
github.com/aerokube/util v0.0.0-20181001032247-3a9b3f70da09/go.mod h1:a1duJwYg3lfxakFPqpJsD41PYdkBmeUFPA4S+ISkHhQ=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
Expand All @@ -29,4 +31,5 @@ golang.org/x/net v0.0.0-20181017193950-04a2e542c03f h1:4pRM7zYwpBjCnfA1jRmhItLxY
golang.org/x/net v0.0.0-20181017193950-04a2e542c03f/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0 h1:8H8QZJ30plJyIVj60H3lr8TZGIq2Fh3Cyrs/ZNg1foU=
golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
20 changes: 20 additions & 0 deletions watch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// +build watch

package main

import (
"github.com/aandryashin/reloader"
"log"
"time"
)

func init() {

err := reloader.Watch(quotaDir, func() {
configure()
}, 5*time.Second)
if err != nil {
log.Fatalf("[-] [INIT] [Failed to init watching quota for changes: %v]", err)
}
log.Printf("[-] [INIT] [Watching quota directory %s for changes]", quotaDir)
}

0 comments on commit 236d258

Please sign in to comment.