forked from Threadfin/Threadfin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaintenance.go
More file actions
98 lines (72 loc) · 1.75 KB
/
maintenance.go
File metadata and controls
98 lines (72 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package src
import (
"fmt"
"math/rand"
"time"
)
// InitMaintenance : Wartungsprozess initialisieren
func InitMaintenance() (err error) {
rand.Seed(time.Now().Unix())
System.TimeForAutoUpdate = fmt.Sprintf("0%d%d", randomTime(0, 2), randomTime(10, 59))
go maintenance()
return
}
func maintenance() {
for {
var t = time.Now()
// Aktualisierung der Playlist und XMLTV Dateien
systemMutex.Lock()
if System.ScanInProgress == 0 {
systemMutex.Unlock()
for _, schedule := range Settings.Update {
if schedule == t.Format("1504") {
showInfo("Update:" + schedule)
// Backup erstellen
err := ThreadfinAutoBackup()
if err != nil {
ShowError(err, 000)
}
// Playlist und XMLTV Dateien aktualisieren
getProviderData("m3u", "")
getProviderData("hdhr", "")
if Settings.EpgSource == "XEPG" {
getProviderData("xmltv", "")
}
// Datenbank für DVR erstellen
err = buildDatabaseDVR()
if err != nil {
ShowError(err, 000)
}
systemMutex.Lock()
if !Settings.CacheImages && System.ImageCachingInProgress == 0 {
systemMutex.Unlock()
removeChildItems(System.Folder.ImagesCache)
} else {
systemMutex.Unlock()
}
// XEPG Dateien erstellen
systemMutex.Lock()
Data.Cache.XMLTV = make(map[string]XMLTV)
systemMutex.Unlock()
buildXEPG(false)
}
}
// Update Threadfin (Binary)
systemMutex.Lock()
if System.TimeForAutoUpdate == t.Format("1504") {
systemMutex.Unlock()
BinaryUpdate()
} else {
systemMutex.Unlock()
}
} else {
systemMutex.Unlock()
}
time.Sleep(60 * time.Second)
}
return
}
func randomTime(min, max int) int {
rand.Seed(time.Now().Unix())
return rand.Intn(max-min) + min
}