Documentation ¶
Overview ¶
Package jobexec provides mechanism to control permission for distributed job execution by providing context.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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 ExecutorID ¶
type ExecutorID string
ExecutorID is the executor indentifier
const EmptyExecutorID ExecutorID = ExecutorID("")
EmptyExecutorID is empty ExecutorID
func (*ExecutorID) Scan ¶
func (id *ExecutorID) Scan(src interface{}) error
Scan implements the sql.Scanner 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 ¶
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 ¶
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.