worker

package
v0.0.0-...-7df7d9a Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package worker contains all the logic or workers to execute queries to a DB It makes queries to a DB and returns how long it took to perform the operation The jobs are assigned deterministic based on the query (Hostname)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job struct {
	parameters.QueryParams
	// contains filtered or unexported fields
}

Job holds the information needed to execute a query. The query read from the file and the DB connection

func (Job) Execute

func (j Job) Execute() (time.Duration, error)

Execute makes the query to the DB with the job params. Returns the Duration taken

func (Job) GetWorkerID

func (j Job) GetWorkerID(numberWorkers int) uint

GetWorkerID generates a number [0, numberWorkers-1] based on the host name the same hostname always gives the same worker (if the number of workers is the same)

type Pool

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

Pool contains a pool of worker goroutines that execute the jobs.

func CreatePool

func CreatePool(size int, expectedResults int, db *sql.DB) Pool

CreatePool creates a pool of workers of the given size and also the channels needed We need to pass the expected amount of results, so we can simplify the code as we will reserve a channel of the size of the results, hence we won't have a dead lock

func (*Pool) Queue

func (p *Pool) Queue(job Job)

Queue gets a job and puts it in a queue to be processed

func (Pool) WaitUntilDone

func (p Pool) WaitUntilDone() []time.Duration

WaitUntilDone blocks and waits until all jobs have been executed and returns a slice of Duration of all the successful results This method closes the input channels, so the worker goroutines will die when done.

type Result

type Result struct {
	OK       bool
	Duration time.Duration
}

Result of the execution of a job

Jump to

Keyboard shortcuts

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