resource

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2022 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package resource provides model representations that users of job-manager typically interact with. job-manager as well as backends should use these types, as opposed to protobufs or backend representations.

Index

Constants

This section is empty.

Variables

View Source
var ErrGenericNotFound = &Error{
	Status:  http.StatusNotFound,
	Message: "not found",
	Kind:    "not_found",
}
View Source
var ErrMethodNotAllowed = &Error{
	Status:  http.StatusMethodNotAllowed,
	Message: "method not allowed",
	Kind:    "method_not_allowed",
}

Functions

func ParseCLIArgs added in v0.3.0

func ParseCLIArgs(args []string) ([]interface{}, error)

func StatusIsDone

func StatusIsDone(status *Status) bool

func StatusStrings

func StatusStrings(statuses ...*Status) []string

Types

type Ack

type Ack struct {
	ID     string  `json:"-" db:"id"`
	JobID  string  `json:"job_id" db:"job_id"`
	Status *Status `json:"status"`
	Data   []byte  `json:"data,omitempty"`
	Error  string  `json:"error,omitempty"`
}

func (*Ack) String

func (ack *Ack) String() string

type Acks

type Acks struct {
	Acks []*Ack `json:"acks"`
}

func (*Acks) JobIDs

func (as *Acks) JobIDs() []string

type Duration

type Duration time.Duration

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (*Duration) String

func (d *Duration) String() string

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

type Error

type Error struct {
	Status     int                `json:"status,omitempty"`
	Message    string             `json:"message"`
	Kind       string             `json:"kind"`
	Resource   string             `json:"resource,omitempty"`
	ResourceID string             `json:"resource_id,omitempty"`
	Reason     string             `json:"reason,omitempty"`
	Orig       error              `json:"orig,omitempty"`
	Invalid    []*ValidationError `json:"invalid,omitempty"`
	IDs        []string           `json:"ids,omitempty"`
}

func NewBlockedError added in v0.4.0

func NewBlockedError(resource, resourceID, reason string) *Error

func NewConflictError

func NewConflictError(resource, resourceID, reason string) *Error

func NewInternalServerError

func NewInternalServerError(err error) *Error

func NewNotFoundError

func NewNotFoundError(resource, resourceID, reason string) *Error

func NewUnprocessableEntityError

func NewUnprocessableEntityError(resource, resourceID, reason string, ids []string) *Error

func NewValidationError

func NewValidationError(resource, resourceID, reason string, verrs []*ValidationError) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) GetStatus

func (e *Error) GetStatus() int

func (*Error) Is

func (e *Error) Is(iother error) bool

func (*Error) Unwrap

func (e *Error) Unwrap() error

type GetByIDOpts

type GetByIDOpts struct {
	Includes []string `json:"include,omitempty"`
}

type Job

type Job struct {
	ID string `json:"id"`
	// QueueID is the id of the queue that manages this job.
	QueueID        string        `json:"-" db:"queue_id"`
	Version        *Version      `json:"version" db:"v"`
	Name           string        `json:"name"`
	QueueVersion   *Version      `json:"queue_version" db:"queue_v"`
	ArgsRaw        []byte        `json:"args" db:"args"`
	Data           *JobData      `json:"data,omitempty" db:"-"`
	DataRaw        []byte        `json:"-" db:"data"`
	Status         *Status       `json:"status"`
	Attempt        int           `json:"attempt,omitempty"`
	Checkins       []*JobCheckin `json:"checkins,omitempty"`
	Results        []*JobResult  `json:"results,omitempty"`
	EnqueuedAt     time.Time     `json:"enqueued_at,omitempty" db:"enqueued_at"`
	StartedAt      NullTime      `json:"-" db:"started_at"`
	CompletedAt    NullTime      `json:"-" db:"completed_at"`
	BackoffInitial Duration      `json:"-" db:"backoff_initial_duration"`
	BackoffMax     Duration      `json:"-" db:"backoff_max_duration"`
	BackoffFactor  float32       `json:"-" db:"backoff_factor"`
	// Duration lives on queues, but consumers need it for correct timeouts.
	Duration Duration `json:"duration,omitempty" db:"duration"`
}

