From a2cbbae3835fc7e7a01cf643a6fe88956f186ffe Mon Sep 17 00:00:00 2001 From: franklin Date: Sun, 19 Mar 2017 17:06:11 +0100 Subject: [PATCH] added auto-update flag --- README.md | 2 +- neosproxy.go | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8828183..478e739 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Furthermore you need to define on which address the proxy should listen. The NEOS endpoint must be configured by setting the "neos" parameter as well. ``` -neosproxy --address=":80" --neos="https://www.myneosendpoint.com" +neosproxy --address=":80" --neos="https://www.myneosendpoint.com" --auto-update="1h" ``` web hooks diff --git a/neosproxy.go b/neosproxy.go index 023ac4e..a23abf8 100644 --- a/neosproxy.go +++ b/neosproxy.go @@ -203,7 +203,6 @@ func main() { apiKey := os.Getenv("API_KEY") if apiKey == "" { log.Fatal("missing env variable API_KEY") - return } flagAddress := flag.String("address", "0.0.0.0:80", "address to listen to") @@ -214,6 +213,9 @@ func main() { flagCallbackTLSVerify := flag.Bool("callback-tls-verify", true, "skip TLS verification on web callbacks") flagCallbackUpdated := flag.String("callback-updated", "", "comma seperated list of urls to notify on update event") + // Update flags + flagAutoUpdate := flag.String("auto-update", "", "duration value on which to automatically update the proxy") + flag.Parse() neosURL, err := url.Parse(*flagNeosHostname) @@ -232,6 +234,25 @@ func main() { CallbackUpdated: strings.Split(*flagCallbackUpdated, ","), } + if *flagAutoUpdate != "" { + autoUpdate, err := time.ParseDuration(*flagAutoUpdate) + if err != nil { + log.Fatal("invalid auto-update duration value: " + err.Error()) + } + go func() { + log.Println("starting with auto update every " + *flagAutoUpdate) + for { + time.Sleep(autoUpdate) + select { + case p.CacheInvalidationChannel <- time.Now(): + log.Println("auto update: added cache invalidation request to queue") + default: + log.Println("auto update: ignored cache invalidation request due to pending invalidation requests") + } + } + }() + } + fmt.Println("start proxy on ", *flagAddress, "for neos", *flagNeosHostname, "with cache file in", p.FilenameCachedContentServerExport) if err := p.run(); err != nil { log.Fatal(err)