mirror of
https://github.com/bingohuang/docker-labs.git
synced 2025-08-05 00:39:50 +08:00
Show when session has expired
This commit is contained in:
parent
a0ffe28be9
commit
4950f03404
@ -23,30 +23,35 @@ func NewSession() (*types.Session, error) {
|
|||||||
sessions[s.Id] = s
|
sessions[s.Id] = s
|
||||||
|
|
||||||
// Schedule cleanup of the session
|
// Schedule cleanup of the session
|
||||||
time.AfterFunc(1*time.Minute, func() {
|
time.AfterFunc(1*time.Hour, func() {
|
||||||
|
s = GetSession(s.Id)
|
||||||
|
log.Printf("Starting clean up of session [%s]\n", s.Id)
|
||||||
for _, i := range s.Instances {
|
for _, i := range s.Instances {
|
||||||
if err := DeleteContainer(i.Name); err != nil {
|
if err := DeleteContainer(i.Name); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DeleteNetwork(s.Id)
|
if err := DeleteNetwork(s.Id); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
delete(sessions, s.Id)
|
||||||
|
log.Printf("Cleaned up session [%s]\n", s.Id)
|
||||||
})
|
})
|
||||||
|
|
||||||
if err := CreateNetwork(s.Id); err != nil {
|
if err := CreateNetwork(s.Id); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Schedule deletion after an hour
|
|
||||||
|
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSession(sessionId string) *types.Session {
|
func GetSession(sessionId string) *types.Session {
|
||||||
//TODO: Use redis
|
//TODO: Use redis
|
||||||
s := sessions[sessionId]
|
s, found := sessions[sessionId]
|
||||||
if instances[sessionId] != nil {
|
if found {
|
||||||
s.Instances = instances[sessionId]
|
s.Instances = instances[sessionId]
|
||||||
}
|
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,9 @@
|
|||||||
if ($scope.instances.length) {
|
if ($scope.instances.length) {
|
||||||
$scope.showInstance($scope.instances[0]);
|
$scope.showInstance($scope.instances[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Since session exists, we check it still exists every 10 seconds
|
||||||
|
$scope.checkHandler = setInterval(checkSession, 10*1000);
|
||||||
}, function(response) {
|
}, function(response) {
|
||||||
if (response.status == 404) {
|
if (response.status == 404) {
|
||||||
document.write('session not found');
|
document.write('session not found');
|
||||||
@ -79,5 +82,17 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$scope.getSession($scope.sessionId);
|
$scope.getSession($scope.sessionId);
|
||||||
|
|
||||||
|
function checkSession() {
|
||||||
|
$http({
|
||||||
|
method: 'GET',
|
||||||
|
url: '/sessions/' + $scope.sessionId,
|
||||||
|
}).then(function(response) {}, function(response) {
|
||||||
|
if (response.status == 404) {
|
||||||
|
clearInterval($scope.checkHandler);
|
||||||
|
$scope.showAlert('Session timedout!', 'Your session has expire and all your instances has been deleted.')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}]);
|
}]);
|
||||||
})();
|
})();
|
||||||
|
@ -40,6 +40,9 @@
|
|||||||
<p>
|
<p>
|
||||||
Add instances to your playground.
|
Add instances to your playground.
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong>Sessions and all their instances are deleted after 1 hour.</strong>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div flex></div>
|
<div flex></div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user