job

package
Version: v0.0.0-...-db26c95 Latest Latest
Warning

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

Go to latest
Published: May 26, 2018 License: MIT Imports: 17 Imported by: 22

Documentation

Index

Constants

View Source
const (
	MaxExecs        = 10 // max number of jobs allowed in the chain
	MaxRetries      = 5
	MaxRetryBackoff = 120 //! 2 minutes
	DefaultMaxTTL   = time.Minute * 10
	DefaultRetries  = 0
	DefaultPriority = NORMAL
)
View Source
const (
	BOOST  = 4
	HIGH   = 3
	MEDIUM = 2
	LOW    = 1
	NORMAL = 0 //! default
)

! priorities

View Source
const (
	CANCELLED   = "CANCELLED"  // cancelled by sender
	QUEUED      = "QUEUED"     // job added to job queue
	TIMEOUT     = "TIMEOUT"    // job timed out
	RUNNING     = "RUNNING"    //job being executed
	FINISHED    = "FINISHED"   //job done
	RETRYING    = "RETRYING"   //job retrying
	DISPATHCHED = "DISPATCHED" //job dispatched to worker
	STARTED     = "STARTED"    //job received by dispatcher (prior to dispatch)
)

! statuses

Variables

View Source
var (
	ErrExecNotFound           = errors.New("Exec Not Found")
	ErrInvalidPriority        = errors.New("Invalid priority number")
	ErrRetriesOutsideLimit    = errors.New("Retries outside limit")
	ErrRetryDelayOutsideLimit = errors.New("Retry Delay outside limit")
	ErrExecutionTimeBehind    = errors.New("Execution time is past")
	ErrJobsLenRange           = errors.New("Number of jobs is more than allowed")
)
View Source
var (
	ErrUnverifiedSignature = errors.New("signature not verified")
	ErrUnableToConvert     = errors.New("Unable to convert to string")
)

Functions

This section is empty.

Types

type EnvironmentVariable

type EnvironmentVariable struct {
	Key   string
	Value string
}

EnvironmentVariables stores key and value of env variables

func NewEnv

func NewEnv(key, value string) *EnvironmentVariable

func (EnvironmentVariable) GetKey

func (env EnvironmentVariable) GetKey() string

func (EnvironmentVariable) GetValue

func (env EnvironmentVariable) GetValue() string

type EnvironmentVariables

type EnvironmentVariables []EnvironmentVariable

func DeserializeEnvs

func DeserializeEnvs(b []byte) (EnvironmentVariables, error)

func NewEnvVariables

func NewEnvVariables(variables ...EnvironmentVariable) EnvironmentVariables

func (EnvironmentVariables) Serialize

func (e EnvironmentVariables) Serialize() []byte

type Exec

type Exec struct {
	Hash          []byte
	Timestamp     int64
	Duration      time.Duration //saved in nanoseconds
	Args          []interface{} // parameters
	Err           interface{}
	Priority      int
	Result        interface{}
	Status        string        //job status
	Retries       int           // number of max retries
	RetriesCount  int           //number of retries
	Backoff       time.Duration //backoff time of retries (seconds)
	ExecutionTime int64         // time scheduled to run (unix) - should sleep # of seconds before adding to job queue
	Interval      int           //periodic job exec (seconds)
	By            string        //! ID of the worker node that ran this
	TTL           time.Duration //! time limit of job running
	Pub           string        //! public key for private jobs
	Envs          []byte
	// contains filtered or unexported fields
}

TODO: add environment variables

func DeserializeExec

func DeserializeExec(b []byte) Exec

func NewExec

func NewExec(args []interface{}, retries, priority int, backoff time.Duration, execTime int64, interval int, ttl time.Duration, pub string, envs EnvironmentVariables, passphrase string) (*Exec, error)

func UniqExec

func UniqExec(execs []Exec) []Exec

UniqExec returns unique values of parameter

func (*Exec) Cancel

func (e *Exec) Cancel()

func (Exec) GetArgs

func (e Exec) GetArgs() []interface{}

func (Exec) GetBackoff

func (e Exec) GetBackoff() time.Duration

func (Exec) GetBy

func (e Exec) GetBy() string

func (Exec) GetCancelChan

func (e Exec) GetCancelChan() chan struct{}

func (Exec) GetDuration

func (e Exec) GetDuration() time.Duration

func (Exec) GetEnvs

func (e Exec) GetEnvs(passphrase string) (EnvironmentVariables, error)

func (Exec) GetEnvsMap

func (e Exec) GetEnvsMap(passphrase string) (map[string]interface{}, error)

returns environment variables as a map

func (Exec) GetErr

func (e Exec) GetErr() interface{}

func (Exec) GetExecutionTime

func (e Exec) GetExecutionTime() int64

func (Exec) GetHash

func (e Exec) GetHash() []byte

func (Exec) GetInterval

func (e Exec) GetInterval() int

func (Exec) GetPriority

