This repository has been archived by the owner on Oct 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix source code formatting * Init fs watch. Move bats test to dedicated dir * Refactor file watching * Add notification channel to config watcher * Fix path to bats tests in CircleCI config * observer implementation (#5) * config file watching, "requiedHash" support * vendor fsnotify (and update some dependencies) * Upgrade vendored `color` package. Add StdErr outup * Revert changes in a vendor dir * Fix bats test directory paths * problem: duplicate config flags (#6)
- Loading branch information
Showing
82 changed files
with
4,723 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package core | ||
|
||
import ( | ||
"log" | ||
"path/filepath" | ||
|
||
"github.com/fsnotify/fsnotify" | ||
) | ||
|
||
type configWatchdog struct { | ||
path string | ||
watcher *fsnotify.Watcher | ||
observers []func(*SufficientChainConfig) | ||
} | ||
|
||
// NewConfigWatchdog creates new file watcher for config | ||
// directory | ||
func NewConfigWatchdog() (*configWatchdog, error) { | ||
path := flaggedExternalChainConfigPath // pull the package-level variable | ||
watcher, err := fsnotify.NewWatcher() | ||
if err != nil { | ||
return nil, err | ||
} | ||
// monitor entire directory - we assume, that files can be included only from this directory | ||
err = watcher.Add(filepath.Dir(path)) | ||
|
||
return &configWatchdog{path, watcher, nil}, err | ||
} | ||
|
||
// Start config directory watching | ||
func (cw *configWatchdog) Start() { | ||
go func() { | ||
for { | ||
select { | ||
case event := <-cw.watcher.Events: | ||
log.Println("event:", event) | ||
if event.Op&fsnotify.Write == fsnotify.Write { | ||
log.Println("modified file:", event.Name) | ||
newConfig, err := ReadExternalChainConfigFromFile(cw.path) | ||
if err != nil { | ||
log.Println("configuration error:", err) | ||
continue | ||
} | ||
for _, observer := range cw.observers { | ||
observer(newConfig) | ||
} | ||
} | ||
case err := <-cw.watcher.Errors: | ||
log.Println("error:", err) | ||
} | ||
} | ||
}() | ||
} | ||
|
||
// Stop config directory watching | ||
func (cw *configWatchdog) Stop() error { | ||
return cw.watcher.Close() | ||
} | ||
|
||
func (cw *configWatchdog) Subscribe(observer func(*SufficientChainConfig)) { | ||
cw.observers = append(cw.observers, observer) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.