scheduler

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ThrottledWholeCollectionType = "ThrottledWholeCollection"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cycle

type Cycle interface {
	ID() string
	Name() string
	Type() string
	Start()
	Stop()
	Reset()
	Metadata() CycleMetadata
	SetMetadata(state CycleMetadata)
	TransformToConfig() CycleConfig
	State() []string
}

func NewScalingWindowCycle

func NewScalingWindowCycle(
	name string,
	uuidCollectionBuilder *native.NativeUUIDCollectionBuilder,
	dbCollection string,
	origin string,
	timeWindow time.Duration,
	coolDown time.Duration,
	minimumThrottle time.Duration,
	maximumThrottle time.Duration,
	publishTask tasks.Task,
) Cycle

func NewThrottledWholeCollectionCycle

func NewThrottledWholeCollectionCycle(name string, uuidCollectionBuilder *native.NativeUUIDCollectionBuilder, dbCollection string, origin string, coolDown time.Duration, throttle Throttle, publishTask tasks.Task) Cycle

type CycleConfig

type CycleConfig struct {
	Name            string `yaml:"name" json:"name"`
	Type            string `yaml:"type" json:"type"`
	Origin          string `yaml:"origin" json:"origin"`
	Collection      string `yaml:"collection" json:"collection"`
	CoolDown        string `yaml:"coolDown" json:"coolDown"`
	Throttle        string `yaml:"throttle" json:"throttle,omitempty"`
	TimeWindow      string `yaml:"timeWindow" json:"timeWindow,omitempty"`
	MinimumThrottle string `yaml:"minimumThrottle" json:"minimumThrottle,omitempty"`
	MaximumThrottle string `yaml:"maximumThrottle" json:"maximumThrottle,omitempty"`
}

func (CycleConfig) Validate

func (c CycleConfig) Validate() error

Validate checks the provided config for errors

type CycleMetadata

type CycleMetadata struct {
	CurrentPublishUUID  string     `json:"currentPublishUuid"`
	CurrentPublishRef   string     `json:"currentPublishReference"`
	CurrentPublishError string     `json:"currentPublishError,omitempty"`
	Errors              int        `json:"errors"`
	Progress            float64    `json:"progress"`
	State               []string   `json:"state"`
	Completed           int        `json:"completed"`
	Total               int        `json:"total"`
	Iteration           int        `json:"iteration"`
	Attempts            int        `json:"attempts"`
	Start               *time.Time `json:"windowStart,omitempty"`
	End                 *time.Time `json:"windowEnd,omitempty"`
}

type DefaultThrottle

type DefaultThrottle struct {
	Context context.Context
	Limiter *rate.Limiter
	// contains filtered or unexported fields
}

func (*DefaultThrottle) Interval

func (d *DefaultThrottle) Interval() time.Duration

func (*DefaultThrottle) MarshalJSON added in v0.2.12

func (d *DefaultThrottle) MarshalJSON() ([]byte, error)

func (*DefaultThrottle) Queue

func (d *DefaultThrottle) Queue() error

func (*DefaultThrottle) Stop

func (d *DefaultThrottle) Stop()

func (*DefaultThrottle) UnmarshalJSON added in v0.2.12

func (d *DefaultThrottle) UnmarshalJSON(in []byte) error

type MetadataReadWriter

type MetadataReadWriter interface {
	LoadMetadata(id string) (CycleMetadata, error)
	WriteMetadata(id string, config CycleConfig, metadata CycleMetadata) error
}

func NewS3MetadataReadWriter

func NewS3MetadataReadWriter(rw s3.ReadWriter) MetadataReadWriter

type MockCycle

type MockCycle struct {
	mock.Mock
}

func (*MockCycle) ID

func (m *MockCycle) ID() string

func (*MockCycle) Metadata

func (m *MockCycle) Metadata() CycleMetadata

func (*MockCycle) Name added in v0.2.12

func (m *MockCycle) Name() string

