lock

package
v0.0.0-...-3461fee Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SQLErrorSessionNotFound = "SL001"
)

SQL errors

Variables

This section is empty.

Functions

This section is empty.

Types

type DBFinder

type DBFinder func() (Database, error)

DBFinder will return an Database implementation This will be called every loop in case the DB moves

type Database

type Database interface {
	StartSession(ctx context.Context) (int64, glitch.DataError)
	EndSession(ctx context.Context, sessionID int64) glitch.DataError
	BumpSession(ctx context.Context, sessionID int64) glitch.DataError
	GetWork(ctx context.Context, sessionID int64, scanTask ScanTask) ([]Task, glitch.DataError)
	FinishTasks(ctx context.Context, taskIDs []string) glitch.DataError
}

Database can make the PG calls necessary to use a session locked runner

type Logger

type Logger interface {
	Printf(format string, a ...interface{})
	Errorf(format string, a ...interface{})
}

Logger allows you to control how logging happens

type Runner

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

Runner will loop and run tasks assigned to it

func NewRunner

func NewRunner(dbFinder DBFinder, scanTask ScanTask, tasker Tasker, loopTick time.Duration, logger Logger, name string, client metrics.Client) *Runner

NewRunner will create a new Runner to handle a type of task dbFinder can get an instance of the Database interface on demand scanTask can read from a sql.row into a Task tasker can complete Tasks looptick defines how often to check for tasks to complete client is a go-metrics-client that will also start spans for us logger is optional and will log errors if provided

func (*Runner) Run

func (r *Runner) Run() error

Run will start looping and processing tasks dont call this more than once.

func (*Runner) Stop

func (r *Runner) Stop() *sync.WaitGroup

Stop stops the runner from looping Stop returns a WaitGroup which you can wait on to ensure all work is finished

type ScanTask

type ScanTask func(row Scanner) (Task, glitch.DataError)

ScanTask can scan the data from Get work and store it in a struct. That struct should be returned and will be added to the GetWork array.

type Scanner

type Scanner interface {
	Scan(dest ...interface{}) error
}

Scanner is an interface for the database/sql Scan function. sql.Rows and sql.Row implement this

type Task

type Task interface {
	GetID() string
}

Task is an interface that can GetID - This is meant to be implemented as a struct that holds all task info that The Tasker needs to do the work associated with the task.

type Tasker

type Tasker func(ctx context.Context, tasks []Task) ([]Task, error)

Tasker can do the work associated with the tasks passed to it. It should return any completed tasks so they can by flaged as "finished"

type Tracer

type Tracer interface {
	StartSpanWithContext(ctx context.Context, name string) (opentracing.Span, context.Context)
}

Tracer can trace the flow of calls via child spans. This is meant to play nice with open tracing

Directories

Path Synopsis
Package lockmock is a generated GoMock package.
Package lockmock is a generated GoMock package.
Package lockmock is a generated GoMock package.
Package lockmock is a generated GoMock package.

Jump to

Keyboard shortcuts

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