ingest

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 7 Imported by: 1 module, 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 ingest drives the Slack source: discovery, change detection by object version, detail reads of what moved, and saves through the source's store.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunJob

func RunJob(ctx context.Context, j Job, now time.Time) (summary, skipped string, err error)

RunJob is one run of j: Prepare, Run, After.

Types

type Facts

type Facts interface{ Units() []unit.Unit }

Facts is a source's typed payload; it may name units not seen before.

type Job

type Job struct {
	Every time.Duration
	// Prepare builds one run's registration; a non-empty skip, such as a
	// low budget, runs nothing and is the job's skipped text.
	Prepare func(ctx context.Context, now time.Time) (p Plan, skip string, err error)
}

Job is a source's ingestion job: the daemon runs it every Every with RunJob.

type Plan

type Plan struct {
	Registration
	// After runs once Run returns, with its report and error, and gives the
	// job's outcome; nil summarizes the report and returns Run's error.
	After func(ctx context.Context, rep Report, err error) (summary, skipped string, _ error)
}

Plan is one run of a Job.

type Registration

type Registration struct {
	Source Source
	Store  SourceStore
	// Valid says why key is not a unit key of the source.
	Valid func(key string) error
}

Registration is one source with its store and how its unit keys are checked.

type Report

type Report struct {
	Provider          unit.ProviderID
	Discovered, Moved int
	Read              []unit.Unit // units of the read facts, distinct, sorted by Unit.Less
	Cursor            string      // the cursor saved by this pass
}

Report is what one pass did.

func Run

func Run(ctx context.Context, r Registration, now time.Time) (Report, error)

Run is one two-phase pass: Discover from the stored cursor, Stubs of Watched (minus discovered), compare each object's Version with Versions, Read what moved or is unknown, Save (light facts of every stub, read facts, cursor), See every object returned. It spends no budget itself: the source's client does. Passes of one provider never interleave.

func Touch

func Touch(ctx context.Context, r Registration, objects []string, now time.Time) (Report, error)

Touch is the push entry: a source that hears of changed objects calls it; it reads and saves those objects as Run would, keeping the stored cursor. Passes of one provider never interleave.

type Source

type Source interface {
	Provider() unit.ProviderID
	Discover(ctx context.Context, cursor string) (stubs []Stub, next string, err error)
	Stubs(ctx context.Context, objects []string) ([]Stub, error)
	Read(ctx context.Context, objects []string) (Facts, error)
	Viewer(ctx context.Context) (string, error)
}

Source reads the provider's objects. It never writes the store.

type SourceStore

type SourceStore interface {
	// Watched are the objects to stub-check every run with their stored versions;
	// an object whose detail is older than its max age has Version "".
	Watched(ctx context.Context) ([]Stub, error)
	Versions(ctx context.Context, objects []string) (map[string]string, error)
	Cursor(ctx context.Context) (string, error)
	// Save stores light facts, then read facts (the read wins for one object),
	// then the cursor. It runs on every pass, so read may be nil and light empty.
	Save(ctx context.Context, light []Facts, read Facts, cursor string, at time.Time) error
	// See stamps the objects as seen at at.
	See(ctx context.Context, objects []string, at time.Time) error
}

SourceStore is the source's own persistence. Only ingest calls it.

type Stub

type Stub struct {
	Object  string // a channel and thread ts for a thread, a conversation for a DM
	Version string // the latest reply of a thread, the latest message of a DM
	Light   Facts  // facts the stub already carries; nil when none
}

Stub is an object as a cheap listing names it.

Jump to

Keyboard shortcuts

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