func (*MockCycle) Reset

func (m *MockCycle) Reset()

func (*MockCycle) SetMetadata

func (m *MockCycle) SetMetadata(state CycleMetadata)

func (*MockCycle) Start

func (m *MockCycle) Start()

func (*MockCycle) State

func (m *MockCycle) State() []string

func (*MockCycle) Stop

func (m *MockCycle) Stop()

func (*MockCycle) TransformToConfig

func (m *MockCycle) TransformToConfig() CycleConfig

func (*MockCycle) Type added in v0.2.12

func (m *MockCycle) Type() string

type MockMetadataRW

type MockMetadataRW struct {
	mock.Mock
}

MetadataRWMock is a mock of a MetadataReadWriter that can be used to test

func (*MockMetadataRW) LoadMetadata

func (m *MockMetadataRW) LoadMetadata(id string) (CycleMetadata, error)

func (*MockMetadataRW) WriteMetadata

func (m *MockMetadataRW) WriteMetadata(id string, config CycleConfig, metadata CycleMetadata) error

type MockScheduler

type MockScheduler struct {
	mock.Mock
}

func (*MockScheduler) AddCycle

func (m *MockScheduler) AddCycle(cycle Cycle) error

func (*MockScheduler) AddThrottle

func (m *MockScheduler) AddThrottle(name string, throttleInterval string) error

func (*MockScheduler) AutomaticToggleHandler added in v0.2.12

func (m *MockScheduler) AutomaticToggleHandler(toggleValue string)

func (*MockScheduler) Cycles

func (m *MockScheduler) Cycles() map[string]Cycle

func (*MockScheduler) DeleteCycle

func (m *MockScheduler) DeleteCycle(cycleID string) error

func (*MockScheduler) DeleteThrottle

func (m *MockScheduler) DeleteThrottle(name string) error

func (*MockScheduler) IsAutomaticallyDisabled added in v0.2.12

func (m *MockScheduler) IsAutomaticallyDisabled() bool

func (*MockScheduler) IsEnabled added in v0.2.12

func (m *MockScheduler) IsEnabled() bool

func (*MockScheduler) IsRunning added in v0.2.12

func (m *MockScheduler) IsRunning() bool

func (*MockScheduler) ManualToggleHandler added in v0.2.12

func (m *MockScheduler) ManualToggleHandler(toggleValue string)

func (*MockScheduler) NewCycle

func (m *MockScheduler) NewCycle(config CycleConfig) (Cycle, error)

func (*MockScheduler) RestorePreviousState

func (m *MockScheduler) RestorePreviousState()

func (*MockScheduler) Shutdown

func (m *MockScheduler) Shutdown() error

func (*MockScheduler) Start

func (m *MockScheduler) Start() error

func (*MockScheduler) Throttles

func (m *MockScheduler) Throttles() map[string]Throttle

func (*MockScheduler) WasAutomaticallyDisabled added in v0.2.12

func (m *MockScheduler) WasAutomaticallyDisabled() bool

type MockThrottle

type MockThrottle struct {
	mock.Mock
}

func (*MockThrottle) Interval

func (m *MockThrottle) Interval() time.Duration

func (*MockThrottle) Queue

func (m *MockThrottle) Queue() error

func (*MockThrottle) Stop

func (m *MockThrottle) Stop()

type ScalingWindowCycle

type ScalingWindowCycle struct {
	MaximumThrottle string `json:"maximumThrottle"`
	// contains filtered or unexported fields
}

func (*ScalingWindowCycle) Start

func (s *ScalingWindowCycle) Start()

func (*ScalingWindowCycle) TransformToConfig

func (s *ScalingWindowCycle) TransformToConfig() CycleConfig

type Scheduler