func (e Exec) GetPriority() int

func (Exec) GetResult

func (e Exec) GetResult() interface{}

func (Exec) GetRetries

func (e Exec) GetRetries() int

func (Exec) GetRetriesCount

func (e Exec) GetRetriesCount() int

func (Exec) GetStatus

func (e Exec) GetStatus() string

func (Exec) GetTTL

func (e Exec) GetTTL() time.Duration

func (Exec) GetTimestamp

func (e Exec) GetTimestamp() int64

func (*Exec) IncrRetriesCount

func (e *Exec) IncrRetriesCount()

func (Exec) Serialize

func (e Exec) Serialize() []byte

func (*Exec) SetArgs

func (e *Exec) SetArgs(a []interface{})

func (*Exec) SetBackoff

func (e *Exec) SetBackoff(b time.Duration) error

func (*Exec) SetBy

func (e *Exec) SetBy(by string)

func (*Exec) SetDuration

func (e *Exec) SetDuration(t time.Duration)

func (*Exec) SetErr

func (e *Exec) SetErr(err interface{})

func (*Exec) SetExecutionTime

func (e *Exec) SetExecutionTime(t int64) error

? takes unix time

func (*Exec) SetInterval

func (e *Exec) SetInterval(i int)

func (*Exec) SetPriority

func (e *Exec) SetPriority(p int) error

func (*Exec) SetResult

func (e *Exec) SetResult(r interface{})

func (*Exec) SetRetries

func (e *Exec) SetRetries(r int) error

func (*Exec) SetStatus

func (e *Exec) SetStatus(s string)

func (*Exec) SetTTL

func (e *Exec) SetTTL(ttl time.Duration)

func (*Exec) SetTimestamp

func (e *Exec) SetTimestamp(t int64)

type Job

type Job struct {
	ID             string
	Hash           []byte
	Execs          []Exec
	Name           string
	Task           string
	Signature      [][]byte // signature of owner
	SubmissionTime time.Time
	Private        bool //private job flag (default to false - public)
}

func DeserializeJob

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

func NewJob

func NewJob(task string, name string, priv bool, privKey string) (*Job, error)

func (*Job) AddExec

func (j *Job) AddExec(je Exec)

func (*Job) Execute

func (j *Job) Execute(exec *Exec, passphrase string) *Exec

func (Job) GetExec

func (j Job) GetExec(hash []byte) (*Exec, error)

func (Job) GetExecs

func (j Job) GetExecs() []Exec

func (Job) GetHash

func (j Job) GetHash() []byte

func (Job) GetID

func (j Job) GetID() string

func (Job) GetLatestExec

func (j Job) GetLatestExec() Exec

func (Job) GetName

func (j Job) GetName() string

func (Job) GetPrivate

func (j Job) GetPrivate() bool

func (Job) GetSignature

func (j Job) GetSignature() [][]byte

func (Job) GetSubmissionTime

func (j Job) GetSubmissionTime() time.Time

func (Job) GetTask

func (j Job) GetTask() string

func (Job) IsEmpty

func (j Job) IsEmpty() bool

func (*Job) Serialize

func (j *Job) Serialize() []byte

func (*Job) Sign

func (j *Job) Sign(priv []byte)

func (Job) Verify

func (j Job) Verify() bool

Verify checks if the job has been modified

func (Job) VerifySignature

func (j Job) VerifySignature(pub string) bool

type JobRequestMultiple

type JobRequestMultiple struct {
	ID    string
	Execs []*Exec
}

func DeserializeJRM

func DeserializeJRM(b []byte) (JobRequestMultiple, error)

func NewJobRequestMultiple

func NewJobRequestMultiple(id string, exec ...*Exec) *JobRequestMultiple

func (*JobRequestMultiple) AppendExec

func (jr *JobRequestMultiple) AppendExec(exec *Exec)

func (JobRequestMultiple) GetExec

func (jr JobRequestMultiple) GetExec() []*Exec

func (JobRequestMultiple) GetID

func (jr JobRequestMultiple) GetID() string

func (JobRequestMultiple) Serialize

func (jr JobRequestMultiple) Serialize() []byte

func (*JobRequestMultiple) SetID

func (jr *JobRequestMultiple) SetID(id string)

type JobRequestSingle

type JobRequestSingle struct {
	ID   string
	Exec *Exec
}

func DeserializeJRS

func DeserializeJRS(b []byte) (JobRequestSingle, error)

func NewJobRequestSingle

func NewJobRequestSingle(id string, exec *Exec) *JobRequestSingle

func (JobRequestSingle) GetExec

func (jr JobRequestSingle) GetExec() *Exec

func (JobRequestSingle) GetID

func (jr JobRequestSingle) GetID() string

func (JobRequestSingle) Serialize

func (jr JobRequestSingle) Serialize() []byte

func (*JobRequestSingle) SetID

func (jr *JobRequestSingle) SetID(id string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL