jobs

package
v0.10.5 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2023 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const ErrExecFailure = "ExecutionFailure"
View Source
const ErrMissingDetails = "MissingDetails"
View Source
const ErrPostExecFailure = "PostExecutionFailure"
View Source
const ErrPreExecFailure = "PreExecutionFailure"
View Source
const ErrQueueIsEmpty = "QueueIsEmpty"

Variables

This section is empty.

Functions

func ErrCode

func ErrCode(msg string, err error) error

func NewID

func NewID() string

NewID returns a new ID for a job. Currently this is just a UUID string

Types

type DatabaseRunner added in v0.9.0

type DatabaseRunner struct {
	Endpoint         string
	EndpointTemplate string
	Token            string
}

func NewDatabaseRunner added in v0.9.0

func NewDatabaseRunner(config map[string]interface{}) (*DatabaseRunner, error)

NewDatabaseRunner creates and configures a new database runner. An endpoint or endpoint template is required the endpoint and endpoint template are not currently validated but this can/should be done in the future. If a a token is passed, it will be configured but is not required.

func (*DatabaseRunner) Run added in v0.9.0

func (r *DatabaseRunner) Run(ctx context.Context, account string, parameters interface{}) (string, error)

Run executes the DatabaseRunner. The instance_id and database_action are required. Allowable actions are 'start' and 'stop'. If an endpoint is configured on the runner, it will be used, otherwise we assume there is an endpointTemplate and try to execute it. Database actions are currently only executed with the PUT method and a body containing {"state": "action"}.

type DummyRunner

type DummyRunner struct {
	Template string
}

func NewDummyRunner

func NewDummyRunner(config map[string]interface{}) (*DummyRunner, error)

NewDummyRunner creates a new dummy runner that doesn't do anything, but requires a template and returns that executed template when called

func (*DummyRunner) Run

func (r *DummyRunner) Run(ctx context.Context, account string, parameters interface{}) (string, error)

Run executes the DummyRunner, ignoring the parameters

type InstanceRunner

type InstanceRunner struct {
	Endpoint         string
	EndpointTemplate string
	Token            string
	Encrypt          bool
	AuthHeader       string
}

func NewInstanceRunner

func NewInstanceRunner(config map[string]interface{}) (*InstanceRunner, error)

NewInstanceRunner creates and configures a new instance runner. An endpoint or endpoint template is required the endpoint and endpoint template are not currently validated but this can/should be done in the future. If a a token is passed, it will be configured but is not required.

func (*InstanceRunner) Run

func (r *InstanceRunner) Run(ctx context.Context, account string, parameters interface{}) (string, error)

Run executes the InstanceRunner. The instance_id and instance_action are required. Allowable actions are 'start', 'stop' and 'reboot'. If an endpoint is configured on the runner, it will be used, otherwise we assume there is an endpointTemplate and try to execute it. Instance actions are currently only executed with the PUT method and a body containing {"state": "action"}.

type Job

type Job struct {
	Account            string
	Description        string
	Details            map[string]string
	Enabled            bool
	ID                 string
	ModifiedBy         string
	ModifiedAt         *time.Time
	Name               string
	Group              string
	ScheduleExpression string
}

Job is the detail about a job

func (*Job) MarshalBinary

func (m *Job) MarshalBinary() ([]byte, error)

func (Job) MarshalJSON

func (m Job) MarshalJSON() ([]byte, error)

MarshalJSON is a custom JSON marshaller for a job

func (*Job) NextRun added in v0.6.1

func (j *Job) NextRun(t time.Time) (*time.Time, error)

NextRun returns the next invocation of the schedule expression

func (*Job) UnmarshalBinary

func (m *Job) UnmarshalBinary(data []byte) error

func (*Job) UnmarshalJSON

func (m *Job) UnmarshalJSON(j []byte) error

UnmarshalJSON is a custom JSON unmarshaller for a job

type Locker

