dbworker

package
v0.0.0-...-78bde44 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package dbworker receiver mongodb access request, and processed by one or more worker goroutines. Provide features such as:

monitor db load, by monitor db request queue length
put slow db operation to specific queue, do not put too much pressure on database
better handling database fatal error, such as database shutdown

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(ctx context.Context, work Work) (interface{}, error)

Do queue a db worker.into default DBWorker.

Types

type Work

type Work func(ctx context.Context, db *mongo.Database) (res interface{}, err error)

Work function do the actual database operation.

type Worker

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

Worker maintains a mongodb work queue

func New

func New(workers int, queueLen int) *Worker

New create worker, connect to default bgo configured mongodb.

func NewWithDB

func NewWithDB(db *mongo.Database, workers int, queueLen int) *Worker

NewWithDB create worker with specific database.

func (*Worker) Close

func (w *Worker) Close() error

Close closes queue, wait for current work load complete, close database.

func (*Worker) Do

func (w *Worker) Do(ctx context.Context, work Work) (interface{}, error)

Do put work into queue, wait for its execution and returns result.

Jump to

Keyboard shortcuts

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