forked from chrislusf/glow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal_executor_manager.go
50 lines (43 loc) · 1.05 KB
/
local_executor_manager.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
package agent
import (
"sync"
"time"
)
type LocalExecutorManager struct {
sync.Mutex
id2ExecutorStatus map[uint32]*AgentExecutorStatus
}
func newLocalExecutorsManager() *LocalExecutorManager {
m := &LocalExecutorManager{
id2ExecutorStatus: make(map[uint32]*AgentExecutorStatus),
}
go m.purgeExpiredEntries()
return m
}
func (m *LocalExecutorManager) getExecutorStatus(id uint32) *AgentExecutorStatus {
m.Lock()
defer m.Unlock()
executorStatus, ok := m.id2ExecutorStatus[id]
if ok {
return executorStatus
}
executorStatus = &AgentExecutorStatus{LastAccessTime: time.Now()}
m.id2ExecutorStatus[id] = executorStatus
return executorStatus
}
// purge executor status older than 24 hours to save memory
func (m *LocalExecutorManager) purgeExpiredEntries() {
for {
func() {
m.Lock()
cutoverLimit := time.Now().Add(-24 * time.Hour)
for id, executorStatus := range m.id2ExecutorStatus {
if executorStatus.LastAccessTime.Before(cutoverLimit) {
delete(m.id2ExecutorStatus, id)
}
}
m.Unlock()
time.Sleep(1 * time.Hour)
}()
}
}