type Locker interface {
	Lock(key, id string) error
}

type QueueError

type QueueError struct {
	Code    string
	Message string
	OrigErr error
}

Error wraps lower level errors with code, message and an original error

func NewQueueError

func NewQueueError(code, message string, err error) QueueError

New constructs a QueueError and returns it as an error

func (QueueError) Error

func (e QueueError) Error() string

Error Satisfies the Error interface

func (QueueError) String

func (e QueueError) String() string

String returns the error as string

func (QueueError) Unwrap

func (e QueueError) Unwrap() error

Unwrap returns the contained error

type QueuedJob

type QueuedJob struct {
	ID    string
	Score float64
}

type Queuer

type Queuer interface {
	Close() error
	Enqueue(queued *QueuedJob) error
	Fetch(queued *QueuedJob) error
	Finalize(id string) error
}

type RedisLocker

type RedisLocker struct {
	Expire time.Duration
	Prefix string
	// contains filtered or unexported fields
}

RedisLocker is a redis lock/unlock provider.

func NewRedisLocker

func NewRedisLocker(prefix, address, password string, db int, expiration string) (*RedisLocker, error)

NewRedisLocker returns a new redis lock provider

func (*RedisLocker) Lock

func (l *RedisLocker) Lock(key, id string) error

Lock locks l.Prefix-key with the value id in a redis set. This uses SetNX. If the result is an error or false, the key was not set and the lock was not aquired.

type RedisQueuer

type RedisQueuer struct {
	BackupName string

	Name   string
	Window int64
	// contains filtered or unexported fields
}

func NewRedisQueuer

func NewRedisQueuer(name, address, password string, db int, window int64) (*RedisQueuer, error)

func (*RedisQueuer) Close

func (q *RedisQueuer) Close() error

Close the redis client connection

func (*RedisQueuer) Enqueue

func (q *RedisQueuer) Enqueue(queued *QueuedJob) error

Add jobs to both sets

func (*RedisQueuer) Fetch

func (q *RedisQueuer) Fetch(queued *QueuedJob) error

func (*RedisQueuer) Finalize

func (q *RedisQueuer) Finalize(id string) error

Finalize does the final steps once a job is completed successfully, currently this is just dequeuing the backup job created when the job was queued.

type Repository

type Repository interface {
	Create(ctx context.Context, account, group string, job *Job) (*Job, error)
	Delete(ctx context.Context, account, group, id string) error
	Get(ctx context.Context, account, group, id string) (*Job, error)
	List(ctx context.Context, account, group string) ([]string, error)
	Update(ctx context.Context, account, group, id string, job *Job) (*Job, error)
}

type Runner

type Runner interface {
	Run(ctx context.Context, account string, parameters interface{}) (string, error)
}

Runner has a Run method and runs a job

type RunnerError

type RunnerError struct {
	Code    string
	Message string
	OrigErr error
}

func NewRunnerError

func NewRunnerError(code, message string, err error) RunnerError

New constructs a RunnerError and returns it as an error

func (RunnerError) Error

func (e RunnerError) Error() string

Error Satisfies the Error interface

func (RunnerError) String

func (e RunnerError) String() string

String returns the error as string

func (RunnerError) Unwrap

func (e RunnerError) Unwrap() error

Unwrap returns the contained error

type S3Repository

type S3Repository struct {
	S3     s3iface.S3API
	Bucket string
	Prefix string
	// contains filtered or unexported fields
}

S3Repository is an implementation of a jobs respository in S3

func New

func New(opts ...S3RepositoryOption) (*S3Repository, error)

New creates an S3Repository from a list of S3RepositoryOption functions

func NewDefaultRepository

func NewDefaultRepository(config map[string]interface{}) (*S3Repository, error)

NewDefaultRepository creates a new repository from the default config data

func (*S3Repository) Create

func (s *S3Repository) Create(ctx context.Context, account, group string, job *Job) (*Job, error)

