jobstore

package
v0.3.22 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompleteShard

func CompleteShard(ctx context.Context, db Store, shardID model.ShardID) error

CompleteShard a helper function to complete a shard, and update the job state if all other shards are completed.

func GetStateResolver

func GetStateResolver(db Store) *jobutils.StateResolver

func StopShard added in v0.3.21

func StopShard(ctx context.Context, db Store, shardID model.ShardID, reason string, userRequested bool) ([]model.ExecutionState, error)

StopShard a helper function to fail a shard, update the job state if all other shards are failed, and fail all executions.

Types

type ErrExecutionAlreadyExists

type ErrExecutionAlreadyExists struct {
	ExecutionID model.ExecutionID
}

ErrExecutionAlreadyExists is returned when an job already exists

func NewErrExecutionAlreadyExists

func NewErrExecutionAlreadyExists(id model.ExecutionID) ErrExecutionAlreadyExists

func (ErrExecutionAlreadyExists) Error

type ErrExecutionAlreadyTerminal

type ErrExecutionAlreadyTerminal struct {
	ExecutionID model.ExecutionID
	Actual      model.ExecutionStateType
	NewState    model.ExecutionStateType
}

ErrExecutionAlreadyTerminal is returned when an execution is already in terminal state and cannot be updated.

func (ErrExecutionAlreadyTerminal) Error

type ErrExecutionNotFound

type ErrExecutionNotFound struct {
	ExecutionID model.ExecutionID
}

ErrExecutionNotFound is returned when an job already exists

func NewErrExecutionNotFound

func NewErrExecutionNotFound(id model.ExecutionID) ErrExecutionNotFound

func (ErrExecutionNotFound) Error

func (e ErrExecutionNotFound) Error() string

type ErrInvalidExecutionState

type ErrInvalidExecutionState struct {
	ExecutionID model.ExecutionID
	Actual      model.ExecutionStateType
	Expected    model.ExecutionStateType
}

ErrInvalidExecutionState is returned when an execution is in an invalid state.

func (ErrInvalidExecutionState) Error

func (e ErrInvalidExecutionState) Error() string

type ErrInvalidExecutionVersion

type ErrInvalidExecutionVersion struct {
	ExecutionID model.ExecutionID
	Actual      int
	Expected    int
}

ErrInvalidExecutionVersion is returned when an execution has an invalid version.

func NewErrInvalidExecutionVersion

func NewErrInvalidExecutionVersion(id model.ExecutionID, actual int, expected int) ErrInvalidExecutionVersion

func (ErrInvalidExecutionVersion) Error

type ErrInvalidJobState

type ErrInvalidJobState struct {
	JobID    string
	Actual   model.JobStateType
	Expected model.JobStateType
}

ErrInvalidJobState is returned when an job is in an invalid state.

func NewErrInvalidJobState

func NewErrInvalidJobState(id string, actual model.JobStateType, expected model.JobStateType) ErrInvalidJobState

func (ErrInvalidJobState) Error

func (e ErrInvalidJobState) Error() string

type ErrInvalidJobVersion

type ErrInvalidJobVersion struct {
	JobID    string
	Actual   int
	Expected int
}

ErrInvalidJobVersion is returned when an job has an invalid version.

func NewErrInvalidJobVersion

func NewErrInvalidJobVersion(id string, actual int, expected int) ErrInvalidJobVersion

func (ErrInvalidJobVersion) Error

func (e ErrInvalidJobVersion) Error() string

type ErrInvalidShardState

type ErrInvalidShardState struct {
	ShardID  model.ShardID
	Actual   model.ShardStateType
	Expected model.ShardStateType
}

ErrInvalidShardState is returned when an shard is in an invalid state.

func NewErrInvalidShardState

func NewErrInvalidShardState(id model.ShardID, actual model.ShardStateType, expected model.ShardStateType) ErrInvalidShardState

func (ErrInvalidShardState) Error

func (e ErrInvalidShardState) Error() string

type ErrInvalidShardVersion

type ErrInvalidShardVersion struct {
	ShardID  model.ShardID
	Actual   int
	Expected int
}

ErrInvalidShardVersion is returned when an shard has an invalid version.

func NewErrInvalidShardVersion

func NewErrInvalidShardVersion(id model.ShardID, actual int, expected int) ErrInvalidShardVersion

func (ErrInvalidShardVersion) Error

func (e ErrInvalidShardVersion) Error() string

type ErrJobAlreadyExists

type ErrJobAlreadyExists struct {
	JobID string
}

ErrJobAlreadyExists is returned when an job already exists

func NewErrJobAlreadyExists

func NewErrJobAlreadyExists(id string) ErrJobAlreadyExists

func (ErrJobAlreadyExists) Error

func (e ErrJobAlreadyExists) Error() string

type ErrJobAlreadyTerminal

type ErrJobAlreadyTerminal struct {
	JobID    string
	Actual   model.JobStateType
	NewState model.JobStateType
}

ErrJobAlreadyTerminal is returned when an job is already in terminal state and cannot be updated.