type Scheduler interface {
	Cycles() map[string]Cycle
	NewCycle(config CycleConfig) (Cycle, error)
	AddCycle(cycle Cycle) error
	DeleteCycle(cycleID string) error
	RestorePreviousState()
	Start() error
	Shutdown() error
	ManualToggleHandler(toggleValue string)
	AutomaticToggleHandler(toggleValue string)
	IsRunning() bool
	IsEnabled() bool
	IsAutomaticallyDisabled() bool
	WasAutomaticallyDisabled() bool
}

Scheduler is the main component of the publish carousel, which handles the publish cycles.

func LoadSchedulerFromFile

func LoadSchedulerFromFile(configFile string, uuidCollectionBuilder *native.NativeUUIDCollectionBuilder, publishTask tasks.Task, rw MetadataReadWriter, defaultThrottle time.Duration, checkpointInterval time.Duration) (Scheduler, error)

LoadSchedulerFromFile loads cycles and throttles from the provided yaml config file

func NewScheduler

func NewScheduler(uuidCollectionBuilder *native.NativeUUIDCollectionBuilder, publishTask tasks.Task, metadataReadWriter MetadataReadWriter, defaultThrottle time.Duration, checkpointInterval time.Duration) Scheduler

NewScheduler returns a new instance of the cycles scheduler

type State added in v0.2.12

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

func NewState added in v0.2.12

func NewState() *State

func (*State) MarshalJSON added in v0.2.12

func (s *State) MarshalJSON() ([]byte, error)

func (*State) UnmarshalJSON added in v0.2.12

func (s *State) UnmarshalJSON(b []byte) error

func (*State) Update added in v0.2.12

func (s *State) Update(states ...string)

type Throttle

type Throttle interface {
	Queue() error
	Stop()
	Interval() time.Duration
}

func NewCappedDynamicThrottle

func NewCappedDynamicThrottle(interval time.Duration, minThrottle time.Duration, maxThrottle time.Duration, publishes int, burst int) (Throttle, context.CancelFunc)

func NewDynamicThrottle

func NewDynamicThrottle(interval time.Duration, minimumThrottle time.Duration, publishes int, burst int) (Throttle, context.CancelFunc)

func NewThrottle

func NewThrottle(interval time.Duration, burst int) (Throttle, context.CancelFunc)

type ThrottledWholeCollectionCycle

type ThrottledWholeCollectionCycle struct {
	Throttle Throttle `json:"throttle"`
	// contains filtered or unexported fields
}

func (ThrottledWholeCollectionCycle) ID

func (a ThrottledWholeCollectionCycle) ID() string

func (ThrottledWholeCollectionCycle) Metadata

func (a ThrottledWholeCollectionCycle) Metadata() CycleMetadata

func (ThrottledWholeCollectionCycle) Name added in v0.2.12

func (a ThrottledWholeCollectionCycle) Name() string

func (ThrottledWholeCollectionCycle) PublishedItems

func (a ThrottledWholeCollectionCycle) PublishedItems() int

func (ThrottledWholeCollectionCycle) Reset

func (a ThrottledWholeCollectionCycle) Reset()

func (ThrottledWholeCollectionCycle) SetMetadata

func (a ThrottledWholeCollectionCycle) SetMetadata(metadata CycleMetadata)

func (*ThrottledWholeCollectionCycle) Start

func (l *ThrottledWholeCollectionCycle) Start()

func (ThrottledWholeCollectionCycle) State

func (a ThrottledWholeCollectionCycle) State() []string

func (ThrottledWholeCollectionCycle) Stop

func (a ThrottledWholeCollectionCycle) Stop()

func (*ThrottledWholeCollectionCycle) TransformToConfig

func (s *ThrottledWholeCollectionCycle) TransformToConfig() CycleConfig

func (ThrottledWholeCollectionCycle) Type added in v0.2.12

func (a ThrottledWholeCollectionCycle) Type() string

func (ThrottledWholeCollectionCycle) UpdateState

func (a ThrottledWholeCollectionCycle) UpdateState(states ...string)

Jump to

Keyboard shortcuts

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