Documentation ¶
Index ¶
- Constants
- Variables
- type Handler
- type Helper
- type LifecycleEventHandler
- type Logger
- type Manager
- func (mgr *Manager) On(event lifecycleEventType, fn LifecycleEventHandler)
- func (mgr *Manager) ProcessStrictPriorityQueues(queues ...string)
- func (mgr *Manager) ProcessWeightedPriorityQueues(queues map[string]int)
- func (mgr *Manager) Quiet()
- func (mgr *Manager) Register(name string, fn Perform)
- func (mgr *Manager) Run()
- func (mgr *Manager) Terminate(reallydie bool)
- func (mgr *Manager) Use(middleware ...MiddlewareFunc)
- type MiddlewareFunc
- type NoHandlerError
- type Perform
- type PerformExecutor
- type StdLogger
- func (l *StdLogger) Debug(v ...interface{})
- func (l *StdLogger) Debugf(format string, v ...interface{})
- func (l *StdLogger) Error(v ...interface{})
- func (l *StdLogger) Errorf(format string, v ...interface{})
- func (l *StdLogger) Info(v ...interface{})
- func (l *StdLogger) Infof(format string, v ...interface{})
- func (l *StdLogger) Warn(v ...interface{})
- func (l *StdLogger) Warnf(format string, v ...interface{})
Constants ¶
const ( Startup lifecycleEventType = 1 Quiet lifecycleEventType = 2 Shutdown lifecycleEventType = 3 )
const (
Version = "1.5.0"
)
Variables ¶
var ( SIGTERM os.Signal = syscall.SIGTERM SIGTSTP os.Signal = syscall.SIGTSTP SIGTTIN os.Signal = syscall.SIGTTIN SIGINT os.Signal = os.Interrupt )
var (
NoAssociatedBatchError = fmt.Errorf("No batch associated with this job")
)
Functions ¶
This section is empty.
Types ¶
type Helper ¶
type Helper interface { Jid() string JobType() string // Faktory Enterprise: // the BID of the Batch associated with this job Bid() string // Faktory Enterprise: // open the batch associated with this job so we can add more jobs to it. // // func myJob(ctx context.Context, args ...interface{}) error { // helper := worker.HelperFor(ctx) // helper.Batch(func(b *faktory.Batch) error { // return b.Push(faktory.NewJob("sometype", 1, 2, 3)) // }) Batch(func(*faktory.Batch) error) error // allows direct access to the Faktory server from the job With(func(*faktory.Client) error) error // Faktory Enterprise: // this method integrates with Faktory Enterprise's Job Tracking feature. // `reserveUntil` is optional, only needed for long jobs which have more dynamic // lifetimes. // // helper.TrackProgress(10, "Updating code...", nil) // helper.TrackProgress(20, "Cleaning caches...", &time.Now().Add(1 * time.Hour))) // TrackProgress(percent int, desc string, reserveUntil *time.Time) error }
The Helper provides access to valuable data and APIs within an executing job.
We're pretty strict about what's exposed in the Helper because execution should be orthogonal to most of the Job payload contents.
func myJob(ctx context.Context, args ...interface{}) error { helper := worker.HelperFor(ctx) jid := helper.Jid() helper.With(func(cl *faktory.Client) error { cl.Push("anotherJob", 4, "arg") })
type LifecycleEventHandler ¶
type Logger ¶
type Logger interface { Debug(v ...interface{}) Debugf(format string, args ...interface{}) Info(v ...interface{}) Infof(format string, args ...interface{}) Warn(v ...interface{}) Warnf(format string, args ...interface{}) Error(v ...interface{}) Errorf(format string, args ...interface{}) Fatal(v ...interface{}) Fatalf(format string, args ...interface{}) }
func NewStdLogger ¶
func NewStdLogger() Logger
type Manager ¶
type Manager struct { Concurrency int Logger Logger ProcessWID string Labels []string Pool *faktory.Pool // contains filtered or unexported fields }
Manager coordinates the processes for the worker. It is responsible for starting and stopping goroutines to perform work at the desired concurrency level
func (*Manager) On ¶
func (mgr *Manager) On(event lifecycleEventType, fn LifecycleEventHandler)
Register a callback to be fired when a process lifecycle event occurs. These are useful for hooking into process startup or shutdown.
func (*Manager) ProcessStrictPriorityQueues ¶
One of the Process*Queues methods should be called once before Run()
func (*Manager) ProcessWeightedPriorityQueues ¶
func (*Manager) Quiet ¶
func (mgr *Manager) Quiet()
After calling Quiet(), no more jobs will be pulled from Faktory by this process.
func (*Manager) Register ¶
Register a handler for the given jobtype. It is expected that all jobtypes are registered upon process startup.
mgr.Register("ImportantJob", ImportantFunc)
func (*Manager) Run ¶
func (mgr *Manager) Run()
Run starts processing jobs. This method does not return.
func (*Manager) Terminate ¶
Terminate signals that the various components should shutdown. Blocks on the shutdownWaiter until all components have finished.
func (*Manager) Use ¶
func (mgr *Manager) Use(middleware ...MiddlewareFunc)
Use(...) adds middleware to the chain.
type MiddlewareFunc ¶
type NoHandlerError ¶
type NoHandlerError struct {
JobType string
}
func (*NoHandlerError) Error ¶
func (s *NoHandlerError) Error() string
type PerformExecutor ¶
func NewTestExecutor ¶
func NewTestExecutor(p *faktory.Pool) PerformExecutor