jobexec

package module
v0.0.0-...-fed24de Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

README

GoDoc

go-jobexec

jobexec provides mechanism to control permission for distributed job execution by providing context.

Example

var ctx jobexec.Context
// TODO: initialize the ctx

exec := func() error {
    // TODO: do something
    return nil
}

foo := jobexec.ExecutorID("foo")
if err := jobexec.Exec(ctx, foo, exec); err != jobexec.ErrNotPermitted {
    // TODO: handle the error
}

Documentation

Overview

Package jobexec provides mechanism to control permission for distributed job execution by providing context.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNotPermitted = errors.New("jobexec: not permitted")

ErrNotPermitted is error when the acquire is not permitted.

Functions

func Exec

func Exec(ctx Context, executorID ExecutorID, fn func() error) error

Exec a function based on given context.

Example
var ctx jobexec.Context
// TODO: initialize the ctx

exec := func() error {
	// TODO: do something
	return nil
}

foo := jobexec.ExecutorID("foo")
if err := jobexec.Exec(ctx, foo, exec); err != jobexec.ErrNotPermitted {
	// TODO: handle the error
}
Output:

Types

type Context

type Context interface {
	Acquire(ExecutorID) error
}

Context of the job execution.

type ExecutorID

type ExecutorID string

ExecutorID is the executor indentifier

const EmptyExecutorID ExecutorID = ExecutorID("")

EmptyExecutorID is empty ExecutorID

func (ExecutorID) OK

func (id ExecutorID) OK() bool

OK check the validity.

func (*ExecutorID) Scan

func (id *ExecutorID) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (ExecutorID) Value

func (id ExecutorID) Value() (driver.Value, error)

Value implements the driver.Value interface.

type InMemContext

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

InMemContext is the in memory context.

func NewInMemContext

func NewInMemContext(interval time.Duration) (*InMemContext, error)

NewInMemContext constructs new InMemContext.

func NewInMemContextWithClock

func NewInMemContextWithClock(interval time.Duration, clock clockwork.Clock) (*InMemContext, error)

NewInMemContextWithClock constructs new InMemContext with clock.

func (*InMemContext) Acquire

func (c *InMemContext) Acquire(execID ExecutorID) error

Acquire an execution permission.

func (*InMemContext) LastExecutor

func (c *InMemContext) LastExecutor() ExecutorID

LastExecutor permitted to do an execution.

type SQLContext

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

SQLContext is sql based context.

func NewSQLContext

func NewSQLContext(db *sql.DB, name string, interval time.Duration) (*SQLContext, error)

NewSQLContext constructs new SQLContext.

func NewSQLContextWithClock

func NewSQLContextWithClock(db *sql.DB, name string, interval time.Duration, clock clockwork.Clock) (*SQLContext, error)

NewSQLContextWithClock construcrs new SQLContext with clock.

func (*SQLContext) Acquire

func (c *SQLContext) Acquire(execID ExecutorID) error

Acquire an execution permission.

func (*SQLContext) Init

func (c *SQLContext) Init() error

Init will create tracker entries on database if not exists yet.

func (*SQLContext) LastExecutor

func (c *SQLContext) LastExecutor() (ExecutorID, error)

LastExecutor permitted to do an execution.

Directories

Path Synopsis
internal
mysql
Package mysql provide mysql specific implementation of the jobexec.
Package mysql provide mysql specific implementation of the jobexec.

Jump to

Keyboard shortcuts

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