scheduler

package
v0.19.5 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package scheduler periodically triggers collectors and persists the resulting documents.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSlackCollectorNotFound = fmt.Errorf("slack collector not configured")
	ErrSlackChannelNotFound   = fmt.Errorf("channel not found in bot member list")
)

Sentinel errors for Slack channel operations.

Functions

This section is empty.

Types

type ActiveDocumentCounter added in v0.19.4

type ActiveDocumentCounter interface {
	CountActiveDocuments(ctx context.Context, sourceType model.SourceType) (int, error)
}

ActiveDocumentCounter is an optional extension of DocumentUpserter. When the store implements it, the scheduler uses it to perform a deletion-ratio sanity check before calling MarkDeleted. If the ratio of documents that would be deleted exceeds deletionRatioThreshold the deletion is skipped and a warning is logged — this guards against bulk data-loss caused by a partially unmounted or glitching filesystem.

type DocumentUpserter

type DocumentUpserter interface {
	Upsert(ctx context.Context, doc *model.Document) error
	LastCollectedAt(ctx context.Context, instanceID string, src model.SourceType, fallback time.Time) time.Time
	UpdateCollectorState(ctx context.Context, instanceID string, src model.SourceType, lastCollectedAt time.Time) error
	RecordCollectionLog(ctx context.Context, src model.SourceType, started time.Time, count int, err error) error
	MarkDeleted(ctx context.Context, sourceType model.SourceType, activeIDs []string) (int, error)
	// ListUnembedded returns up to limit active documents with a NULL embedding.
	ListUnembedded(ctx context.Context, limit int) ([]*model.Document, error)
	// UpdateEmbedding persists the embedding vector for a single document.
	UpdateEmbedding(ctx context.Context, doc *model.Document) error
	// ActiveSourceIDSet returns the set of source_ids currently active in the
	// store for the given source type. Used by the filesystem collector to detect
	// files that are new (not yet indexed) regardless of their mtime.
	ActiveSourceIDSet(ctx context.Context, sourceType model.SourceType) (map[string]struct{}, error)
}

DocumentUpserter is the subset of the document store used by the scheduler.

type EntityExtractor

type EntityExtractor interface {
	UpsertAndLinkEntities(ctx context.Context, documentID uuid.UUID, entities []model.Entity) error
}

EntityExtractor is the subset of the entity store used by the scheduler to trigger best-effort entity extraction immediately after document ingestion. It is satisfied by *store.EntityStore.

type Scheduler

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

Scheduler wraps robfig/cron and manages periodic collection runs.

func New

func New(store DocumentUpserter, embed search.EmbeddingEngine, collectors ...collector.Collector) *Scheduler

New returns a Scheduler with the given collectors and storage backend. Use WithChunkStore to enable chunk-based FTS indexing (issue #9).

func (*Scheduler) Collectors

func (s *Scheduler) Collectors() []collector.Collector

Collectors returns the list of registered collectors (for status reporting).

func (*Scheduler) ForceCollectSlackChannel

func (s *Scheduler) ForceCollectSlackChannel(ctx context.Context, channelID, channelName string) (int, error)

ForceCollectSlackChannel runs a full-history collection (since = zero time) for a single Slack channel and persists the resulting documents. It bypasses the source-level LastCollectedAt and is intended for manual POST /api/v1/collect/slack/channel calls.

If channelID is empty, channelName is used to resolve the ID via the Slack API (the bot must be a member of the channel).

Returns the number of upserted documents and any error.

func (*Scheduler) LookupSlackChannel

func (s *Scheduler) LookupSlackChannel(ctx context.Context, name string) (id, channelName string, err error)

LookupSlackChannel resolves a channel name (case-insensitive, "#" stripped) to its Slack channel ID by querying the channels the bot is a member of. Returns ErrSlackCollectorNotFound when no Slack collector is configured, ErrSlackChannelNotFound when the name does not match any member channel.

func (*Scheduler) Register

func (s *Scheduler) Register(interval time.Duration) error

Register adds ONE cron job PER enabled collector (each "@every interval").

Cron runs each job in its own goroutine, so distinct collectors execute concurrently. A given collector still skips its own overlapping tick via a per-collector try-lock (runningPerCollector). This eliminates the head-of-line blocking that occurred when a single global job ran all collectors sequentially: a slow gmail backfill (~60 min) no longer prevents calendar, whisper, or SMS collectors from running on their scheduled ticks.

The old single-job / single-lock design that fixed the starvation bug is preserved in runAll, which is still used by TriggerAll.

func (*Scheduler) Start

func (s *Scheduler) Start()

Start begins the cron scheduler. It is non-blocking.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop gracefully halts the scheduler and waits for running jobs to finish.

func (*Scheduler) TriggerAll

func (s *Scheduler) TriggerAll(ctx context.Context)

TriggerAll runs all enabled collectors immediately in the background, each in its own goroutine under its own per-collector lock. It is intended for manual /collect/trigger API calls. Collectors already running on their scheduled tick are skipped for the duration of that overlap; others proceed immediately.

func (*Scheduler) WithChunkStore

func (s *Scheduler) WithChunkStore(cs *store.ChunkStore) *Scheduler

WithChunkStore attaches a ChunkStore so that each collected document is split into overlapping text chunks and stored in the chunks table for FTS indexing. When not called, chunk storage is disabled and the scheduler behaves as before (full-document FTS via documents.tsv only).

func (*Scheduler) WithCutover added in v0.16.4

func (s *Scheduler) WithCutover(t time.Time) *Scheduler

WithCutover sets the cutover floor time that is propagated to every CutoverAwareCollector (SMS, Whisper) registered with this scheduler. When non-zero, those collectors will not emit records whose event time (OccurredAt for SMS/call-log, mtime for Whisper) is before t — even when the record was never indexed (IndexAware path).

Zero t (the default) disables the floor entirely (no behaviour change).

func (*Scheduler) WithEntityExtraction

func (s *Scheduler) WithEntityExtraction(entities EntityExtractor, client llm.Completer) *Scheduler

WithEntityExtraction attaches the entity store and LLM client so that entity extraction is attempted inline after each document is persisted.

This method should only be called when entity extraction is explicitly enabled (ENTITY_EXTRACTION_ENABLED=true in cmd/collector/main.go). When not called, s.entities and s.llmClient remain nil and the extractEntities call in processBatch is skipped entirely — zero LLM calls are made.

Extraction is BEST-EFFORT: failures are logged as warnings and never block document ingestion. Safe to call with nil arguments — extraction is silently disabled in that case.

func (*Scheduler) WithInstance

func (s *Scheduler) WithInstance(id string) *Scheduler

WithInstance sets the collector instance identifier used to key per-instance watermark state. Defaults to "default" when not called.

Jump to

Keyboard shortcuts

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