domain

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Version = "1.4.3"
)

Variables

View Source
var (
	ErrConflict = errors.New("conflict")
	ErrNotFound = errors.New("not found")
)
View Source
var (
	DefaultRetryPolicy = &RetryPolicy{
		RetryCount:    3,
		RetryInterval: 5 * Duration(time.Second),
		Deadline:      20 * Duration(time.Second),
	}

	Connected    = &UpdateEvent{ObjectType: "connection", Operation: "connected"}
	Disconnected = &UpdateEvent{ObjectType: "connection", Operation: "disconnected"}
	Reconnected  = &UpdateEvent{ObjectType: "connection", Operation: "reconnected"}
)
View Source
var ErrUnableCancelJob = errorstate.Single(&errorstate.Detail{
	Domain:   domain,
	Type:     "field",
	Location: "running",
	Reason:   "not implemented",
	Message:  "Unable to cancel the running job.",
})

Functions

func NewID

func NewID() string

func ParseBefore

func ParseBefore(s string) (time.Time, error)

func ValidateCollection

func ValidateCollection(c *Collection) error

func ValidateID

func ValidateID(s string) error

func ValidateJobDefinition

func ValidateJobDefinition(j *JobDefinition) error

func ValidateJobListFields

func ValidateJobListFields(fields []string) error

func ValidateURI

func ValidateURI(uri string) error

func ValidateVariable

func ValidateVariable(v *Variable) error

Types

type Action

type Action struct {
	Type        string       `json:"type"`
	Request     *HttpRequest `json:"request"`
	RetryPolicy *RetryPolicy `json:"retryPolicy,omitempty"`
}

type Collection

type Collection struct {
	CollectionItem
	Updated time.Time `json:"updated"`
}

func (*Collection) ETag

func (c *Collection) ETag() string

type CollectionItem

type CollectionItem struct {
	ID    string          `json:"id"`
	Name  string          `json:"name"`
	State CollectionState `json:"state"`
}

type CollectionState

type CollectionState int
const (
	CollectionStateEnabled CollectionState = iota + 1
	CollectionStateDisabled
)

func (CollectionState) MarshalJSON

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

MarshalJSON marshals the enum as a quoted json string

func (*CollectionState) UnmarshalJSON

func (s *CollectionState) UnmarshalJSON(b []byte) error

UnmarshalJSON unmashals a quoted json string to the enum value

type Duration

type Duration time.Duration

func (Duration) MarshalJSON

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

MarshalJSON marshals the duration as a json string

func (*Duration) UnmarshalJSON

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

UnmarshalJSON unmashals a json string to the duration value

type HttpRequest

type HttpRequest struct {
	Method  string           `json:"method,omitempty"`
	URI     string           `json:"uri"`
	Headers []*NameValuePair `json:"headers,omitempty"`
	Body    string           `json:"body,omitempty"`
}

func (*HttpRequest) Transpose

func (req *HttpRequest) Transpose(variables map[string]string) (*HttpRequest, error)

type JobDefinition

type JobDefinition struct {
	JobItem
	Updated time.Time `json:"updated"`
	Action  *Action   `json:"action"`
}

func (*JobDefinition) ETag

func (j *JobDefinition) ETag() string

type JobHistory

type JobHistory struct {
	JobID      string           `json:"-"`
	Action     string           `json:"action"`
	Started    time.Time        `json:"started"`
	Finished   time.Time        `json:"finished"`
	Status     JobHistoryStatus `json:"status"`
	RetryCount int              `json:"retryCount,omitempty"`
	Message    *string          `json:"message,omitempty"`
}

type JobHistoryStatus

type JobHistoryStatus int
const (
	JobHistoryStatusCompleted JobHistoryStatus = iota + 1
	JobHistoryStatusFailed
)

func (JobHistoryStatus) MarshalJSON

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

MarshalJSON marshals the enum as a quoted json string

func (JobHistoryStatus) String

func (s JobHistoryStatus) String() string

Strings returns a human readable representation of status

func (*JobHistoryStatus) UnmarshalJSON

func (s *JobHistoryStatus) UnmarshalJSON(b []byte) error

UnmarshalJSON unmashals a quoted json string to the enum value

type JobItem

