hooks

package
v0.1.28 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 13 Imported by: 0

Documentation

Overview

Package hooks watches filesystem paths and spawns tasks when things change.

Index

Constants

View Source
const (
	EventFsCreate     = "fs.create"
	EventFsWrite      = "fs.write"
	EventFsDelete     = "fs.delete"
	EventSourceChange = "source.change"
)

Variables

This section is empty.

Functions

func DecodeToken

func DecodeToken(stored []byte) (string, error)

func EncodeToken

func EncodeToken(raw string) ([]byte, error)

func NormalizePath

func NormalizePath(p string) string

func ParseUint

func ParseUint(v any) uint

Types

type Engine

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

func NewEngine

func NewEngine(store repository.FilesystemStore, creator TaskCreator, backend repository.BackendRepository) *Engine

func (*Engine) Handle

func (eng *Engine) Handle(id string, data map[string]any)

func (*Engine) InvalidateCache

func (eng *Engine) InvalidateCache(wsId uint)

func (*Engine) Poll

func (eng *Engine) Poll(ctx context.Context)

Poll reaps stuck tasks and retries failed ones. Exported for testing.

func (*Engine) Start

func (eng *Engine) Start(ctx context.Context)

Start runs the retry poller. Call as a goroutine.

type QueryRefresher

type QueryRefresher interface {
	RefreshQuery(ctx context.Context, query *types.FilesystemQuery) error
}

QueryRefresher executes a source query and emits change events. Implemented by SourceService in the gateway layer.

type SeenTracker

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

SeenTracker detects new query result IDs by diffing against the previous set. Usage: Compare (read-only) → act on new IDs → Commit (update stored set). This two-phase approach ensures the stored set only advances after the caller has successfully processed the new IDs.

func NewSeenTracker

func NewSeenTracker(rdb *common.RedisClient) *SeenTracker

func (*SeenTracker) Commit

func (t *SeenTracker) Commit(ctx context.Context, key string, current []string) error

Commit replaces the stored set with current and refreshes the TTL. Call only after the caller has successfully acted on the new IDs from Compare.

func (*SeenTracker) Compare

func (t *SeenTracker) Compare(ctx context.Context, key string, current []string) ([]string, error)

Compare returns IDs in current that weren't in the previous set at key. Does NOT modify the stored set -- call Commit after successful processing. Returns nil on first call (empty stored set) to avoid a false-positive flood.

func (*SeenTracker) Diff

func (t *SeenTracker) Diff(ctx context.Context, key string, current []string) ([]string, error)

Diff is a convenience that combines Compare + Commit in one call. Use Compare + Commit separately when you need to confirm delivery before advancing.

type Service

type Service struct {
	Store    repository.FilesystemStore
	Backend  repository.BackendRepository
	EventBus *common.EventBus
}

Service handles hook CRUD. Shared by HTTP and gRPC handlers.

func (*Service) Create

func (s *Service) Create(ctx context.Context, wsId uint, memberId, tokenId *uint, rawToken, path, prompt string) (*types.Hook, error)

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, externalId string) error

func (*Service) Get

func (s *Service) Get(ctx context.Context, externalId string) (*types.Hook, error)

func (*Service) List

func (s *Service) List(ctx context.Context, wsId uint) ([]*types.Hook, error)

func (*Service) ListRuns

func (s *Service) ListRuns(ctx context.Context, hookId uint) ([]*types.Task, error)

ListRuns returns tasks associated with a hook.

func (*Service) Update

func (s *Service) Update(ctx context.Context, externalId string, prompt *string, active *bool) (*types.Hook, error)

type SourcePoller

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

SourcePoller periodically refreshes source queries watched by active hooks. Each query is locked via Redis SETNX so only one replica refreshes it per interval.

func NewSourcePoller

func NewSourcePoller(store repository.FilesystemStore, refresher QueryRefresher, rdb *common.RedisClient) *SourcePoller

func (*SourcePoller) Poll

func (p *SourcePoller) Poll(ctx context.Context)

Poll fetches stale watched queries and refreshes them with distributed locking.

func (*SourcePoller) Start

func (p *SourcePoller) Start(ctx context.Context)

Start runs the poll loop. Call as a goroutine.

type TaskCreator

type TaskCreator interface {
	CreateTask(ctx context.Context, wsId uint, memberId *uint, token, prompt string, hookId uint, attempt, max int) error
}

Jump to

Keyboard shortcuts

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