func (*Job) ArgKey

func (jb *Job) ArgKey() (string, error)

func (*Job) Copy

func (jb *Job) Copy() *Job

func (*Job) HasStatus

func (jb *Job) HasStatus(statuses ...*Status) bool

func (*Job) IsAttempted

func (jb *Job) IsAttempted() bool

func (*Job) LastClaimWindow

func (jb *Job) LastClaimWindow() time.Time

func (*Job) LastResult

func (jb *Job) LastResult() *JobResult

func (*Job) String

func (jb *Job) String() string

type JobCheckin

type JobCheckin struct {
	ID        string    `json:"-"`
	JobID     string    `json:"-" db:"job_id"`
	Data      []byte    `json:"data,omitempty"`
	CreatedAt time.Time `json:"created_at" db:"created_at"`
}

type JobData

type JobData struct {
	Claims  label.Claims `json:"claims,omitempty"`
	DataRaw []byte       `json:"data,omitempty"`
}

type JobListParams

type JobListParams struct {
	Queues        []string         `json:"names,omitempty"`
	Statuses      []*Status        `json:"statuses,omitempty"`
	Selectors     *label.Selectors `json:"selectors,omitempty"`
	Claims        label.Claims     `json:"claims,omitempty"`
	EnqueuedSince time.Time        `json:"enqueued_since,omitempty"`
	EnqueuedUntil time.Time        `json:"enqueued_until,omitempty"`
	NoPaused      bool             `json:"no_paused,omitempty"`
	NoBlocked     bool             `json:"no_blocked,omitempty"`

	// NoUnclaimed will exclude jobs that have outstanding claims.
	NoUnclaimed bool        `json:"no_unclaimed,omitempty"`
	Page        *Pagination `json:"page,omitempty"`
	Includes    []string    `json:"include,omitempty"`
}

type JobResult

type JobResult struct {
	ID          string    `json:"-"`
	JobID       string    `json:"-" db:"job_id"`
	Attempt     int       `json:"attempt"`
	Status      *Status   `json:"status"`
	Data        []byte    `json:"data,omitempty"`
	Error       string    `json:"error,omitempty"`
	StartedAt   time.Time `json:"started_at" db:"started_at"`
	CompletedAt time.Time `json:"completed_at" db:"completed_at"`
}

type Jobs

type Jobs struct {
	Jobs []*Job `json:"jobs"`
}

func (*Jobs) ArgKeys

func (jobs *Jobs) ArgKeys() ([]string, error)

func (*Jobs) IDs

func (jobs *Jobs) IDs() []string

func (*Jobs) Queues

func (jobs *Jobs) Queues() []string

type NullRawMessage

type NullRawMessage struct {
	json.RawMessage
	Valid bool
}

func (*NullRawMessage) Scan

func (n *NullRawMessage) Scan(value interface{}) error

Scan implements the Scanner interface.

func (NullRawMessage) Value

func (n NullRawMessage) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullTime added in v0.3.0

type NullTime struct {
	sql.NullTime
}

func (NullTime) MarshalJSON added in v0.3.0

func (v NullTime) MarshalJSON() ([]byte, error)

func (*NullTime) UnmarshalJSON added in v0.3.0

func (v *NullTime) UnmarshalJSON(data []byte) error

type Pagination

type Pagination struct {
	Limit  int64  `json:"limit,omitempty"`
	LastID string `json:"last_id,omitempty"`
}

type Queue

