reactor

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InstrumentClient

func InstrumentClient(client *http.Client) *http.Client

InstrumentClient instruments the client provided as argument to measure and report networking metrics

func RegisterMetrics

func RegisterMetrics(reg prometheus.Registerer)

RegisterMetrics registers the http client metrics. The second parameter `reg` can be used to provide a custom registry, e.g. for tests.

func ResetMetrics

func ResetMetrics()

ResetMetrics resets the metrics

func SelectContent

func SelectContent(contentBytes []byte, selectorExpression string) ([]byte, error)

SelectContent TODO: Not implemented

Types

type DocumentWorkTask

type DocumentWorkTask struct {
	Node *api.Node
}

DocumentWorkTask implements jobs#Task

type DocumentWorker

type DocumentWorker struct {
	writers.Writer
	Reader
	processors.Processor
	NodeContentProcessor *NodeContentProcessor
	// contains filtered or unexported fields
}

DocumentWorker implements jobs#Worker

func (*DocumentWorker) Work

func (w *DocumentWorker) Work(ctx context.Context, task interface{}) *jobs.WorkerError

Work implements Worker#Work function

type DownloadJob

type DownloadJob interface {
	Start(ctx context.Context, errCh chan error, shutdownCh chan struct{}, wg *sync.WaitGroup)
	Schedule(ctx context.Context, link, resourceName string)
}

DownloadJob encapsulates activities for asyncronous and parallel scheduling and download of resources

func NewResourceDownloadJob

func NewResourceDownloadJob(reader Reader, writer writers.Writer, workersCount int, failFast bool, rhs resourcehandlers.Registry) DownloadJob

NewResourceDownloadJob creates DownloadJob object

type DownloadTask

type DownloadTask struct {
	Source string
	Target string
}

DownloadTask holds information for source and target of linked document resources

type GenericReader

type GenericReader struct {
	ResourceHandlers resourcehandlers.Registry
}

GenericReader is generic implementation for Reader interface

func (*GenericReader) Read

func (g *GenericReader) Read(ctx context.Context, source string) ([]byte, error)

Read reads from the resource at the source URL delegating the the actual operation to a suitable resource hadler

type NodeContentProcessor

type NodeContentProcessor struct {
	DownloadJob DownloadJob

	ResourceHandlers resourcehandlers.Registry
	// contains filtered or unexported fields
}

NodeContentProcessor operates on documents content to reconcile links and schedule linked resources downloads

func NewNodeContentProcessor

func NewNodeContentProcessor(resourcesRoot string, ld localityDomain, downloadJob DownloadJob, failFast bool, markdownFmt bool, resourceHandlers resourcehandlers.Registry) *NodeContentProcessor

NewNodeContentProcessor creates NodeContentProcessor objects

func (c *NodeContentProcessor) ReconcileLinks(ctx context.Context, node *api.Node, contentSourcePath string, documentBlob []byte) ([]byte, error)

ReconcileLinks analyzes a document referenced by a node's contentSourcePath and processes its links to other resources to resolve their inconsistencies. The processing might involve rewriting links to relative and having new destinations, or rewriting them to absolute, as well as downloading some of the linked resources. The function returns the processed document or error.

type Options

type Options struct {
	MaxWorkersCount              int
	MinWorkersCount              int
	FailFast                     bool
	DestinationPath              string
	ResourcesPath                string
	ResourceDownloadWorkersCount int
	MarkdownFmt                  bool
	processors.Processor
	ResourceDownloadWriter writers.Writer
	Writer                 writers.Writer
	ResourceHandlers       []resourcehandlers.ResourceHandler
}

Options encapsulates the parameters for creating new Reactor objects wiht NewReactor

type Reactor

type Reactor struct {
	ReplicateDocumentation *jobs.Job
	FailFast               bool
	ResourceHandlers       resourcehandlers.Registry
	// contains filtered or unexported fields
}

Reactor orchestrates the documentation build workflow

func NewReactor

func NewReactor(o *Options) *Reactor

NewReactor creates a Reactor from Options

func (*Reactor) Build

func (r *Reactor) Build(ctx context.Context, documentationRoot *api.Node, localityDomain localityDomain) error

Build starts the build operation for a document structure root in a locality domain

func (*Reactor) Resolve

func (r *Reactor) Resolve(ctx context.Context, node *api.Node) error

Resolve builds the subnodes hierarchy of a node based on the natural nodes hierarchy and on rules such as those in NodeSelector. The node hierarchy is resolved by an appropriate handler selected based on the NodeSelector path URI The resulting model is the actual flight plan for replicating resources.

func (*Reactor) Run

func (r *Reactor) Run(ctx context.Context, docStruct *api.Documentation, dryRun bool) error

Run starts build operation on docStruct

type Reader

type Reader interface {
	Read(ctx context.Context, source string) ([]byte, error)
}

Reader reads the bytes data from a given source URI

type ResourceDownloadJob

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

ResourceDownloadJob implements reactor#DownloadJob

func (*ResourceDownloadJob) Schedule

func (l *ResourceDownloadJob) Schedule(ctx context.Context, link, resourceName string)

Schedule enqeues and resource link for download

func (*ResourceDownloadJob) Start

func (l *ResourceDownloadJob) Start(ctx context.Context, errCh chan error, shutdownCh chan struct{}, jobWg *sync.WaitGroup)

Start the job with multiple workers, each waiting for download tasks or context termination

Jump to

Keyboard shortcuts

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