pool

package
v0.0.0-...-eee6e6f Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Impl

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

Impl is the Pool interface implementation

func (*Impl) Add

func (p *Impl) Add(f func(taskID string) error) (taskID string, err error)

Add new workers to pool

*The given function will be queued and called further

func (*Impl) GetInfoChannel

func (p *Impl) GetInfoChannel() chan *WorkerInfo

GetInfoChannel returns the info channel used on pool

*The info channel will receive information about finished
*tasks.
*on shutdown it will receive all tasks which are not
*runned yet

func (*Impl) Server

func (p *Impl) Server()

Server start pool as service

func (*Impl) SetMaxPoolSize

func (p *Impl) SetMaxPoolSize(size int)

SetMaxPoolSize pool max size to a different number

  • It should change the pull size and start more workers
  • if it the new pool size is greater then the previous one
  • and if there is more workers to start.
  • if the new pull size is lower, it should do nothing,
  • because when a current task finish it will check if
  • it should call a new worker or not.

func (*Impl) Shutdown

func (p *Impl) Shutdown()

Shutdown force a shutdown on application, it will wait only for

*the running tasks finish, for a Graceful shutdown take a look into
*which will try to run all tasks on pool which are been queued ShutdownGraceful

type Pool

type Pool interface {
	// Server will be a pool server which will wait until a shootdown as send
	Server()

	// Add worker to pool
	Add(f func(taskID string) error) (id string, err error)

	// SetMaxPoolSize pool max size to a different number
	SetMaxPoolSize(s int)

	// Shutdown start shutdown pool server
	Shutdown()

	GetInfoChannel() chan *WorkerInfo
}

Pool to create a pool

func New

func New(size int) Pool

New Pool Server

type WorkerInfo

type WorkerInfo struct {
	ID            string
	QueuedAt      time.Time
	WaitingTime   time.Duration
	ExecutionTime time.Duration
	FinishedTime  time.Duration
	Err           error
	CalledToRun   bool
}

WorkerInfo return success information

Jump to

Keyboard shortcuts

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