Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop service in core main async #816

Merged
merged 1 commit into from
Mar 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package main

import (
"path/filepath"
"sync"

"github.com/mesg-foundation/core/api"
"github.com/mesg-foundation/core/config"
"github.com/mesg-foundation/core/database"
"github.com/mesg-foundation/core/interface/grpc"
"github.com/mesg-foundation/core/logger"
"github.com/mesg-foundation/core/version"
"github.com/mesg-foundation/core/x/xerrors"
"github.com/mesg-foundation/core/x/xsignal"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -65,7 +67,7 @@ func deployCoreServices(config *config.Config, api *api.API) error {
}
service.Sid = s.Sid
service.Hash = s.Hash
logrus.Infof("Service %q deployed with hash %s", service.Key, service.Hash)
logrus.Infof("Service %q deployed with hash %q", service.Key, service.Hash)
if err := api.StartService(s.Sid); err != nil {
return err
}
Expand All @@ -78,12 +80,28 @@ func stopRunningServices(api *api.API) error {
if err != nil {
return err
}
for _, s := range services {
if err := api.StopService(s.Hash); err != nil {
return err
}
var (
serviceLen = len(services)
errC = make(chan error, serviceLen)
wg sync.WaitGroup
)
wg.Add(serviceLen)
for _, service := range services {
go func(hash string) {
defer wg.Done()
err := api.StopService(hash)
if err != nil {
errC <- err
}
}(service.Hash)
}
return nil
wg.Wait()
close(errC)
var errs xerrors.Errors
for err := range errC {
errs = append(errs, err)
}
return errs.ErrorOrNil()
}

func main() {
Expand Down