updates

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2021 License: Apache-2.0 Imports: 17 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DefaultInterval = time.Duration(30 * time.Minute)
)

Variables

View Source
var (
	DefaultBatchSize = runtime.NumCPU()
)

Functions

This section is empty.

Types

type Configs

type Configs map[string]driver.ConfigUnmarshaler

type Manager

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

Manager oversees the configuration and invocation of vulstore updaters.

The Manager may be used in a one-shot fashion, configured to run background jobs, or both.

func NewManager

func NewManager(ctx context.Context, store vulnstore.Updater, pool *pgxpool.Pool, client *http.Client, opts ...ManagerOption) (*Manager, error)

NewManager will return a manager ready to have its Start or Run methods called.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context) error

Run constructs updaters from factories, configures them and runs them in Manager.batchSize batches.

Run is safe to call at anytime, regardless of whether background updaters are running.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

Start will run updaters at the given interval.

Start is designed to be ran as a go routine. Cancel the provided ctx to end the updater loop.

Start must only be called once between context cancelations.

type ManagerOption

type ManagerOption func(m *Manager)

ManagerOption specify optional configuration for a Manager. Defaults will be used where options are not provided to the constructor.

func WithBatchSize

func WithBatchSize(n int) ManagerOption

WithBatchSize sets the max number of parallel updaters that will run during an update interval.

func WithConfigs

func WithConfigs(cfgs Configs) ManagerOption

WithConfigs tells the Manager to configure each updater where a configuration is provided.

Configuration of individual updaters is delegated to updater/registry.go Note: this option is optimal when ran after WithEnabled option. However, this option has no strict depedency on others.

func WithEnabled

func WithEnabled(enabled []string) ManagerOption

WithEnabled configures the Manager to only run the specified updater sets.

If enabled == nil all default updater sets will run (same as not providing this option to the constructor at all). If len(enabled) == 0 no default updater sets will run. If len(enabled) > 0 only provided updater sets will be ran.

func WithGC

func WithGC(retention int) ManagerOption

WithGC instructs the manager to run garbage collection at the end of an update interval.

The provided retention value informs the manager how many update operations to keep.

func WithInterval

func WithInterval(interval time.Duration) ManagerOption

WithInterval configures the interval at which updaters will be ran. The manager runs all configured updaters during an interval. Setting this duration too low may cause missed update intervals.

func WithOutOfTree

func WithOutOfTree(outOfTree []driver.Updater) ManagerOption

WithOutOfTree allows callers to provide their own out-of-tree updaters.

note: currently we will never configure the outOfTree updater factory. if this changes consider making this option a required to avoid missing configuration

Jump to

Keyboard shortcuts

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