Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/ws-proxy/pkg/sshproxy/heartbeat.go
2500 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package sshproxy
6
7
import (
8
"context"
9
"time"
10
11
"github.com/gitpod-io/gitpod/common-go/log"
12
wsmanapi "github.com/gitpod-io/gitpod/ws-manager/api"
13
)
14
15
type Heartbeat interface {
16
// SendHeartbeat sends a heartbeat for a workspace
17
SendHeartbeat(instanceID string, isClosed, ignoreIfActive bool)
18
}
19
20
type noHeartbeat struct{}
21
22
func (noHeartbeat) SendHeartbeat(instanceID string, isClosed, ignoreIfActive bool) {}
23
24
type WorkspaceManagerHeartbeat struct {
25
Client wsmanapi.WorkspaceManagerClient
26
}
27
28
func (m *WorkspaceManagerHeartbeat) SendHeartbeat(instanceID string, isClosed, ignoreIfActive bool) {
29
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
30
defer cancel()
31
_, err := m.Client.MarkActive(ctx, &wsmanapi.MarkActiveRequest{
32
Id: instanceID,
33
Closed: isClosed,
34
IgnoreIfActive: ignoreIfActive,
35
})
36
if err != nil {
37
log.WithError(err).Warn("cannot send heartbeat for workspace instance")
38
} else {
39
log.WithField("instanceId", instanceID).Debug("sent heartbeat to ws-manager")
40
}
41
}
42
43