Path: blob/main/components/ws-proxy/pkg/sshproxy/heartbeat.go
2500 views
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package sshproxy56import (7"context"8"time"910"github.com/gitpod-io/gitpod/common-go/log"11wsmanapi "github.com/gitpod-io/gitpod/ws-manager/api"12)1314type Heartbeat interface {15// SendHeartbeat sends a heartbeat for a workspace16SendHeartbeat(instanceID string, isClosed, ignoreIfActive bool)17}1819type noHeartbeat struct{}2021func (noHeartbeat) SendHeartbeat(instanceID string, isClosed, ignoreIfActive bool) {}2223type WorkspaceManagerHeartbeat struct {24Client wsmanapi.WorkspaceManagerClient25}2627func (m *WorkspaceManagerHeartbeat) SendHeartbeat(instanceID string, isClosed, ignoreIfActive bool) {28ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)29defer cancel()30_, err := m.Client.MarkActive(ctx, &wsmanapi.MarkActiveRequest{31Id: instanceID,32Closed: isClosed,33IgnoreIfActive: ignoreIfActive,34})35if err != nil {36log.WithError(err).Warn("cannot send heartbeat for workspace instance")37} else {38log.WithField("instanceId", instanceID).Debug("sent heartbeat to ws-manager")39}40}414243