type Queue struct {
	ID              string       `json:"-"`
	Name            string       `json:"name"`
	Version         *Version     `json:"version" db:"v"`
	Retries         int          `json:"retries,omitempty"`
	Duration        Duration     `json:"duration,omitempty"`
	CheckinDuration Duration     `json:"checkin_duration,omitempty" db:"checkin_duration"`
	ClaimDuration   Duration     `json:"claim_duration,omitempty" db:"claim_duration"`
	Unique          bool         `json:"unique,omitempty" db:"unique_args"`
	Labels          label.Labels `json:"labels,omitempty"`
	SchemaRaw       []byte       `json:"schema_raw,omitempty" db:"job_schema"`
	BackoffInitial  Duration     `json:"backoff_initial" db:"backoff_initial_duration"`
	BackoffMax      Duration     `json:"backoff_max" db:"backoff_max_duration"`
	BackoffFactor   float32      `json:"backoff_factor" db:"backoff_factor"`
	Paused          bool         `json:"paused"`
	Unpaused        bool         `json:"unpaused"`
	Blocked         bool         `json:"blocked"`
	CreatedAt       time.Time    `json:"created_at" db:"created_at"`
	UpdatedAt       time.Time    `json:"-" db:"updated_at"`
	DeletedAt       NullTime     `json:"deleted_at,omitempty" db:"deleted_at"`
}

func (*Queue) ClaimExpired

func (q *Queue) ClaimExpired(job *Job, now time.Time) bool

func (*Queue) Copy

func (q *Queue) Copy() *Queue

func (*Queue) Equal

func (q *Queue) Equal(other *Queue) bool

func (*Queue) EqualAttrs

func (q *Queue) EqualAttrs(other *Queue) bool

func (*Queue) String

func (q *Queue) String() string

type QueueListParams

type QueueListParams struct {
	Names     []string         `json:"names,omitempty"`
	Selectors *label.Selectors `json:"selectors,omitempty"`
	Page      *Pagination      `json:"page,omitempty"`
	Includes  []string         `json:"include,omitempty"`
}

type Queues

type Queues struct {
	Queues []*Queue `json:"queues"`
}

func (*Queues) ToMap

func (qs *Queues) ToMap() map[string]*Queue

type Stats

type Stats struct {
	Queued           int64 `json:"queued"`
	Running          int64 `json:"running"`
	Complete         int64 `json:"complete"`
	Dead             int64 `json:"dead"`
	Cancelled        int64 `json:"cancelled"`
	Invalid          int64 `json:"invalid"`
	Failed           int64 `json:"failed"`
	LongestUnstarted int64 `json:"longest_unstarted_secs"`
}

type Status

type Status int
const (
	StatusUnspecified Status = iota
	StatusQueued
	StatusRunning
	StatusComplete
	StatusDead
	StatusCancelled
	StatusInvalid
	StatusFailed
)

func NewStatus

func NewStatus(s Status) *Status

func StatusFromString

func StatusFromString(s string) *Status

func StatusesFromStrings

func StatusesFromStrings(statuses ...string) []*Status

func (Status) MarshalJSON added in v0.3.0

func (s Status) MarshalJSON() ([]byte, error)

func (*Status) Scan

func (s *Status) Scan(value interface{}) error

func (*Status) String

func (s *Status) String() string

func (*Status) UnmarshalJSON added in v0.3.0

func (s *Status) UnmarshalJSON(data []byte) error

func (*Status) Value

func (s *Status) Value() (driver.Value, error)

type ValidationError

type ValidationError struct {
	Message  string      `json:"message"`
	Path     string      `json:"path,omitempty"`
	ValueRaw string      `json:"value_raw,omitempty"`
	Value    interface{} `json:"value,omitempty"`
}

type Version

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

func NewVersion

func NewVersion(v int32) *Version

func NewVersionFromString

func NewVersionFromString(s string) (*Version, error)

func (*Version) Equals

func (v *Version) Equals(other *Version) bool

func (*Version) Inc

func (v *Version) Inc()

func (Version) MarshalJSON

func (v Version) MarshalJSON() ([]byte, error)

func (*Version) Raw

func (v *Version) Raw() int32

func (*Version) Scan

func (v *Version) Scan(value interface{}) error

func (*Version) Strict

func (v *Version) Strict() string

func (*Version) String

func (v *Version) String() string

func (*Version) UnmarshalJSON

func (v *Version) UnmarshalJSON(b []byte) error

func (*Version) Value

func (v *Version) Value() (driver.Value, error)

Directories

Path Synopsis
job
v1
Package v1 contains the protocol for working with jobs and queues.
Package v1 contains the protocol for working with jobs and queues.

Jump to

Keyboard shortcuts

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