func NewErrJobAlreadyTerminal

func NewErrJobAlreadyTerminal(id string, actual model.JobStateType, newState model.JobStateType) ErrJobAlreadyTerminal

func (ErrJobAlreadyTerminal) Error

func (e ErrJobAlreadyTerminal) Error() string

type ErrJobNotFound

type ErrJobNotFound struct {
	JobID string
}

ErrJobNotFound is returned when the job is not found

func NewErrJobNotFound

func NewErrJobNotFound(id string) ErrJobNotFound

func (ErrJobNotFound) Error

func (e ErrJobNotFound) Error() string

type ErrShardAlreadyTerminal

type ErrShardAlreadyTerminal struct {
	ShardID  model.ShardID
	Actual   model.ShardStateType
	NewState model.ShardStateType
}

ErrShardAlreadyTerminal is returned when an shard is already in terminal state and cannot be updated.

func NewErrShardAlreadyTerminal

func NewErrShardAlreadyTerminal(id model.ShardID, actual model.ShardStateType, newState model.ShardStateType) ErrShardAlreadyTerminal

func (ErrShardAlreadyTerminal) Error

func (e ErrShardAlreadyTerminal) Error() string

type ErrShardNotFound

type ErrShardNotFound struct {
	ShardID model.ShardID
}

ErrShardNotFound is returned when the Shard is not found

func NewErrShardNotFound

func NewErrShardNotFound(id model.ShardID) ErrShardNotFound

func (ErrShardNotFound) Error

func (e ErrShardNotFound) Error() string

type JobQuery

type JobQuery struct {
	ID          string              `json:"id"`
	ClientID    string              `json:"clientID"`
	IncludeTags []model.IncludedTag `json:"include_tags"`
	ExcludeTags []model.ExcludedTag `json:"exclude_tags"`
	Limit       int                 `json:"limit"`
	Offset      int                 `json:"offset"`
	ReturnAll   bool                `json:"return_all"`
	SortBy      string              `json:"sort_by"`
	SortReverse bool                `json:"sort_reverse"`
}

type Store

type Store interface {
	GetJob(ctx context.Context, id string) (model.Job, error)
	GetJobs(ctx context.Context, query JobQuery) ([]model.Job, error)
	GetJobState(ctx context.Context, jobID string) (model.JobState, error)
	GetInProgressJobs(ctx context.Context) ([]model.JobWithInfo, error)
	GetJobHistory(ctx context.Context, jobID string) ([]model.JobHistory, error)
	GetJobsCount(ctx context.Context, query JobQuery) (int, error)
	CreateJob(ctx context.Context, j model.Job) error
	// UpdateJobState updates the Job state
	UpdateJobState(ctx context.Context, request UpdateJobStateRequest) error
	// GetShardState returns the shard for a given id
	GetShardState(ctx context.Context, shardID model.ShardID) (model.ShardState, error)
	// UpdateShardState updates the shard state
	UpdateShardState(ctx context.Context, request UpdateShardStateRequest) error
	// CreateExecution creates a new execution for a given job
	CreateExecution(ctx context.Context, execution model.ExecutionState) error
	// UpdateExecution updates the Job state
	UpdateExecution(ctx context.Context, request UpdateExecutionRequest) error
}

A Store will persist jobs and their state to the underlying storage. It also gives an efficient way to retrieve jobs using queries.

type UpdateExecutionCondition

type UpdateExecutionCondition struct {
	ExpectedState    model.ExecutionStateType
	ExpectedVersion  int
	UnexpectedStates []model.ExecutionStateType
}

func (UpdateExecutionCondition) Validate

func (condition UpdateExecutionCondition) Validate(execution model.ExecutionState) error

Validate checks if the condition matches the given execution

type UpdateExecutionRequest

type UpdateExecutionRequest struct {
	ExecutionID model.ExecutionID
	Condition   UpdateExecutionCondition
	NewValues   model.ExecutionState
	Comment     string
}

type UpdateJobCondition

type UpdateJobCondition struct {
	ExpectedState    model.JobStateType
	UnexpectedStates []model.JobStateType
	ExpectedVersion  int
}

func (UpdateJobCondition) Validate

func (condition UpdateJobCondition) Validate(jobState model.JobState) error

Validate checks if the condition matches the given shard

type UpdateJobStateRequest

type UpdateJobStateRequest struct {
	JobID     string
	Condition UpdateJobCondition
	NewState  model.JobStateType
	Comment   string
}

type UpdateShardCondition

type UpdateShardCondition struct {
	ExpectedState    model.ShardStateType
	UnexpectedStates []model.ShardStateType
	ExpectedVersion  int
}

func (UpdateShardCondition) Validate

func (condition UpdateShardCondition) Validate(shard model.ShardState) error

Validate checks if the condition matches the given shard

type UpdateShardStateRequest

type UpdateShardStateRequest struct {
	ShardID   model.ShardID
	Condition UpdateShardCondition
	NewState  model.ShardStateType
	Comment   string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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