-
-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #252 from spiral/rr_1.6.2
release 1.6.2
- Loading branch information
Showing
17 changed files
with
1,176 additions
and
85 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
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
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,66 @@ | ||
package reload | ||
|
||
import ( | ||
"errors" | ||
"github.com/spiral/roadrunner" | ||
"github.com/spiral/roadrunner/service" | ||
"time" | ||
) | ||
|
||
// Config is a Reload configuration point. | ||
type Config struct { | ||
// Interval is a global refresh interval | ||
Interval time.Duration | ||
|
||
// Patterns is a global file patterns to watch. It will be applied to every directory in project | ||
Patterns []string | ||
|
||
// Services is set of services which would be reloaded in case of FS changes | ||
Services map[string]ServiceConfig | ||
} | ||
|
||
type ServiceConfig struct { | ||
// Enabled indicates that service must be watched, doest not required when any other option specified | ||
Enabled bool | ||
|
||
// Recursive is options to use nested files from root folder | ||
Recursive bool | ||
|
||
// Patterns is per-service specific files to watch | ||
Patterns []string | ||
|
||
// Dirs is per-service specific dirs which will be combined with Patterns | ||
Dirs []string | ||
|
||
// Ignore is set of files which would not be watched | ||
Ignore []string | ||
|
||
// service is a link to service to restart | ||
service *roadrunner.Controllable | ||
} | ||
|
||
// Hydrate must populate Config values using given Config source. Must return error if Config is not valid. | ||
func (c *Config) Hydrate(cfg service.Config) error { | ||
if err := cfg.Unmarshal(c); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// InitDefaults sets missing values to their default values. | ||
func (c *Config) InitDefaults() error { | ||
c.Interval = time.Second | ||
c.Patterns = []string{".php"} | ||
|
||
return nil | ||
} | ||
|
||
// Valid validates the configuration. | ||
func (c *Config) Valid() error { | ||
if c.Interval < time.Second { | ||
return errors.New("too short interval") | ||
} | ||
|
||
return nil | ||
} |
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,55 @@ | ||
package reload | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func Test_Config_Valid(t *testing.T) { | ||
services := make(map[string]ServiceConfig) | ||
services["test"] = ServiceConfig{ | ||
Recursive: false, | ||
Patterns: nil, | ||
Dirs: nil, | ||
Ignore: nil, | ||
service: nil, | ||
} | ||
|
||
cfg := &Config{ | ||
Interval: time.Second, | ||
Patterns: nil, | ||
Services: services, | ||
} | ||
assert.NoError(t, cfg.Valid()) | ||
} | ||
|
||
func Test_Fake_ServiceConfig(t *testing.T) { | ||
services := make(map[string]ServiceConfig) | ||
cfg := &Config{ | ||
Interval: time.Second, | ||
Patterns: nil, | ||
Services: services, | ||
} | ||
assert.Error(t, cfg.Valid()) | ||
} | ||
|
||
func Test_Interval(t *testing.T) { | ||
services := make(map[string]ServiceConfig) | ||
cfg := &Config{ | ||
Interval: time.Millisecond, | ||
Patterns: nil, | ||
Services: services, | ||
} | ||
assert.Error(t, cfg.Valid()) | ||
} | ||
|
||
func Test_NoServiceConfig(t *testing.T) { | ||
services := make(map[string]ServiceConfig) | ||
cfg := &Config{ | ||
Interval: time.Millisecond, | ||
Patterns: nil, | ||
Services: services, | ||
} | ||
assert.Error(t, cfg.Valid()) | ||
} |
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,9 @@ | ||
// +build !windows | ||
|
||
package reload | ||
|
||
import "os" | ||
|
||
func sameFile(fi1, fi2 os.FileInfo) bool { | ||
return os.SameFile(fi1, fi2) | ||
} |
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,12 @@ | ||
// +build windows | ||
|
||
package reload | ||
|
||
import "os" | ||
|
||
func sameFile(fi1, fi2 os.FileInfo) bool { | ||
return fi1.ModTime() == fi2.ModTime() && | ||
fi1.Size() == fi2.Size() && | ||
fi1.Mode() == fi2.Mode() && | ||
fi1.IsDir() == fi2.IsDir() | ||
} |
Oops, something went wrong.