jobs

package
v0.0.0-...-8018142 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: MPL-2.0 Imports: 13 Imported by: 6

README

jobs

GoDoc

Documentation

Overview

Package jobs manages the configuration and execution of the jobs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Name string      `mapstructure:"name"`
	Exec interface{} `mapstructure:"exec"`

	// service discovery
	Port          int           `mapstructure:"port"`
	InitialStatus string        `mapstructure:"initial_status"`
	Interfaces    interface{}   `mapstructure:"interfaces"`
	Tags          []string      `mapstructure:"tags"`
	ConsulExtras  *ConsulExtras `mapstructure:"consul"`

	// health checking
	Health *HealthConfig `mapstructure:"health"`

	// timeouts and restarts
	ExecTimeout string      `mapstructure:"timeout"`
	Restarts    interface{} `mapstructure:"restarts"`
	StopTimeout string      `mapstructure:"stopTimeout"`

	// related jobs and frequency
	When *WhenConfig `mapstructure:"when"`

	// logging
	Logging *LoggingConfig `mapstructure:"logging"`
	// contains filtered or unexported fields
}

Config holds the configuration for service discovery data

func NewConfigs

func NewConfigs(raw []interface{}, disc discovery.Backend) ([]*Config, error)

NewConfigs parses json config into a validated slice of Configs

func (*Config) String

func (cfg *Config) String() string

String implements the stdlib fmt.Stringer interface for pretty-printing

func (*Config) Validate

func (cfg *Config) Validate(disc discovery.Backend) error

Validate ensures that a Config meets all constraints

type ConsulExtras

type ConsulExtras struct {
	EnableTagOverride              bool   `mapstructure:"enableTagOverride"`
	DeregisterCriticalServiceAfter string `mapstructure:"deregisterCriticalServiceAfter"`
}

ConsulExtras handles additional Consul configuration.

type HealthConfig

type HealthConfig struct {
	CheckExec    interface{}    `mapstructure:"exec"`
	CheckTimeout string         `mapstructure:"timeout"`
	Heartbeat    int            `mapstructure:"interval"` // time in seconds
	TTL          int            `mapstructure:"ttl"`      // time in seconds
	Logging      *LoggingConfig `mapstructure:"logging"`
}

HealthConfig configures the Job's health checks

type Job

type Job struct {
	Name string

	// service health and discovery
	Status JobStatus

	Service *discovery.ServiceDefinition

	// completed
	IsComplete bool

	events.Subscriber
	events.Publisher
	// contains filtered or unexported fields
}

Job manages the state of a job and its start/stop conditions

func FromConfigs

func FromConfigs(cfgs []*Config) []*Job

FromConfigs creates Jobs from a slice of validated Configs

func NewJob

func NewJob(cfg *Config) *Job

NewJob creates a new Job from a Config

func (*Job) GetStatus

func (job *Job) GetStatus() JobStatus

GetStatus returns the current health status of the Job

func (*Job) Kill

func (job *Job) Kill()

Kill sends SIGTERM to the Job's executable, if any

func (*Job) Run

func (job *Job) Run(pctx context.Context, completedCh chan struct{})

Run executes the event loop for the Job

func (*Job) SendHeartbeat

func (job *Job) SendHeartbeat()

SendHeartbeat sends a heartbeat for this Job's service

func (*Job) String

func (job *Job) String() string

String implements the stdlib fmt.Stringer interface for pretty-printing

type JobStatus

type JobStatus int

JobStatus is an enum of job health status

func (JobStatus) String

func (i JobStatus) String() string

type LoggingConfig

type LoggingConfig struct {
	Raw bool `mapstructure:"raw"`
}

LoggingConfig handles job-specific logging fields

type WhenConfig

type WhenConfig struct {
	Frequency string `mapstructure:"interval"`
	Source    string `mapstructure:"source"`
	Once      string `mapstructure:"once"`
	Each      string `mapstructure:"each"`
	Timeout   string `mapstructure:"timeout"`
}

WhenConfig determines when a Job runs (dependencies on other Jobs, Watches, or frequency timers)

Jump to

Keyboard shortcuts

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