summaryrefslogtreecommitdiff
path: root/service/container.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-06-10 17:53:13 +0300
committerWolfy-J <[email protected]>2018-06-10 17:53:13 +0300
commit4fd4c7a1e8194287249fa59252afc2cd260d5643 (patch)
tree7f2f3872ff13ff063acca14d4294b4d299c3dea2 /service/container.go
parent094a4c211022b9446ef988c74c546ad6efb09722 (diff)
rr is working now
Diffstat (limited to 'service/container.go')
-rw-r--r--service/container.go19
1 files changed, 5 insertions, 14 deletions
diff --git a/service/container.go b/service/container.go
index 0e89f224..c47e0fd2 100644
--- a/service/container.go
+++ b/service/container.go
@@ -65,7 +65,7 @@ func (c *container) Register(name string, service Service) {
status: StatusRegistered,
})
- c.log.Debugf("%s: registered", color.GreenString(name))
+ c.log.Debugf("%s: registered", color.YellowString(name))
}
// Check hasStatus svc has been registered.
@@ -98,23 +98,20 @@ func (c *container) Get(target string) (svc Service, status int) {
// Configure configures all underlying services with given configuration.
func (c *container) Configure(cfg Config) error {
- c.mu.Lock()
- defer c.mu.Unlock()
-
for _, e := range c.services {
if e.getStatus() >= StatusConfigured {
- return fmt.Errorf("service %s has already been configured", color.GreenString(e.name))
+ return fmt.Errorf("service %s has already been configured", color.RedString(e.name))
}
segment := cfg.Get(e.name)
if segment == nil {
- c.log.Debugf("%s: no config has been provided", color.GreenString(e.name))
+ c.log.Debugf("%s: no config has been provided", color.YellowString(e.name))
continue
}
ok, err := e.svc.Configure(segment, c)
if err != nil {
- return errors.Wrap(err, fmt.Sprintf("%s", color.GreenString(e.name)))
+ return errors.Wrap(err, fmt.Sprintf("%s", color.RedString(e.name)))
} else if ok {
e.setStatus(StatusConfigured)
}
@@ -131,7 +128,6 @@ func (c *container) Serve() error {
)
defer close(done)
- c.mu.Lock()
for _, e := range c.services {
if e.hasStatus(StatusConfigured) {
numServing ++
@@ -145,12 +141,10 @@ func (c *container) Serve() error {
defer e.setStatus(StatusStopped)
if err := e.svc.Serve(); err != nil {
- c.log.Errorf("%s: %s", color.GreenString(e.name), err)
- done <- errors.Wrap(err, fmt.Sprintf("%s", color.GreenString(e.name)))
+ done <- errors.Wrap(err, fmt.Sprintf("%s", color.RedString(e.name)))
}
}(e)
}
- c.mu.Unlock()
for i := 0; i < numServing; i++ {
result := <-done
@@ -167,9 +161,6 @@ func (c *container) Serve() error {
// Stop sends stop command to all running services.
func (c *container) Stop() {
- c.mu.Lock()
- defer c.mu.Unlock()
-
for _, e := range c.services {
if e.hasStatus(StatusServing) {
e.svc.Stop()