job

package
v0.0.0-...-f1c0aba Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2015 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AllJobs = &JobCache{
		Jobs:   make(map[string]*Job),
		rwLock: sync.Mutex{},
	}
)
View Source
var (
	SaveAllJobsWaitTime = 5 * time.Second
)

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 GetAllJobs

func GetAllJobs() ([]*Job, error)

func GetJob

func GetJob(id string) (*Job, error)

func (*Job) Delete

func (j *Job) Delete()

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() error

Init fills in the protected fields and parses the iso8601 notation.

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

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

func (j *Job) Save() error

func (*Job) StartWaiting

func (j *Job) StartWaiting()

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

type JobCache

type JobCache struct {
	Jobs map[string]*Job
	// contains filtered or unexported fields
}

func (*JobCache) Delete

func (c *JobCache) Delete(id string)

func (*JobCache) Get

func (c *JobCache) Get(id string) *Job

func (*JobCache) GetAll

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

func (*JobCache) Persist

func (c *JobCache) Persist() error

func (*JobCache) PersistEvery

func (c *JobCache) PersistEvery(waitTime time.Duration)

func (*JobCache) Set

func (c *JobCache) Set(j *Job)

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() *KalaStats

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

Jump to

Keyboard shortcuts

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