Documentation
¶
Overview ¶
Package catalogcrawler is the onix plugin wiring for the decentralized- catalog crawl: it parses plugin config, builds the four concrete pieces crawlmanager.Params needs (a Postgres Store, a registry+static Source, an HTTP-push-to-Discovery Sink, and a ticker-driven Scheduler), and satisfies definition.Crawler by delegating to the Scheduler's lifecycle. No business logic of its own -- see github.com/beckn/catalog-core's pkg/catalog/crawlmanager for that.
Logging here uses log/slog, not this repo's usual pkg/log (zerolog) directly, because crawlmanager.Params.Log and Scheduler are typed against *slog.Logger -- catalog-core is a dependency-free library and can't import onix's pkg/log. New wires slog.New(log.NewSlogHandler()) instead of slog.Default(), the same bridge catalogpublisher uses, so crawler logs still flow through onix's usual zerolog pipeline.
Index ¶
Constants ¶
const ( DefaultIndexInterval = 5 * time.Minute DefaultCatalogInterval = 30 * time.Second DefaultParkSweepInterval = 15 * time.Minute )
DefaultIndexInterval, DefaultCatalogInterval, and DefaultParkSweepInterval are used when SchedulerConfig leaves the corresponding field at zero.
const ( // DefaultMaxParkRetryBudget is the total wall-clock time a parked // catalog keeps getting revived before being abandoned, by default -- // combined with the actual (possibly overridden) park-sweep interval // via crawlmanager.DeriveMaxParkCount to compute Params.MaxParkCount. DefaultMaxParkRetryBudget = 12 * time.Hour )
Variables ¶
This section is empty.
Functions ¶
func NewHandler ¶
func NewHandler(ctx context.Context, crawler definition.Crawler, cfg *handler.Config, moduleName string) (http.Handler, error)
NewHandler builds the /crawl/* endpoint family. Sub-routes on the request path stripped of cfg.BasePath: "trigger" -> the on-demand crawl trigger (trigger.go), "status" -> the crawl/sync status query (status.go). Both explicit, rather than treating the bare path as the trigger, so neither endpoint depends on how a bare-subtree-root request happens to redirect.
func RegisterHandler ¶
func RegisterHandler(crawler definition.Crawler)
RegisterHandler wires this package's /crawl/* endpoints to the given already-running Crawler singleton, registering it as the Provider for HandlerTypeCatalogCrawl. Call this once, from main.go, right after the Crawler has been constructed and Start()-ed -- CrawlRegistry requires that exact instance to already be running, so unlike catalogpublisher's static handlerProviders entry (which builds everything it needs from PluginManager+config per module), this can't be wired ahead of time; it has to close over a concrete object that only exists after startup.
Types ¶
type Provider ¶
type Provider struct{}
Provider implements definition.CrawlerProvider.
func (Provider) New ¶
func (Provider) New(ctx context.Context, registry definition.RegistryLookup, metadataLookup definition.RegistryMetadataLookup, config map[string]string) (definition.Crawler, func() error, error)
New builds a Crawler from config, wiring a Postgres Store, a registry+static Source, a Discovery-push Sink, and a ticker Scheduler. registry is REQUIRED: it is the key-distribution channel every fetched index entry/file's self-signature is verified against. metadataLookup is REQUIRED whenever registry-backed discovery (the "networks" config) is used: it resolves each configured networkId to its member providers via the dediregistry plugin's QueryByNetwork, rather than a direct DeDi call. A deployment using only staticIndexUrls (no networks) does not need it and may pass nil.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler runs Params.PollIndexes and Params.SyncNext on their own intervals until Stop.
func NewScheduler ¶
func NewScheduler(params crawlmanager.Params, cfg SchedulerConfig, log *slog.Logger) *Scheduler
NewScheduler builds a Scheduler over params, driven at cfg's cadence. log may be nil.
func (*Scheduler) RunOnce ¶
RunOnce launches fn once in a goroutine tied to the scheduler's OWN lifecycle context (from Start), not the caller's -- so an on-demand crawl triggered from a request-scoped context outlives that request, and is tracked by the same WaitGroup Stop waits on, so shutdown never orphans it. Reports false without launching fn if the scheduler hasn't been started (or has already been stopped) -- see Stop's doc comment for why the not-done check and the wg.Add below must happen as one atomic step under s.mu, the same lock Stop holds across its own cancel+Wait.
func (*Scheduler) Start ¶
Start launches the index-poll, catalog-sync, and park-sweep loops as three goroutines and returns immediately; Stop drains them.
func (*Scheduler) Stop ¶
func (s *Scheduler) Stop()
Stop signals both loops and waits for the in-flight tick (if any), and any RunOnce call already in flight, to finish before returning. Holds s.mu for its entire cancel+Wait -- not just the cancel -- so it can never interleave with RunOnce's own check+Add critical section: either a RunOnce call's Add happens-before Stop acquires the lock (so Wait below correctly blocks on it), or it acquires the lock only after Stop has already canceled ctx under the same lock, in which case it observes ctx.Err() != nil and never launches anything. Without holding the lock across Wait too, Stop's cancel-then-Wait could otherwise run entirely between a RunOnce call's not-done check and its Add, letting Wait return on a still-zero counter before that call ever adds itself -- orphaning it after Stop has already returned to its caller.
type SchedulerConfig ¶
type SchedulerConfig struct {
IndexInterval time.Duration // 0 => DefaultIndexInterval
CatalogInterval time.Duration // 0 => DefaultCatalogInterval
// ParkSweepInterval is how often RequeueOrAbandonParked runs -- a third,
// independent cadence from IndexInterval/CatalogInterval (see
// crawlmanager.Params.RequeueOrAbandonParked's own doc comment for why
// it's deliberately decoupled from PollIndexes/SyncNext). 0 =>
// DefaultParkSweepInterval.
ParkSweepInterval time.Duration
// ParkOlderThan is how long a catalog must have been sitting parked
// before this sweep will revive or abandon it. Zero (the default) means
// no extra grace period beyond the sweep cadence itself -- each tick
// acts on anything currently parked.
ParkOlderThan time.Duration
}
SchedulerConfig is Scheduler's tunable cadence.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
sink
Package sink implements crawlmanager.Sink: an HTTP push to a Discovery service.
|
Package sink implements crawlmanager.Sink: an HTTP push to a Discovery service. |
|
source
Package source implements crawlmanager.Source: a fixed config list, and a registry-backed lookup (registry.go/dediquery.go).
|
Package source implements crawlmanager.Source: a fixed config list, and a registry-backed lookup (registry.go/dediquery.go). |
|
store
Package store is catalogcrawler's Postgres-backed crawlmanager.Store: the crawler_index/crawler_queue/crawler_catalog schema and queries ported from the catalog-crawler prototype's own store package (working, reused as-is -- see migrations/).
|
Package store is catalogcrawler's Postgres-backed crawlmanager.Store: the crawler_index/crawler_queue/crawler_catalog schema and queries ported from the catalog-crawler prototype's own store package (working, reused as-is -- see migrations/). |