This commit is contained in:
asoseil 2018-02-08 13:55:08 +01:00
parent 0cc05cff1f
commit e1ec6e46c4
6 changed files with 26 additions and 8 deletions

View File

@ -38,6 +38,7 @@ func main() {
&cli.BoolFlag{Name: "install", Aliases: []string{"i"}, Value: false, Usage: "Enable go install"}, &cli.BoolFlag{Name: "install", Aliases: []string{"i"}, Value: false, Usage: "Enable go install"},
&cli.BoolFlag{Name: "build", Aliases: []string{"b"}, Value: false, Usage: "Enable go build"}, &cli.BoolFlag{Name: "build", Aliases: []string{"b"}, Value: false, Usage: "Enable go build"},
&cli.BoolFlag{Name: "run", Aliases: []string{"nr"}, Value: false, Usage: "Enable go run"}, &cli.BoolFlag{Name: "run", Aliases: []string{"nr"}, Value: false, Usage: "Enable go run"},
&cli.BoolFlag{Name: "legacy", Aliases: []string{"l"}, Value: false, Usage: "Legacy watch by polling instead fsnotify"},
&cli.BoolFlag{Name: "no-config", Aliases: []string{"nc"}, Value: false, Usage: "Ignore existing config and doesn't create a new one"}, &cli.BoolFlag{Name: "no-config", Aliases: []string{"nc"}, Value: false, Usage: "Ignore existing config and doesn't create a new one"},
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
@ -1117,6 +1118,10 @@ func setup(c *cli.Context) (err error) {
// Start realize workflow // Start realize workflow
func start(c *cli.Context) (err error) { func start(c *cli.Context) (err error) {
r.Server = realize.Server{Parent: &r, Status: false, Open: false, Port: realize.Port, Host: realize.Host} r.Server = realize.Server{Parent: &r, Status: false, Open: false, Port: realize.Port, Host: realize.Host}
// set legacy watcher
if c.Bool("legacy"){
r.Settings.Legacy.Set(1)
}
// check no-config and read // check no-config and read
if !c.Bool("no-config") { if !c.Bool("no-config") {
// read a config if exist // read a config if exist

View File

@ -18,7 +18,7 @@ var (
// RPrefix tool name // RPrefix tool name
RPrefix = "realize" RPrefix = "realize"
// RVersion current version // RVersion current version
RVersion = "2.0.1" RVersion = "2.1"
// RExt file extension // RExt file extension
RExt = ".yaml" RExt = ".yaml"
// RFile config file name // RFile config file name

View File

@ -2,7 +2,7 @@ package realize
// this code is imported from moby, unfortunately i can't import it directly as dependencies from its repo, // this code is imported from moby, unfortunately i can't import it directly as dependencies from its repo,
// cause there was a problem between moby vendor and fsnotify // cause there was a problem between moby vendor and fsnotify
// i have just added only walk methods and some little changes to polling interval, originally set as static. // i have just added only the walk methods and some little changes to polling interval, originally set as static.
import ( import (
"errors" "errors"
@ -57,7 +57,7 @@ type (
// PollingWatcher returns a poll-based file watcher // PollingWatcher returns a poll-based file watcher
func PollingWatcher(interval time.Duration) FileWatcher { func PollingWatcher(interval time.Duration) FileWatcher {
if interval == 0 { if interval == 0 {
interval = 100 * time.Millisecond interval = time.Duration(1) * time.Second
} }
return &filePoller{ return &filePoller{
interval: interval, interval: interval,
@ -67,13 +67,13 @@ func PollingWatcher(interval time.Duration) FileWatcher {
} }
// NewFileWatcher tries to use an fs-event watcher, and falls back to the poller if there is an error // NewFileWatcher tries to use an fs-event watcher, and falls back to the poller if there is an error
func NewFileWatcher(force bool, interval time.Duration) (FileWatcher, error) { func NewFileWatcher(l Legacy) (FileWatcher, error) {
if !force { if !l.Force {
if w, err := EventWatcher(); err == nil { if w, err := EventWatcher(); err == nil {
return w, nil return w, nil
} }
} }
return PollingWatcher(interval), nil return PollingWatcher(l.Interval), nil
} }
// EventWatcher returns an fs-event based file watcher // EventWatcher returns an fs-event based file watcher

View File

@ -274,7 +274,7 @@ func (p *Project) Watch(wg *sync.WaitGroup) {
// change channel // change channel
p.stop = make(chan bool) p.stop = make(chan bool)
// init a new watcher // init a new watcher
p.watcher, err = NewFileWatcher(p.parent.Settings.Legacy.Force, p.parent.Settings.Legacy.Interval) p.watcher, err = NewFileWatcher(p.parent.Settings.Legacy)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -100,7 +100,9 @@ func TestProject_Reload(t *testing.T) {
parent: &r, parent: &r,
}) })
input := "test/path" input := "test/path"
r.Projects[0].watcher, _ = NewFileWatcher(false, 0) r.Settings.Legacy.Force = false
r.Settings.Legacy.Interval = 0
r.Projects[0].watcher, _ = NewFileWatcher(r.Settings.Legacy)
r.Reload = func(context Context) { r.Reload = func(context Context) {
log.Println(context.Path) log.Println(context.Path)
} }

View File

@ -61,6 +61,17 @@ type Resource struct {
Name string Name string
} }
// Set legacy watcher with an interval
func (l *Legacy) Set(interval int){
l.Force = true
l.Interval = time.Duration(interval) * time.Second
}
// Unset legacy watcher
func (l *Legacy) Unset(){
l.Force = false
}
// Remove realize folder // Remove realize folder
func (s *Settings) Remove(d string) error { func (s *Settings) Remove(d string) error {
_, err := os.Stat(d) _, err := os.Stat(d)