job

package
v0.0.0-...-eef6c14 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2018 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

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

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

Gizo Statuses

Variables

View Source
var (
	//ErrExecNotFound occurs when exec not found
	ErrExecNotFound = errors.New("Exec Not Found")
	//ErrInvalidPriority occurs when invalid priority number
	ErrInvalidPriority = errors.New("Invalid priority number")
	//ErrRetriesOutsideLimit occurs when retries outside limit
	ErrRetriesOutsideLimit = errors.New("Retries outside limit")
	//ErrRetryDelayOutsideLimit occurs when retry delay is outside limit
	ErrRetryDelayOutsideLimit = errors.New("Retry Delay outside limit")
	//ErrBackoffOutsideLimit occurs when backoff duration is outside limit
	ErrBackoffOutsideLimit = errors.New("Backoff duration outside limit")
	//ErrExecutionTimeBehind occurs when execution time is past
	ErrExecutionTimeBehind = errors.New("Execution time is past")
	//ErrJobsLenRange occurs when number of jobs is more than allowed
	ErrJobsLenRange = errors.New("Number of jobs is more than allowed")
)
View Source
var (
	//ErrUnverifiedSignature when unauthorized person tries to execute private job
	ErrUnverifiedSignature = errors.New("Signature not verified")
	//ErrUnableToConvert when args is not able to be converted to string
	ErrUnableToConvert = errors.New("Unable to convert to string")
	//ErrUnableToSign unable to sign job
	ErrUnableToSign = errors.New("Unable to sign job")
)

Functions

This section is empty.

Types

type EnvironmentVariable

type EnvironmentVariable struct {
	Key   string
	Value string
}

EnvironmentVariable stores key and value of env variables

func NewEnv

func NewEnv(key, value string) *EnvironmentVariable

NewEnv initializes an environment variable

func (EnvironmentVariable) GetKey

func (env EnvironmentVariable) GetKey() string

GetKey returns key

func (EnvironmentVariable) GetValue

func (env EnvironmentVariable) GetValue() string

GetValue returns value

type EnvironmentVariables

type EnvironmentVariables []EnvironmentVariable

EnvironmentVariables list of environment variables

func NewEnvVariables

func NewEnvVariables(variables ...EnvironmentVariable) EnvironmentVariables

NewEnvVariables initializes environment variables

type Exec

type Exec struct {
	Hash          string
	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        //encrypted environment variables
	// contains filtered or unexported fields
}

Exec - config for job executions

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)

NewExec initializes an exec

func UniqExec

func UniqExec(execs []Exec) []Exec

UniqExec returns unique values of parameter

func (*Exec) Cancel

func (e *Exec) Cancel()

Cancel cancels job

func (Exec) GetArgs

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

GetArgs return args

func (Exec) GetBackoff

func (e Exec) GetBackoff() time.Duration

GetBackoff returns backoff

func (Exec) GetBy

func (e Exec) GetBy() string

GetBy returns by

func (Exec) GetCancelChan

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

GetCancelChan returns cancel channel

func (Exec) GetDuration

func (e Exec) GetDuration() time.Duration

GetDuration returns duration

func (Exec) GetEnvs

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

GetEnvs returns environment variables

func (Exec) GetEnvsMap

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

GetEnvsMap returns environment variables as a map

func (Exec) GetErr

func (e Exec) GetErr() interface{}

GetErr returns err

func (Exec) GetExecutionTime

func (e Exec) GetExecutionTime() int64

GetExecutionTime returne execution time

func (Exec) GetHash

func (e Exec) GetHash() string

GetHash returns hash

func (Exec) GetInterval

func (e Exec) GetInterval() int

GetInterval returns interval

func (Exec) GetPriority

func (e Exec) GetPriority() int

GetPriority returns prioritys

func (Exec) GetResult

func (e Exec) GetResult() interface{}

GetResult returns result

func (Exec) GetRetries

func (e Exec) GetRetries() int

GetRetries return retries

func (Exec) GetRetriesCount

func (e Exec) GetRetriesCount() int

GetRetriesCount return retries count

func (Exec) GetStatus

func (e Exec) GetStatus() string

GetStatus returns status

func (Exec) GetTTL

func (e Exec) GetTTL() time.Duration

GetTTL returns ttl

func (Exec) GetTimestamp

func (e Exec) GetTimestamp() int64

GetTimestamp return timestamp

func (*Exec) IncrRetriesCount

func (e *Exec) IncrRetriesCount()

IncrRetriesCount increments retries count

func (*Exec) SetArgs

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

SetArgs sets args

func (*Exec) SetBackoff

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

SetBackoff sets backoff

func (*Exec) SetBy

func (e *Exec) SetBy(by string)

SetBy sets by

func (*Exec) SetDuration

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

SetDuration sets duration

func (*Exec) SetErr

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

SetErr sets err

func (*Exec) SetExecutionTime

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

SetExecutionTime sets execution time - unix

func (*Exec) SetInterval

func (e *Exec) SetInterval(i int)

SetInterval sets interval

func (*Exec) SetPriority

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

SetPriority sets priority

func (*Exec) SetResult

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

SetResult sets result

func (*Exec) SetRetries

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

SetRetries sets retries

func (*Exec) SetStatus

func (e *Exec) SetStatus(s string)

SetStatus sets status

func (*Exec) SetTTL

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

SetTTL sets ttl

func (*Exec) SetTimestamp

func (e *Exec) SetTimestamp(t int64)

SetTimestamp sets timestamp

type Job

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

Job holds deployed job

func NewJob

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

NewJob initializes a new job

func UniqJob

func UniqJob(jobs []Job) []Job

UniqJob returns unique values of parameter

func (*Job) AddExec

func (j *Job) AddExec(je Exec)

AddExec add exec to job

func (*Job) Execute

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

Execute runs the exec

func (Job) GetExec

func (j Job) GetExec(hash string) (*Exec, error)

GetExec return exec of specified hash

func (Job) GetExecs

func (j Job) GetExecs() []Exec

GetExecs returns exec of job

func (Job) GetHash

func (j Job) GetHash() string

GetHash return job hash

func (Job) GetID

func (j Job) GetID() string

GetID returns job id

func (Job) GetLatestExec

func (j Job) GetLatestExec() Exec

GetLatestExec return latest exec of job

func (Job) GetName

func (j Job) GetName() string

GetName returns name of job

func (Job) GetPrivate

func (j Job) GetPrivate() bool

GetPrivate check if job is private

func (Job) GetSignature

func (j Job) GetSignature() string

GetSignature returns job signature

func (Job) GetSubmissionTime

func (j Job) GetSubmissionTime() int64

GetSubmissionTime returns submission time

func (Job) GetTask

func (j Job) GetTask() (string, error)

GetTask returns task

func (Job) IsEmpty

func (j Job) IsEmpty() (bool, error)

IsEmpty check if job is empty

func (*Job) Sign

func (j *Job) Sign(priv string) error

Sign signature of owner of job

func (Job) Verify

func (j Job) Verify() (bool, error)

Verify checks if the job has been modified

func (Job) VerifySignature

func (j Job) VerifySignature(pub string) (bool, error)

VerifySignature verifies if pub is for the owner

type Request

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

Request requests job execs

func NewRequest

func NewRequest(id string, exec ...*Exec) *Request

NewRequest initializes job request

func (*Request) AppendExec

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

AppendExec adds exec to job request

func (Request) GetExec

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

GetExec returns job execs

func (Request) GetID

func (jr Request) GetID() string

GetID returns job reqiest id

func (*Request) SetID

func (jr *Request) SetID(id string)

SetID sets job id

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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