pipeline

package
v0.0.0-...-099dad8 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Idle is the status of an idle job
	Idle Status = iota
	// Scheduled is the status of a job that has been scheduled
	Scheduled = iota
	// Active is the status of a job that is currently being processed
	Active = iota
	// Completed is the status of a job that completed successfully
	Completed = iota
	// Failed is the status of a job that completed unsuccessfully
	Failed = iota
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job struct {
	// Name is a human-readable name of the job.
	Name string
	// Description is a human-readable description for the job.
	Description string
	// Tries is the current number of performed tries
	Tries uint

	// MaximumTries is the maximum number of tries before ignoring the job.
	MaximumTries uint
	// Status is the current status of the job.
	Status Status
	// JobCompletedCallback is called with the resulting record whenever a job is completed.
	JobCompletedCallback JobCompletedCallback
	// JobFailedCallback is called with the error whenver a job fails.
	JobFailedCallback JobFailedCallback
	// PerformJobCallback is called whenever the job is performed.
	PerformJobCallback PerformJobCallback
	// contains filtered or unexported fields
}

Job is a job to produce a WARC record.

func NewJob

func NewJob(name string, description string, handler JobHandler) *Job

NewJob creates a new job with default settings.

func (*Job) Complete

func (job *Job) Complete(records ...*warc.Record)

Complete completes the job with the given record.

func (*Job) Fail

func (job *Job) Fail(err error)

Fail fails the job with the given error.

func (*Job) Perform

func (job *Job) Perform()

Perform invokes the job.

type JobCompletedCallback

type JobCompletedCallback func(job *Job, records ...*warc.Record)

JobCompletedCallback is called with the resulting record whenever a job is completed.

type JobFailedCallback

type JobFailedCallback func(job *Job, err error)

JobFailedCallback is called with the error whenver a job fails.

type JobHandler

type JobHandler func(job *Job) ([]*warc.Record, error)

JobHandler is the function invoked to perform the job. May return nil or one or more records.

type PerformJobCallback

type PerformJobCallback func(job *Job)

PerformJobCallback is called whenever the job is performed.

type Pool

type Pool struct {
	Parallelism uint
	Workers     []*Worker
	// contains filtered or unexported fields
}

Pool is a worker pool.

func NewPool

func NewPool(parallelism uint) *Pool

NewPool creates a new pool of the specified number of workers.

func (*Pool) Start

func (pool *Pool) Start()

Start starts the workers of the pool.

func (*Pool) Submit

func (pool *Pool) Submit(job *Job)

Submit submits a job to the pool. Note: will block once the queue buffer (10) is filled. TODO: Investigate if this causes issues in reality.

func (*Pool) Wait

func (pool *Pool) Wait()

Wait waits for all scheduled jobs to complete.

type Status

type Status int

Status is the status of a job.

type Worker

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

Worker is a routine processing jobs as quickly as it can.

func NewWorker

func NewWorker(queue chan chan *Job, syncGroup *sync.WaitGroup) *Worker

NewWorker creates a new worker for the specified job queue.

func (*Worker) Start

func (worker *Worker) Start()

Start starts the worker

Jump to

Keyboard shortcuts

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