mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
|
|
// Licensed under the GNU Affero General Public License (AGPL).
|
|
// See License.AGPL.txt in the project root for license information.
|
|
|
|
package sshproxy
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/gitpod-io/gitpod/common-go/log"
|
|
wsmanapi "github.com/gitpod-io/gitpod/ws-manager/api"
|
|
)
|
|
|
|
type Heartbeat interface {
|
|
// SendHeartbeat sends a heartbeat for a workspace
|
|
SendHeartbeat(instanceID string, isClosed, ignoreIfActive bool)
|
|
}
|
|
|
|
type noHeartbeat struct{}
|
|
|
|
func (noHeartbeat) SendHeartbeat(instanceID string, isClosed, ignoreIfActive bool) {}
|
|
|
|
type WorkspaceManagerHeartbeat struct {
|
|
Client wsmanapi.WorkspaceManagerClient
|
|
}
|
|
|
|
func (m *WorkspaceManagerHeartbeat) SendHeartbeat(instanceID string, isClosed, ignoreIfActive bool) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
defer cancel()
|
|
_, err := m.Client.MarkActive(ctx, &wsmanapi.MarkActiveRequest{
|
|
Id: instanceID,
|
|
Closed: isClosed,
|
|
IgnoreIfActive: ignoreIfActive,
|
|
})
|
|
if err != nil {
|
|
log.WithError(err).Warn("cannot send heartbeat for workspace instance")
|
|
} else {
|
|
log.WithField("instanceId", instanceID).Debug("sent heartbeat to ws-manager")
|
|
}
|
|
}
|