ops

package
v0.0.0-...-a6a2865 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package ops provides code that observes the tracker state, and takes appropriate actions. It basically implements a simple state machine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

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

An Action describes an operation to be applied to jobs that meet the required condition. Monitor handles the selection of Action, and the transition to the next State on success.

func (Action) Name

func (a Action) Name() string

Name returns the name of the state that the action applies to.

type ActionFunc

type ActionFunc = func(context.Context, tracker.Job, time.Time) *Outcome

An ActionFunc performs an operation on a job, and updates its state. These functions may take a long time to complete, and may be resource intensive. Time parameter is the last state transition time.

type ConditionFunc

type ConditionFunc = func(ctx context.Context, job tracker.Job) bool

A ConditionFunc checks whether a Job meets some condition. These functions may take a long time to complete, but should NOT use a lot of resources.

type Monitor

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

Monitor "owns" all jobs in the states that have actions.

func NewMonitor

func NewMonitor(clientCtx context.Context, config cloud.BQConfig, tk *tracker.Tracker) (*Monitor, error)

NewMonitor creates a Monitor with no Actions

func NewStandardMonitor

func NewStandardMonitor(ctx context.Context, project, inputBucket string, config cloud.BQConfig, tk *tracker.Tracker) (*Monitor, error)

NewStandardMonitor creates the standard monitor that handles several state transitions.

func (*Monitor) AddAction

func (m *Monitor) AddAction(state tracker.State, cond ConditionFunc, op ActionFunc,
	successState tracker.State)

AddAction adds a specific action to the Monitor.

func (*Monitor) GetAction

func (m *Monitor) GetAction(state tracker.State) Action

func (*Monitor) UpdateJob

func (m *Monitor) UpdateJob(o *Outcome, state tracker.State) (string, error)

UpdateJob updates the tracker state with the outcome.

func (*Monitor) Watch

func (m *Monitor) Watch(ctx context.Context, period time.Duration)

Watch polls the tracker, and takes appropriate actions.

type Outcome

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

Outcome is a custom error for use in this package. It is a little unusual in that it can encode a successful outcome, in which case Unwrap will return nil.

func Failure

func Failure(job tracker.Job, err error, detail string) *Outcome

Failure creates a failure Outcome

func Retry

func Retry(job tracker.Job, err error, detail string) *Outcome

Retry creates a retry type Outcome

func Success

func Success(job tracker.Job, detail string) *Outcome

Success returns a successful outcome.

func (Outcome) Error

func (o Outcome) Error() string

func (Outcome) IsDone

func (o Outcome) IsDone() bool

IsDone indicates if the operation was successful.

func (Outcome) ShouldRetry

func (o Outcome) ShouldRetry() bool

ShouldRetry indicates of the operation should be retried later.

func (*Outcome) Unwrap

func (o *Outcome) Unwrap() error

Jump to

Keyboard shortcuts

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