task_runner

package module
v0.0.0-...-3626fda Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2017 License: MIT Imports: 3 Imported by: 3

README

task-runner

As the name suggests, this library provides concurrent task execution.

I recently found an article, explaining a design of Worker Queue implementation in Go.

http://nesv.github.io/golang/2014/02/25/worker-queues-in-go.html

I would suggest going through the article first. Also the article mentions about some videos you can watch, which explain concurrency patterns in Go. I would suggest going through that as well.

I wanted to create a library out of this, so that I can use it everywhere.

For example usage you can go through the /example/examples.go

Basically this TaskRunner provides two interfaces to run Tasks.

Task type is pretty much anything that has a Execute() routine. Tasks have to be structured this way.

The first interface is free is a simple function call interface.

The second is the channel interface.

Some basic tests can be found in the test/ dir as well as the main pkg.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Task

type Task interface {
	Execute()
}

Structure of Task which we will be able to run

type TaskRunner

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

func StartTaskRunner

func StartTaskRunner(no_of_workers int, logger_out io.Writer) *TaskRunner

func (*TaskRunner) CreateBufferedTaskRunner

func (runner *TaskRunner) CreateBufferedTaskRunner(size int) chan Task

func (*TaskRunner) EnqueueTask

func (runner *TaskRunner) EnqueueTask(newTask Task)

func (*TaskRunner) Stop

func (runner *TaskRunner) Stop()

type Worker

type Worker struct {
	ID          int
	TaskQueue   chan Task
	WorkerQueue chan chan Task
	StopSignal  chan bool
	// contains filtered or unexported fields
}

* Worker type. * The task queue is the incoming tasks channel. * The worker queue is the queue of workers it will add itself to. * Stop channel to stop the worker.

func NewWorker

func NewWorker(id int, workerQueue chan chan Task, logr *log.Logger) Worker

func (*Worker) Start

func (w *Worker) Start()

func (*Worker) Stop

func (w *Worker) Stop()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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