Reset the directories when the stream gets disconnected (#152)

* Reset the directories when the stream gets disconnected

* Cleanup after a delay

Co-authored-by: Gabe Kangas <gabek@real-ity.com>
This commit is contained in:
Bradley Hilton 2020-09-16 15:31:21 -05:00 committed by GitHub
parent 80b2b9e668
commit dd9267f1ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import (
"os"
"path"
"strconv"
"time"
log "github.com/sirupsen/logrus"
@ -15,8 +16,9 @@ import (
)
var (
_stats *models.Stats
_storage models.ChunkStorageProvider
_stats *models.Stats
_storage models.ChunkStorageProvider
_cleanupTicker *time.Ticker
)
//Start starts up the core processing
@ -56,6 +58,25 @@ func createInitialOfflineState() error {
return nil
}
func startCleanupTimer() {
_cleanupTicker := time.NewTicker(5 * time.Minute)
go func() {
for {
select {
case <-_cleanupTicker.C:
resetDirectories()
}
}
}()
}
// StopCleanupTimer will stop the previous cleanup timer
func stopCleanupTimer() {
if _cleanupTicker != nil {
_cleanupTicker.Stop()
}
}
func resetDirectories() {
log.Trace("Resetting file directories to a clean slate.")

View File

@ -27,6 +27,8 @@ func GetStatus() models.Status {
//SetStreamAsConnected sets the stream as connected
func SetStreamAsConnected() {
stopCleanupTimer()
_stats.StreamConnected = true
_stats.LastConnectTime = utils.NullTime{time.Now(), true}
_stats.LastDisconnectTime = utils.NullTime{time.Now(), false}
@ -50,4 +52,5 @@ func SetStreamAsDisconnected() {
_stats.LastDisconnectTime = utils.NullTime{time.Now(), true}
ffmpeg.ShowStreamOfflineState()
startCleanupTimer()
}