type JobItem struct {
	ID           string         `json:"id"`
	Name         string         `json:"name"`
	CollectionID string         `json:"collectionId"`
	State        JobState       `json:"state"`
	Schedule     string         `json:"schedule"`
	Status       *JobStatusCode `json:"status,omitempty"`
	ErrorRate    *float32       `json:"errorRate,omitempty"`
}

type JobState

type JobState int
const (
	JobStateEnabled JobState = iota + 1
	JobStateDisabled
)

func (JobState) MarshalJSON

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

MarshalJSON marshals the enum as a quoted json string

func (*JobState) UnmarshalJSON

func (s *JobState) UnmarshalJSON(b []byte) error

UnmarshalJSON unmashals a quoted json string to the enum value

type JobStatus

type JobStatus struct {
	Updated    time.Time  `json:"updated"`
	Running    bool       `json:"running"`
	RunCount   int        `json:"runCount"`
	ErrorCount int        `json:"errorCount"`
	LastRun    *time.Time `json:"lastRun,omitempty"`
	NextRun    *time.Time `json:"nextRun,omitempty"`
}

func (*JobStatus) ETag

func (j *JobStatus) ETag() string

type JobStatusCode

type JobStatusCode int
const (
	JobStatusReady JobStatusCode = iota + 1
	JobStatusRunning
	JobStatusPassing
	JobStatusFailing
)

func (JobStatusCode) MarshalJSON

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

MarshalJSON marshals the enum as a quoted json string

func (*JobStatusCode) UnmarshalJSON

func (s *JobStatusCode) UnmarshalJSON(b []byte) error

UnmarshalJSON unmashals a quoted json string to the enum value

type NameValuePair

type NameValuePair struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type Repository

type Repository interface {
	Ping() error
	Close() error

	ListCollections() ([]*CollectionItem, error)
	CreateCollection(c *Collection) error
	RetrieveCollection(id string) (*Collection, error)
	UpdateCollection(c *Collection) error
	DeleteCollection(id string) error

	ListVariables(collectionID string) ([]*VariableItem, error)
	MapVariables(collectionID string) (map[string]string, error)
	CreateVariable(v *Variable) error
	RetrieveVariable(id string) (*Variable, error)
	UpdateVariable(v *Variable) error
	DeleteVariable(id string) error

	ListJobs(collectionID string, fields []string) ([]*JobItem, error)
	CreateJob(j *JobDefinition) error
	RetrieveJob(id string) (*JobDefinition, error)
	UpdateJob(j *JobDefinition) error
	DeleteJob(id string) error

	RetrieveJobStatus(id string) (*JobStatus, error)
	ListLeftOverJobs() ([]string, error)
	ResetJobStatus(id string) error

	ListJobHistory(id string) ([]*JobHistory, error)
	DeleteJobHistory(id string, before time.Time) error

	AcquireJob(id string, deadline time.Duration) error
	AddJobHistory(*JobHistory) error
}

type RetryPolicy

type RetryPolicy struct {
	RetryCount    int      `json:"retryCount"`
	RetryInterval Duration `json:"retryInterval"`
	Deadline      Duration `json:"deadline"`
}

type RunError

type RunError struct {
	Code int
	Err  error
}

func (*RunError) Error

func (r *RunError) Error() string

type Runner

type Runner interface {
	Run(ctx context.Context, a *Action) error
}

type Scheduler

type Scheduler interface {
	SetRunner(f func(*JobDefinition))
	ListIDs() []string
	Add(j *JobDefinition) error
	Remove(id string)
	NextRun(id string) *time.Time
	Start()
	Stop()
}

type Subscriber

type Subscriber interface {
	SetCallback(callback UpdateEventCallback)
	Start()
	Stop()
}

type UpdateEvent

type UpdateEvent struct {
	ObjectType string
	Operation  string
	ObjectID   string
}

type UpdateEventCallback

type UpdateEventCallback func(*UpdateEvent) error

type Variable

type Variable struct {
	VariableItem
	Value string `json:"value"`
}

func (*Variable) ETag

func (c *Variable) ETag() string

type VariableItem

type VariableItem struct {
	ID           string    `json:"id"`
	Name         string    `json:"name"`
	CollectionID string    `json:"collectionId"`
	Updated      time.Time `json:"updated"`
}

Jump to

Keyboard shortcuts

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