1
0
mirror of https://github.com/bingohuang/docker-labs.git synced 2025-10-05 01:43:22 +08:00

Change import paths

Add session cleanup
This commit is contained in:
Jonathan Leibiusky (@xetorthio)
2016-10-08 10:25:10 +02:00
parent 0d693b344c
commit b6b849e2c6
9 changed files with 32 additions and 9 deletions

View File

@@ -1,8 +1,11 @@
package services
import (
"log"
"time"
"github.com/franela/play-with-docker/types"
"github.com/twinj/uuid"
"github.com/xetorthio/play-with-docker/types"
)
var sessions map[string]*types.Session
@@ -19,6 +22,16 @@ func NewSession() (*types.Session, error) {
//TODO: Store in something like redis
sessions[s.Id] = s
// Schedule cleanup of the session
time.AfterFunc(1*time.Minute, func() {
for _, i := range s.Instances {
if err := DeleteContainer(i.Name); err != nil {
log.Println(err)
}
}
DeleteNetwork(s.Id)
})
if err := CreateNetwork(s.Id); err != nil {
return nil, err
}