mock

package
v0.0.0-...-f5b6858 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package mock contains mock implementations of different task interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DesiredState

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

DesiredState is a mock implementation of DesiredState (used by NewScheduler).

func NewDesiredState

func NewDesiredState() *DesiredState

func (*DesiredState) CreateNextRun

func (d *DesiredState) CreateNextRun(_ context.Context, taskID platform.ID, now int64) (backend.RunCreation, error)

CreateNextRun creates the next run for the given task. Refer to the documentation for SetTaskPeriod to understand how the times are determined.

func (*DesiredState) CreatedFor

func (d *DesiredState) CreatedFor(taskID platform.ID) []backend.QueuedRun

func (*DesiredState) FinishRun

func (d *DesiredState) FinishRun(_ context.Context, taskID, runID platform.ID) error

func (*DesiredState) PollForNumberCreated

func (d *DesiredState) PollForNumberCreated(taskID platform.ID, count int) ([]scheduler.QueuedRun, error)

PollForNumberCreated blocks for a small amount of time waiting for exactly the given count of created runs for the given task ID. If the expected number isn't found in time, it returns an error.

Because the scheduler and executor do a lot of state changes asynchronously, this is useful in test.

func (*DesiredState) SetTaskMeta

func (d *DesiredState) SetTaskMeta(taskID platform.ID, meta backend.StoreTaskMeta)

SetTaskMeta sets the task meta for the given task ID. SetTaskMeta must be called before CreateNextRun, for a given task ID.

type Executor

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

func NewExecutor

func NewExecutor() *Executor

func (*Executor) Execute

func (*Executor) PollForNumberRunning

func (e *Executor) PollForNumberRunning(taskID platform.ID, count int) ([]*RunPromise, error)

PollForNumberRunning blocks for a small amount of time waiting for exactly the given count of active runs for the given task ID. If the expected number isn't found in time, it returns an error.

Because the scheduler and executor do a lot of state changes asynchronously, this is useful in test.

func (*Executor) RunningFor

func (e *Executor) RunningFor(taskID platform.ID) []*RunPromise

RunningFor returns the run promises for the given task.

func (*Executor) WithLogger

func (e *Executor) WithLogger(l *zap.Logger)

type RunPromise

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

RunPromise is a mock RunPromise.

func NewRunPromise

func NewRunPromise(qr backend.QueuedRun) *RunPromise

func (*RunPromise) Cancel

func (p *RunPromise) Cancel()

func (*RunPromise) Finish

func (p *RunPromise) Finish(r backend.RunResult, err error)

Finish unblocks any call to Wait, to return r and err. Only the first call to Finish has any effect.

func (*RunPromise) Run

func (p *RunPromise) Run() backend.QueuedRun

func (*RunPromise) Wait

func (p *RunPromise) Wait() (backend.RunResult, error)

type RunResult

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

RunResult is a mock implementation of RunResult.

func NewRunResult

func NewRunResult(err error, isRetryable bool) *RunResult

func (*RunResult) Err

func (rr *RunResult) Err() error

func (*RunResult) IsRetryable

func (rr *RunResult) IsRetryable() bool

type Scheduler

type Scheduler struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Scheduler is a mock implementation of a task scheduler.

func NewScheduler

func NewScheduler() *Scheduler

func (*Scheduler) ClaimError

func (s *Scheduler) ClaimError(err error)

ClaimError sets an error to be returned by s.ClaimTask, if err is not nil.

func (*Scheduler) ClaimTask

func (s *Scheduler) ClaimTask(task *backend.StoreTask, meta *backend.StoreTaskMeta) error

func (*Scheduler) ReleaseError

func (s *Scheduler) ReleaseError(err error)

ReleaseError sets an error to be returned by s.ReleaseTask, if err is not nil.

func (*Scheduler) ReleaseTask

func (s *Scheduler) ReleaseTask(taskID platform.ID) error

func (*Scheduler) TaskCreateChan

func (s *Scheduler) TaskCreateChan() <-chan *Task

func (*Scheduler) TaskFor

func (s *Scheduler) TaskFor(id platform.ID) *Task

func (*Scheduler) TaskReleaseChan

func (s *Scheduler) TaskReleaseChan() <-chan *Task

func (*Scheduler) Tick

func (s *Scheduler) Tick(now int64)

func (*Scheduler) WithLogger

func (s *Scheduler) WithLogger(l *zap.Logger)

type Task

type Task struct {
	Script           string
	StartExecution   int64
	ConcurrencyLimit uint8
}

Task is a mock implementation of a task.

Jump to

Keyboard shortcuts

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