scanconfigwatcher

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPollInterval     = 15 * time.Second
	DefaultReconcileTimeout = 5 * time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Backend          *backendclient.BackendClient
	PollPeriod       time.Duration `mapstructure:"poll_period"`
	ReconcileTimeout time.Duration `mapstructure:"reconcile_timeout"`
}

func (Config) WithBackendClient

func (c Config) WithBackendClient(b *backendclient.BackendClient) Config

func (Config) WithPollPeriod

func (c Config) WithPollPeriod(t time.Duration) Config

func (Config) WithReconcileTimeout

func (c Config) WithReconcileTimeout(t time.Duration) Config

type OperationTime

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

OperationTime is a single point in time defined by the time parameter. Providing an optional cron parameter makes the OperationTime recurring in case the cron expression represents a recurring cadence.

func NewOperationTime

func NewOperationTime(t time.Time, c *cronexpr.Expression) *OperationTime

NewOperationTime returns a OperationTime created by using the provided t time and c cron expression.

func (*OperationTime) IsRecurring

func (o *OperationTime) IsRecurring() bool

IsRecurring returns true of cron is set and its expression defines a recurring cadence.

func (OperationTime) Next

func (o OperationTime) Next() *OperationTime

Next returns a new OperationTime representing the next cadence in case cron parameter is provided, otherwise it returns itself.

func (OperationTime) NextAfter

func (o OperationTime) NextAfter(t time.Time) *OperationTime

NextAfter returns a new OperationTime representing time which is after then the provided t time. It returns itself if t is zero or o has no cron set.

func (OperationTime) String

func (o OperationTime) String() string

func (*OperationTime) Time

func (o *OperationTime) Time() time.Time

Time returns time.Time represented by the OperationTime.

type ScanConfigPoller

type ScanConfigPoller = common.Poller[ScanConfigReconcileEvent]

type ScanConfigQueue

type ScanConfigQueue = common.Queue[ScanConfigReconcileEvent]

type ScanConfigReconcileEvent

type ScanConfigReconcileEvent struct {
	ScanConfigID models.ScanConfigID
}

func (ScanConfigReconcileEvent) Hash

func (ScanConfigReconcileEvent) String

func (e ScanConfigReconcileEvent) String() string

func (ScanConfigReconcileEvent) ToFields

func (e ScanConfigReconcileEvent) ToFields() log.Fields

type ScanConfigSchedule

type ScanConfigSchedule struct {
	State         ScheduleState
	OperationTime *OperationTime
	Window        *ScheduleWindow
}

ScanConfigSchedule defines the state of scheduling based on the OperationTime and the ScheduleWindow where former is calculated using the ScanConfig schedule.

func NewScanConfigSchedule

func NewScanConfigSchedule(scanConfig *models.ScanConfig, window *ScheduleWindow) (*ScanConfigSchedule, error)

NewScanConfigSchedule returns a ScanConfigSchedule using the provided scanConfig models.ScanConfig and window ScheduleWindow. nolint:cyclop

func (ScanConfigSchedule) String

func (w ScanConfigSchedule) String() string

type ScheduleState

type ScheduleState int8
const (
	// ScheduleStateDisabled means the ScanConfig is disabled no Scan needs to be scheduled for it.
	ScheduleStateDisabled ScheduleState = iota
	// ScheduleStateUnscheduled means the ScanConfig does not define a schedule.
	ScheduleStateUnscheduled
	// ScheduleStateNotDue means the OperationTime for ScanConfig is in the future based on the current ScheduleWindow.
	ScheduleStateNotDue
	// ScheduleStateDue means the OperationTime for ScanConfig is in the current ScheduleWindow.
	ScheduleStateDue
	// ScheduleStateOverdue means the OperationTime for ScanConfig is in the past compared to
	// the current ScheduleWindow, but it has recurring schedule, therefore the new OperationTime needs
	// to be calculated from the cron expression.
	ScheduleStateOverdue
)

func (ScheduleState) String

func (s ScheduleState) String() string

type ScheduleWindow

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

The ScheduleWindow represents a timeframe defined by the start and end timestamps.

func NewScheduleWindow

func NewScheduleWindow(now time.Time, size time.Duration) *ScheduleWindow

NewScheduleWindow returns a new ScheduleWindow representing a timeframe where now parameter defines the middle of the calculated timeframe.

+--------------------+
|   ScheduleWindow   |
+--------------------+
          ^
         now (middle)

<-------------------->
         size

nolint:gomnd

func (*ScheduleWindow) After

func (w *ScheduleWindow) After(t time.Time) bool

After returns true if w ScheduleWindow is after t time.Time, otherwise false.

func (*ScheduleWindow) Before

func (w *ScheduleWindow) Before(t time.Time) bool

Before returns true if w ScheduleWindow is before t time.Time, otherwise false.

func (*ScheduleWindow) End

func (w *ScheduleWindow) End() time.Time

End returns the end of the ScheduleWindow.

func (*ScheduleWindow) In

func (w *ScheduleWindow) In(t time.Time) bool

In returns true if the t time is within the w ScheduleWindow, otherwise it returns false.

func (ScheduleWindow) Next

func (w ScheduleWindow) Next() *ScheduleWindow

Next returns a new ScheduleWindow which represents the timeframe after w ScheduleWindow.

func (ScheduleWindow) Prev

func (w ScheduleWindow) Prev() *ScheduleWindow

Prev returns a new ScheduleWindow which represents the timeframe before w ScheduleWindow.

func (*ScheduleWindow) Start

func (w *ScheduleWindow) Start() time.Time

Start returns the beginning of the ScheduleWindow.

func (ScheduleWindow) String

func (w ScheduleWindow) String() string

type Watcher

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

func New

func New(c Config) *Watcher

func (*Watcher) GetScanConfigs

func (w *Watcher) GetScanConfigs(ctx context.Context) ([]ScanConfigReconcileEvent, error)

func (*Watcher) Reconcile

func (w *Watcher) Reconcile(ctx context.Context, event ScanConfigReconcileEvent) error

nolint:cyclop

func (*Watcher) Start

func (w *Watcher) Start(ctx context.Context)

Jump to

Keyboard shortcuts

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