cloudproxy: agent: refresh every 11 seconds

This commit is contained in:
Yousong Zhou
2021-05-10 14:16:30 +08:00
parent 1457b37c7d
commit a4d35457ca
2 changed files with 13 additions and 2 deletions

View File

@@ -150,6 +150,7 @@ func (c *Client) Start(ctx context.Context) {
sshClientC := make(chan *ssh.Client)
var sshClient *ssh.Client
go c.runClientState(ctx, sshClientC)
for {
select {
case sshClient = <-sshClientC:

View File

@@ -180,14 +180,24 @@ func (w *Worker) Start(ctx context.Context) {
}
go w.apih.Start(ctx)
var mss *agentmodels.ModelSets
const tickDur = 11 * time.Second
var (
mss *agentmodels.ModelSets
tick = time.NewTicker(tickDur)
)
for {
select {
case imss := <-w.apih.ModelSets():
log.Infof("agent: got new data from api helper")
mss = imss.(*agentmodels.ModelSets)
if err := w.run(ctx, mss); err != nil {
log.Errorf("agent: %v", err)
log.Errorf("agent run: %v", err)
}
case <-tick.C:
if mss != nil {
if err := w.run(ctx, mss); err != nil {
log.Errorf("agent refresh run: %v", err)
}
}
case <-ctx.Done():
return