workers

package
v0.0.0-...-9b598c7 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseWorker

type BaseWorker struct {
	Id         string
	WorkerType string
	Reconciler Reconciler
	// contains filtered or unexported fields
}

func (*BaseWorker) GetID

func (b *BaseWorker) GetID() string

func (*BaseWorker) GetStopChan

func (b *BaseWorker) GetStopChan() *chan struct{}

func (*BaseWorker) GetSyncGroup

func (b *BaseWorker) GetSyncGroup() *sync.WaitGroup

func (*BaseWorker) GetWorkerType

func (b *BaseWorker) GetWorkerType() string

func (*BaseWorker) HasTerminated

func (b *BaseWorker) HasTerminated() bool

func (*BaseWorker) IsRunning

func (b *BaseWorker) IsRunning() bool

func (*BaseWorker) SetIsRunning

func (b *BaseWorker) SetIsRunning(val bool)

func (*BaseWorker) StartWorker

func (b *BaseWorker) StartWorker(w Worker)

func (*BaseWorker) StopWorker

func (b *BaseWorker) StopWorker(w Worker)

type LeaderElectionManager

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

func NewLeaderElectionManager

func NewLeaderElectionManager(workers []Worker, connectionFactory *db.ConnectionFactory, reconcilerConfig *ReconcilerConfig) *LeaderElectionManager

func (*LeaderElectionManager) Start

func (s *LeaderElectionManager) Start()

func (*LeaderElectionManager) Stop

func (s *LeaderElectionManager) Stop()

impl. Stoppable Workers started with Leader Election manager should be stop from here

type Reconciler

type Reconciler struct {
	di.Inject

	SignalBus        signalbus.SignalBus
	ReconcilerConfig *ReconcilerConfig
	// contains filtered or unexported fields
}

func (*Reconciler) Start

func (r *Reconciler) Start(worker Worker)

func (*Reconciler) Stop

func (r *Reconciler) Stop(worker Worker)

func (*Reconciler) Wakeup

func (r *Reconciler) Wakeup(wait bool)

Wakeup causes the worker reconcile to be performed as soon as possible. If wait is true, the this function blocks until the reconcile is completed, otherwise this function does not block.

type ReconcilerConfig

type ReconcilerConfig struct {
	ReconcilerRepeatInterval               time.Duration `json:"reconciler_repeat_interval"`
	LeaderLeaseExpirationTime              time.Duration `json:"leader_lease_expiration_time"`
	LeaderElectionReconcilerRepeatInterval time.Duration `json:"leader_election_reconciler_repeat_interval"`
}

func NewReconcilerConfig

func NewReconcilerConfig() *ReconcilerConfig

func (*ReconcilerConfig) AddFlags

func (r *ReconcilerConfig) AddFlags(fs *pflag.FlagSet)

func (*ReconcilerConfig) ReadFiles

func (c *ReconcilerConfig) ReadFiles() error

type Worker

type Worker interface {
	GetID() string
	GetWorkerType() string
	Start()
	Stop()
	Reconcile() []error
	GetStopChan() *chan struct{}
	GetSyncGroup() *sync.WaitGroup
	IsRunning() bool
	SetIsRunning(val bool)
	HasTerminated() bool
}

type WorkerMock

type WorkerMock struct {
	// GetIDFunc mocks the GetID method.
	GetIDFunc func() string

	// GetStopChanFunc mocks the GetStopChan method.
	GetStopChanFunc func() *chan struct{}

	// GetSyncGroupFunc mocks the GetSyncGroup method.
	GetSyncGroupFunc func() *sync.WaitGroup

	// GetWorkerTypeFunc mocks the GetWorkerType method.
	GetWorkerTypeFunc func() string

	// HasTerminatedFunc mocks the HasTerminated method.
	HasTerminatedFunc func() bool

	// IsRunningFunc mocks the IsRunning method.
	IsRunningFunc func() bool

	// ReconcileFunc mocks the Reconcile method.
	ReconcileFunc func() []error

	// SetIsRunningFunc mocks the SetIsRunning method.
	SetIsRunningFunc func(val bool)

	// StartFunc mocks the Start method.
	StartFunc func()

	// StopFunc mocks the Stop method.
	StopFunc func()
	// contains filtered or unexported fields
}

WorkerMock is a mock implementation of Worker.

