gjp

package module
v0.0.0-...-b1d6c03 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2016 License: MIT Imports: 7 Imported by: 0

README

GJP

Go job pool is an easy to use library willing to help users implement a performant a minimal job pool.

Through its simple JobRunner interface containing 4 methods :

type JobRunner interface {
	ExecuteJob(job *Job) (*JobError) //Job error has to be set if the job errored
	NotifyStart(job *Job)
	NotifyEnd(job *Job)
	GetProgress(id string) (percentage float64, err error)
}

All you will need is to initiate the JobPool, start and queue jobs. Regarding the priority, it's your implementation of each queues, and each job that will set it up.

Example

  //create job pool with three queues
	jobPool := gjp.New(3)
	//start it
	jobPool.Start()
	//----------------------------------------------------v Queue number
	//------------------------------------v Job name      v
	//-----------------------v  Job ID    v               v 
	j := jobPool.QueueJob(newJob.Id, newJob.Name, newJob, 0)  

Job API

func (j *Job) HasJobErrored() (errored bool) {}

func (j *Job) GetJobError() (errorString string) {}

func (j *Job) GetJobStatus() (jobStatus string) {}

func (j *Job) GetJobInfos() (jobjson []byte, err error) {}

func (j *Job) GetJobId() (jobId string) {}

func (j *Job) GetJobName() (jobName string) {}

Job Error API

func NewJobError(err error, desc string) (jobError *JobError) {}

func (je *JobError) FmtError() (errorString string) {}

Job pool API

func New(poolRange int) (jp *JobPool) {}

func GenerateJobUID() (id string) {}

func (jp *JobPool) Start() {}

func (jp *JobPool) QueueJob(id string, jobName string, jobRunner JobRunner, poolNumber int) (job *Job) {}

func (jp *JobPool) ProcessJobs() {}

func (jp *JobPool) ListenForShutdown() {}

func (jp *JobPool) ShutdownWorkPool() {}

func (jp *JobPool) GetJobFromJobId(jobId string) (j *Job, err error) {}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateJobUID

func GenerateJobUID() (id string)

generate uuid

Types

type Job

type Job struct {
	JobRunner `json:"-"` //skip the field for json
	Id        string     `json:"id"`
	Name      string     `json:"name"`   //Public property retrievable
	Status    string     `json:"status"` //Status of the current job
	Error     *JobError  `json:"-"`
	Start     time.Time  `json:"start"`
	End       time.Time  `json:"end"`
}

Job

func (*Job) GetJobError

func (j *Job) GetJobError() (errorString string)

create an error well formated

func (*Job) GetJobId

func (j *Job) GetJobId() (jobId string)

func (*Job) GetJobInfos

func (j *Job) GetJobInfos() (jobjson []byte, err error)

func (*Job) GetJobName

func (j *Job) GetJobName() (jobName string)

func (*Job) GetJobStatus

func (j *Job) GetJobStatus() (jobStatus string)

func (*Job) HasJobErrored

func (j *Job) HasJobErrored() (errored bool)

type JobError

type JobError struct {
	ErrorString string //error as a string
	// contains filtered or unexported fields
}

Error handling structure

func NewJobError

func NewJobError(err error, desc string) (jobError *JobError)

func (*JobError) FmtError

func (je *JobError) FmtError() (errorString string)

create an error well formated

type JobPool

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

JobPool principal s²tructure maintaining queues of jobs from a priority range

func New

func New(poolRange int) (jp *JobPool)

Initialization function

func (*JobPool) GetJobFromJobId

func (jp *JobPool) GetJobFromJobId(jobId string) (j *Job, err error)

func (*JobPool) ListWaitingJobs

func (jp *JobPool) ListWaitingJobs() (jobList string)

List current waiting jobs in each queues

func (*JobPool) ListenForShutdown

func (jp *JobPool) ListenForShutdown()

Stop the jobPool and release all memory allowed NYI

func (*JobPool) ProcessJobs

func (jp *JobPool) ProcessJobs()

Loop for processing jobs Started at the creation of the pool

func (*JobPool) QueueJob

func (jp *JobPool) QueueJob(id string, jobName string, jobRunner JobRunner, poolNumber int) (job *Job)

Queue new job to currentJobPool taking on

func (*JobPool) ShutdownWorkPool

func (jp *JobPool) ShutdownWorkPool()

func (*JobPool) Start

func (jp *JobPool) Start()

Start jobPool

type JobQueue

type JobQueue struct {
	Jobs *list.List `json:"jobsWaiting"` //list of waiting jobs
	// contains filtered or unexported fields
}

JobQueue is structure to control jobs queues

func (*JobQueue) GetJobFromJobId

func (jq *JobQueue) GetJobFromJobId(jobId string) (j *Job, err error)

func (*JobQueue) GetJobsWaiting

func (jq *JobQueue) GetJobsWaiting() (jobList string)

type JobRunner

type JobRunner interface {
	ExecuteJob(job *Job) *JobError
	NotifyStart(job *Job)
	NotifyEnd(job *Job)
	GetProgress(id string) (percentage float64, err error)
}

Jump to

Keyboard shortcuts

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