Load sessions in parallel

This commit is contained in:
Jonathan Leibiusky @xetorthio
2017-06-10 18:18:30 -03:00
parent a95d1cd08d
commit 33febafb43
4 changed files with 134 additions and 17 deletions

View File

@@ -197,22 +197,31 @@ func (p *pwd) SessionLoadAndPrepare() error {
return err
}
wg := sync.WaitGroup{}
for _, s := range sessions {
err := p.prepareSession(s)
if err != nil {
return err
}
for _, i := range s.Instances {
// wire the session back to the instance
i.session = s
go p.InstanceAttachTerminal(i)
}
// Connect PWD daemon to the new network
if s.PwdIpAddress == "" {
return fmt.Errorf("Cannot load stored sessions as they don't have the pwd ip address stored with them")
}
wg.Add(1)
go func(s *Session) {
s.rw.Lock()
defer s.rw.Unlock()
defer wg.Done()
err := p.prepareSession(s)
if err != nil {
log.Println(err)
}
for _, i := range s.Instances {
// wire the session back to the instance
i.session = s
go p.InstanceAttachTerminal(i)
}
}(s)
}
wg.Wait()
setGauges()
return nil