Documentation
¶
Overview ¶
Package scheduler periodically triggers collectors and persists the resulting documents.
Index ¶
- Variables
- type DocumentUpserter
- type EntityExtractor
- type Scheduler
- func (s *Scheduler) Collectors() []collector.Collector
- func (s *Scheduler) ForceCollectSlackChannel(ctx context.Context, channelID, channelName string) (int, error)
- func (s *Scheduler) LookupSlackChannel(ctx context.Context, name string) (id, channelName string, err error)
- func (s *Scheduler) Register(interval time.Duration) error
- func (s *Scheduler) Start()
- func (s *Scheduler) Stop()
- func (s *Scheduler) TriggerAll(ctx context.Context)
- func (s *Scheduler) WithChunkStore(cs *store.ChunkStore) *Scheduler
- func (s *Scheduler) WithEntityExtraction(entities EntityExtractor, client llm.Completer) *Scheduler
- func (s *Scheduler) WithInstance(id string) *Scheduler
Constants ¶
This section is empty.
Variables ¶
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 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 have never been 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 ¶
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 ¶
Register adds a cron job for each enabled collector using the given interval (e.g. "@every 1h").
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 ¶
TriggerAll runs all enabled collectors immediately in the background. It is intended for manual /collect/trigger API calls. If a collection is already in progress the call is a no-op and a warning is logged.
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) 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 ¶
WithInstance sets the collector instance identifier used to key per-instance watermark state. Defaults to "default" when not called.