Create creates a job in the s3 jobs repository

func (*S3Repository) Delete

func (s *S3Repository) Delete(ctx context.Context, account, group, id string) error

Delete deletes a job in the s3 jobs repository

func (*S3Repository) Get

func (s *S3Repository) Get(ctx context.Context, account, group, id string) (*Job, error)

Get gets a job from the s3 jobs repository - jobs are in the path /<account>/<group>/<job id>

func (*S3Repository) List

func (s *S3Repository) List(ctx context.Context, account, group string) ([]string, error)

List lists the jobs in the s3 jobs repository. If group is empty, all jobs are returned from the account. If some of those jobs are in a group, the group is prefixed with the job id in the response.

func (*S3Repository) Update

func (s *S3Repository) Update(ctx context.Context, account, group, id string, job *Job) (*Job, error)

Update updates a job in the s3 jobs repository

type S3RepositoryOption

type S3RepositoryOption func(*S3Repository)

S3RepositoryOption is a function to set repository options

func WithBucket

func WithBucket(bucket string) S3RepositoryOption

WithBucket sets the bucket for the S3Repository

func WithEndpoint

func WithEndpoint(endpoint string) S3RepositoryOption

WithEndpoint sets the endpoint for the S3Repository

func WithPrefix

func WithPrefix(prefix string) S3RepositoryOption

WithPrefix sets the bucket prefix for the S3Repository

func WithRegion

func WithRegion(region string) S3RepositoryOption

WithRegion sets the region for the S3Repository

func WithStaticCredentials

func WithStaticCredentials(akid, secret, token string) S3RepositoryOption

WithStaticCredentials authenticates with AWS static credentials (key, secret, token)

type ServiceRunner added in v0.6.0

type ServiceRunner struct {
	Endpoint         string
	EndpointTemplate string
	Token            string
	Encrypt          bool
	AuthHeader       string
}

func NewServiceRunner added in v0.6.0

func NewServiceRunner(config map[string]interface{}) (*ServiceRunner, error)

NewServiceRunner creates and configures a new service runner. An endpoint or endpoint template is required the endpoint and endpoint template are not currently validated but this can/should be done in the future. If a a token is passed, it will be configured but is not required.

func (*ServiceRunner) Run added in v0.6.0

func (r *ServiceRunner) Run(ctx context.Context, account string, parameters interface{}) (string, error)

Run executes the ServiceRunner. The service_cluster, service_name and service_action are required. Allowable actions are 'scale'. If an endpoint is configured on the runner, it will be used, otherwise we assume there is an endpointTemplate and try to execute it.

type ServiceRunnerScaleInput added in v0.6.0

type ServiceRunnerScaleInput struct {
	Account string
	Cluster string
	Name    string
	// contains filtered or unexported fields
}

type Tag added in v0.3.0

type Tag struct {
	Key   string
	Value string
}

Tag is a key value struct for holding tag information

type TaskRunner added in v0.10.0

type TaskRunner struct {
	Endpoint         string
	EndpointTemplate string
	Token            string
	Encrypt          bool
	AuthHeader       string
}

func NewTaskRunner added in v0.10.0

func NewTaskRunner(config map[string]interface{}) (*TaskRunner, error)

NewTaskRunner creates and configures a new task runner. An endpoint or endpoint template is required the endpoint and endpoint template are not currently validated but this can/should be done in the future. If a token is passed, it will be configured but is not required.

func (*TaskRunner) Run added in v0.10.0

func (r *TaskRunner) Run(ctx context.Context, account string, parameters interface{}) (string, error)

Run executes the TaskRunner. The task_cluster, task_name and task_action are required. Allowable actions are 'run'. If an endpoint is configured on the runner, it will be used, otherwise we assume there is an endpointTemplate and try to execute it.

type TaskRunnerRunInput added in v0.10.0

type TaskRunnerRunInput struct {
	Account string
	Cluster string
	Name    string
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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