job

package
v0.0.0-...-ebb22de Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2015 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RFC3339WithoutTimezone = "2006-01-02T15:04:05"

	ErrInvalidJob = errors.New("Invalid Job. Job's must contain a Name and a Command field")
)
View Source
var (
	ErrJobDisabled = errors.New("Job cannot run, as it is disabled")
	ErrCmdIsEmpty  = errors.New("Job Command is empity.")
)
View Source
var (
	ErrJobDoesntExist = errors.New("The job you requested does not exist")
)

Functions

This section is empty.

Types

type ErrJobNotFound

type ErrJobNotFound string

ErrJobNotFound is raised when a Job is able to be found within a database.

func (ErrJobNotFound) Error

func (id ErrJobNotFound) Error() string

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"`

	NextRunAt time.Time `json:"next_run_at"`

	// Meta data about successful and failed runs.
	Metadata Metadata `json:"metadata"`

	// Collection of Job Stats
	Stats []*JobStat `json:"stats"`
	// 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 NewFromBytes

func NewFromBytes(b []byte) (*Job, error)

NewFromBytes returns a Job instance from a byte representation.

func (Job) Bytes

func (j Job) Bytes() ([]byte, error)

Bytes returns the byte representation of the Job.

func (*Job) Delete

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

func (*Job) DeleteFromDependentJobs

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

DeleteFromDependentJobs

func (*Job) DeleteFromParentJobs

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

DeleteFromParentJobs goes through and deletes the current job from any parent jobs.

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) Enable

func (j *Job) Enable(cache JobCache)

func (*Job) GetWaitDuration

func (j *Job) GetWaitDuration() time.Duration

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)

func (*Job) StartWaiting

func (j *Job) StartWaiting(cache JobCache)

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

func (*Job) StopTimer

func (j *Job) StopTimer()

type JobCache

type JobCache interface {
	Get(id string) (*Job, error)
	GetAll() *JobsMap
	Set(j *Job) error
	Delete(id string) error
	Persist() error
}

type JobDB

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

type JobRunner

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

func (*JobRunner) Run

func (j *JobRunner) Run(cache JobCache) (*JobStat, Metadata, error)

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

type JobStat

type JobStat struct {
	JobId             string        `json:"job_id"`
	RanAt             time.Time     `json:"ran_at"`
	NumberOfRetries   uint          `json:"number_of_retries"`
	Success           bool          `json:"success"`
	ExecutionDuration time.Duration `json:"execution_duration"`
}

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

func NewJobStat

func NewJobStat(id string) *JobStat

type JobsMap

type JobsMap struct {
	Jobs map[string]*Job
	Lock sync.RWMutex
}

func NewJobsMap

func NewJobsMap() *JobsMap

type KalaStats

type KalaStats struct {
	ActiveJobs   int `json:"active_jobs"`
	DisabledJobs int `json:"disabled_jobs"`
	Jobs         int `json:"jobs"`

	ErrorCount   uint `json:"error_count"`
	SuccessCount uint `json:"success_count"`

	NextRunAt        time.Time `json:"next_run_at"`
	LastAttemptedRun time.Time `json:"last_attempted_run"`

	CreatedAt time.Time `json:"created"`
}

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) *MemoryJobCache

func NewMockCache

func NewMockCache() *MemoryJobCache

func (*MemoryJobCache) Delete

func (c *MemoryJobCache) Delete(id string) error

func (*MemoryJobCache) Get

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

func (*MemoryJobCache) GetAll

func (c *MemoryJobCache) GetAll() *JobsMap

func (*MemoryJobCache) Persist

func (c *MemoryJobCache) Persist() error

func (*MemoryJobCache) PersistEvery

func (c *MemoryJobCache) PersistEvery(persistWaitTime time.Duration)

func (*MemoryJobCache) Set

func (c *MemoryJobCache) Set(j *Job) error

func (*MemoryJobCache) Start

func (c *MemoryJobCache) Start(persistWaitTime time.Duration)

type Metadata

type Metadata struct {
	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"`
}

type MockDB

type MockDB struct{}

func (*MockDB) Close

func (m *MockDB) Close() error

func (*MockDB) Delete

func (m *MockDB) Delete(id string) error

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
storage

Jump to

Keyboard shortcuts

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