func TestSomethingThatUsesWorker(t *testing.T) {

	// make and configure a mocked Worker
	mockedWorker := &WorkerMock{
		GetIDFunc: func() string {
			panic("mock out the GetID method")
		},
		GetStopChanFunc: func() *chan struct{} {
			panic("mock out the GetStopChan method")
		},
		GetSyncGroupFunc: func() *sync.WaitGroup {
			panic("mock out the GetSyncGroup method")
		},
		GetWorkerTypeFunc: func() string {
			panic("mock out the GetWorkerType method")
		},
		HasTerminatedFunc: func() bool {
			panic("mock out the HasTerminated method")
		},
		IsRunningFunc: func() bool {
			panic("mock out the IsRunning method")
		},
		ReconcileFunc: func() []error {
			panic("mock out the Reconcile method")
		},
		SetIsRunningFunc: func(val bool)  {
			panic("mock out the SetIsRunning method")
		},
		StartFunc: func()  {
			panic("mock out the Start method")
		},
		StopFunc: func()  {
			panic("mock out the Stop method")
		},
	}

	// use mockedWorker in code that requires Worker
	// and then make assertions.

}

func (*WorkerMock) GetID

func (mock *WorkerMock) GetID() string

GetID calls GetIDFunc.

func (*WorkerMock) GetIDCalls

func (mock *WorkerMock) GetIDCalls() []struct {
}

GetIDCalls gets all the calls that were made to GetID. Check the length with:

len(mockedWorker.GetIDCalls())

func (*WorkerMock) GetStopChan

func (mock *WorkerMock) GetStopChan() *chan struct{}

GetStopChan calls GetStopChanFunc.

func (*WorkerMock) GetStopChanCalls

func (mock *WorkerMock) GetStopChanCalls() []struct {
}

GetStopChanCalls gets all the calls that were made to GetStopChan. Check the length with:

len(mockedWorker.GetStopChanCalls())

func (*WorkerMock) GetSyncGroup

func (mock *WorkerMock) GetSyncGroup() *sync.WaitGroup

GetSyncGroup calls GetSyncGroupFunc.

func (*WorkerMock) GetSyncGroupCalls

func (mock *WorkerMock) GetSyncGroupCalls() []struct {
}

GetSyncGroupCalls gets all the calls that were made to GetSyncGroup. Check the length with:

len(mockedWorker.GetSyncGroupCalls())

func (*WorkerMock) GetWorkerType

func (mock *WorkerMock) GetWorkerType() string

GetWorkerType calls GetWorkerTypeFunc.

func (*WorkerMock) GetWorkerTypeCalls

func (mock *WorkerMock) GetWorkerTypeCalls() []struct {
}

GetWorkerTypeCalls gets all the calls that were made to GetWorkerType. Check the length with:

len(mockedWorker.GetWorkerTypeCalls())

func (*WorkerMock) HasTerminated

func (mock *WorkerMock) HasTerminated() bool

HasTerminated calls HasTerminatedFunc.

func (*WorkerMock) HasTerminatedCalls

func (mock *WorkerMock) HasTerminatedCalls() []struct {
}

HasTerminatedCalls gets all the calls that were made to HasTerminated. Check the length with:

len(mockedWorker.HasTerminatedCalls())

func (*WorkerMock) IsRunning

func (mock *WorkerMock) IsRunning() bool

IsRunning calls IsRunningFunc.

func (*WorkerMock) IsRunningCalls

func (mock *WorkerMock) IsRunningCalls() []struct {
}

IsRunningCalls gets all the calls that were made to IsRunning. Check the length with:

len(mockedWorker.IsRunningCalls())

func (*WorkerMock) Reconcile

func (mock *WorkerMock) Reconcile() []error

Reconcile calls ReconcileFunc.

func (*WorkerMock) ReconcileCalls

func (mock *WorkerMock) ReconcileCalls() []struct {
}

ReconcileCalls gets all the calls that were made to Reconcile. Check the length with:

len(mockedWorker.ReconcileCalls())

func (*WorkerMock) SetIsRunning

func (mock *WorkerMock) SetIsRunning(val bool)

SetIsRunning calls SetIsRunningFunc.

func (*WorkerMock) SetIsRunningCalls

func (mock *WorkerMock) SetIsRunningCalls() []struct {
	Val bool
}

SetIsRunningCalls gets all the calls that were made to SetIsRunning. Check the length with:

len(mockedWorker.SetIsRunningCalls())

func (*WorkerMock) Start

func (mock *WorkerMock) Start()

Start calls StartFunc.

func (*WorkerMock) StartCalls

func (mock *WorkerMock) StartCalls() []struct {
}

StartCalls gets all the calls that were made to Start. Check the length with:

len(mockedWorker.StartCalls())

func (*WorkerMock) Stop

func (mock *WorkerMock) Stop()

Stop calls StopFunc.

func (*WorkerMock) StopCalls

func (mock *WorkerMock) StopCalls() []struct {
}

StopCalls gets all the calls that were made to Stop. Check the length with:

len(mockedWorker.StopCalls())

Jump to

Keyboard shortcuts

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