job

package
v0.0.0-...-e25df9a Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2015 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	JobDoesntExistErr = errors.New("The job you requested does not exist")
)

Functions

This section is empty.

Types

type Job

type Job struct {
	Name string `json:"name"`
	Id   string `json:"id"`

	// Command to run
	// e.g. "bash /path/to/my/script.sh"
	Command string `json:"command"`

	// Email of the owner of this job
	// e.g. "admin@example.com"
	Owner string `json:"owner"`

	// Is this job disabled?
	Disabled bool `json:"disabled"`

	// Jobs that are dependent upon this one will be run after this job runs.
	DependentJobs []string `json:"dependent_jobs"`

	// List of ids of jobs that this job is dependent upon.
	ParentJobs []string `json:"parent_jobs"`

	// ISO 8601 String
	// e.g. "R/2014-03-08T20:00:00.000Z/PT2H"
	Schedule string `json:"schedule"`

	// Number of times to retry on failed attempt for each run.
	Retries uint `json:"retries"`

	// Duration in which it is safe to retry the Job.
	Epsilon string `json:"epsilon"`

	// Meta data about successful and failed runs.
	SuccessCount     uint      `json:"success_count"`
	LastSuccess      time.Time `json:"last_success"`
	ErrorCount       uint      `json:"error_count"`
	LastError        time.Time `json:"last_error"`
	LastAttemptedRun time.Time `json:"last_attempted_run"`

	NextRunAt time.Time `json:"next_run_at"`

	Stats []*JobStat `json:"-"`
	// contains filtered or unexported fields
}

func GetMockJob

func GetMockJob() *Job

func GetMockJobWithGenericSchedule

func GetMockJobWithGenericSchedule() *Job

func GetMockJobWithSchedule

func GetMockJobWithSchedule(repeat int, scheduleTime time.Time, delay string) *Job

func (*Job) Delete

func (j *Job) Delete(cache JobCache, db JobDB)

func (*Job) Disable

func (j *Job) Disable()

Disable stops the job from running by stopping its jobTimer. It also sets Job.Disabled to true, which is reflected in the UI.

func (*Job) Init

func (j *Job) Init(cache JobCache) error

Init fills in the protected fields and parses the iso8601 notation. It also adds the job to the Cache

func (*Job) InitDelayDuration

func (j *Job) InitDelayDuration(checkTime bool) error

InitDelayDuration is used to parsed the iso8601 Schedule notation into its relevent fields in the Job struct. If checkTime is true, then it will return an error if the Scheduled time has passed.

func (*Job) Run

func (j *Job) Run(cache JobCache)

Run executes the Job's command, collects metadata around the success or failure of the Job's execution, and schedules the next run.

func (*Job) StartWaiting

func (j *Job) StartWaiting(cache JobCache)

StartWaiting begins a timer for when it should execute the Jobs .Run() method.

type JobCache

type JobCache interface {
	Get(id string) (*Job, error)
	GetAll() map[string]*Job

	Delete(id string)
	Persist() error
	// contains filtered or unexported methods
}

type JobDB

type JobDB interface {
	GetAll() ([]*Job, error)
	Get(id string) (*Job, error)
	Delete(id string)
	Save(job *Job) error
	Close() error
}

type JobStat

type JobStat struct {
	JobId             string
	RanAt             time.Time
	NumberOfRetries   uint
	Success           bool
	ExecutionDuration time.Duration
}

JobStat is used to store metrics about a specific Job .Run()

func NewJobStat

func NewJobStat(id string) *JobStat

type KalaStats

type KalaStats struct {
	ActiveJobs   int
	DisabledJobs int
	Jobs         int

	ErrorCount   uint
	SuccessCount uint

	NextRunAt        time.Time
	LastAttemptedRun time.Time

	CreatedAt time.Time
}

KalaStats is the struct for storing app-level metrics

func NewKalaStats

func NewKalaStats(cache JobCache) *KalaStats

NewKalaStats is used to easily generate a current app-level metrics report.

type MemoryJobCache

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

func NewMemoryJobCache

func NewMemoryJobCache(jobDB JobDB, persistWaitTime time.Duration) *MemoryJobCache

func NewMockCache

func NewMockCache() *MemoryJobCache

func (*MemoryJobCache) Delete

func (c *MemoryJobCache) Delete(id string)

func (*MemoryJobCache) Get

func (c *MemoryJobCache) Get(id string) (*Job, error)

func (*MemoryJobCache) GetAll

func (c *MemoryJobCache) GetAll() map[string]*Job

func (*MemoryJobCache) Persist

func (c *MemoryJobCache) Persist() error

func (*MemoryJobCache) PersistEvery

func (c *MemoryJobCache) PersistEvery()

func (*MemoryJobCache) Start

func (c *MemoryJobCache) Start()

type MockDB

type MockDB struct{}

func (*MockDB) Close

func (m *MockDB) Close() error

func (*MockDB) Delete

func (m *MockDB) Delete(id string)

func (*MockDB) Get

func (m *MockDB) Get(id string) (*Job, error)

func (*MockDB) GetAll

func (m *MockDB) GetAll() ([]*Job, error)

func (*MockDB) Save

func (m *MockDB) Save(job *Job) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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