heartbeat

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package heartbeat 实现定期心跳服务,用于监控系统状态并向用户发送活跃提醒。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Enabled  bool          // 是否启用心跳
	Interval time.Duration // 心跳探测间隔
	MaxIdle  time.Duration // 会话最大允许空闲时间(超过后停止发送心跳)
}

Config 控制心跳服务的运行时行为。

type DispatchFunc

type DispatchFunc func(ctx context.Context, channel, chatID, content, requestID string) error

DispatchFunc 定义了将心跳内容发送到目标会话的函数原型。

type ProbeFunc

type ProbeFunc func(ctx context.Context) (string, error)

ProbeFunc 定义了心跳探测函数的原型,返回简短的状态摘要。

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service 负责定期执行健康探测,并将结果分发到最近活跃的会话中。

func NewService

func NewService(cfg Config, probe ProbeFunc, dispatch DispatchFunc, stateMgr *appstate.Manager) *Service

NewService 创建并初始化一个新的心跳服务。

func (*Service) IsRunning

func (s *Service) IsRunning() bool

IsRunning 返回服务循环当前是否处于活跃状态。

func (*Service) RunOnce

func (s *Service) RunOnce(ctx context.Context) error

RunOnce 执行单次心跳探测并分发结果。

func (*Service) Start

func (s *Service) Start() error

Start 启动心跳服务的周期性循环。

func (*Service) Stop

func (s *Service) Stop()

Stop 停止心跳服务的周期性循环。

func (*Service) TrackActivity

func (s *Service) TrackActivity(channel, chatID string)

TrackActivity 更新并持久化最近活跃的通道与聊天 ID,用于确定心跳发送目标。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL