46 lines
1.5 KiB
Go
46 lines
1.5 KiB
Go
package sources
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gitea.maximumdirect.net/ejr/feedkit/event"
|
|
)
|
|
|
|
// Input is the common surface shared by all source types.
|
|
type Input interface {
|
|
Name() string
|
|
Kind() event.Kind
|
|
}
|
|
|
|
// Source is a configured polling job that emits 0..N events per poll.
|
|
//
|
|
// Source implementations live in domain modules (weatherfeeder/newsfeeder/...)
|
|
// and are registered into a feedkit sources.Registry.
|
|
//
|
|
// feedkit infrastructure treats Source as opaque; it just calls Poll()
|
|
// on the configured cadence and publishes the resulting events.
|
|
type Source interface {
|
|
// Name is the configured source name (used for logs and included in emitted events).
|
|
Name() string
|
|
|
|
// Kind is the "primary kind" emitted by this source.
|
|
//
|
|
// This is mainly useful as a *safety check* (e.g. config says kind=forecast but
|
|
// driver emits observation). Some future sources may emit multiple kinds; if/when
|
|
// that happens, we can evolve this interface (e.g., make Kind optional, or remove it).
|
|
Kind() event.Kind
|
|
|
|
// Poll fetches from upstream and returns 0..N events.
|
|
// Implementations should honor ctx.Done() for network calls and other I/O.
|
|
Poll(ctx context.Context) ([]event.Event, error)
|
|
}
|
|
|
|
// StreamSource is an event-driven source (NATS/RabbitMQ/MQTT/etc).
|
|
//
|
|
// Run should block, producing events into `out` until ctx is cancelled or a fatal error occurs.
|
|
// It MUST NOT close out (the scheduler/daemon owns the bus).
|
|
type StreamSource interface {
|
|
Input
|
|
Run(ctx context.Context, out chan<- event.Event) error
|
|
}
|