-
Notifications
You must be signed in to change notification settings - Fork 65
/
periodic.go
56 lines (51 loc) · 1.45 KB
/
periodic.go
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
package main
import (
"time"
)
func do_restart( config *Config, devd *RunningDev ) {
if config.Stf.AdminToken != "" {
stf_reserve( config, devd.uuid )
}
restart_wdaproxy( devd, false )
wait_wdaup( devd )
if config.Stf.AdminToken != "" {
stf_release( config, devd.uuid )
}
}
func test_restart_on_release( devd *RunningDev ) {
restart_closure := func() { do_restart( devd.confDup, devd ) }
stf_on_release( restart_closure )
}
func periodic_start( config *Config, devd *RunningDev ) {
endChan := devd.periodic
wdaRestartMinutes := config.Timing.WdaRestart
go func() {
minute := 0
stop := false
for {
time.Sleep( time.Minute * 1 )
minute++
if wdaRestartMinutes != 0 {
if ( minute % wdaRestartMinutes ) == 0 { // every 4 hours by default
if devd.owner == "" {
do_restart( config, devd )
} else {
restart_closure := func() { do_restart( config, devd ) }
stf_on_release( restart_closure )
}
}
}
select {
case <- endChan:
stop = true
break
default:
}
if stop { break }
}
} ()
}
func periodic_stop( devd *RunningDev ) {
endChan := devd.periodic
endChan <- true
}