Documentation
¶
Index ¶
- Constants
- type BulkEnqueueResult
- type Client
- type ClientFactory
- type Config
- type FaktoryLogger
- func (l *FaktoryLogger) Debug(v ...interface{})
- func (l *FaktoryLogger) Debugf(format string, args ...interface{})
- func (l *FaktoryLogger) Error(v ...interface{})
- func (l *FaktoryLogger) Errorf(format string, args ...interface{})
- func (l *FaktoryLogger) Fatal(v ...interface{})
- func (l *FaktoryLogger) Fatalf(format string, args ...interface{})
- func (l *FaktoryLogger) Info(v ...interface{})
- func (l *FaktoryLogger) Infof(format string, args ...interface{})
- func (l *FaktoryLogger) Warn(v ...interface{})
- func (l *FaktoryLogger) Warnf(format string, args ...interface{})
- type Faktotum
- func (f *Faktotum) BulkEnqueue(_ context.Context, jobs []*faktory.Job) []BulkEnqueueResult
- func (f *Faktotum) EnqueueJob(_ context.Context, job *faktory.Job) error
- func (f *Faktotum) GetGlobalHooks() map[string]Hook
- func (f *Faktotum) GetJobTypeHooks(jobType string) map[string]Hook
- func (f *Faktotum) ID() string
- func (f *Faktotum) Init() error
- func (f *Faktotum) RegisterGlobalHook(name string, hook Hook) error
- func (f *Faktotum) RegisterJob(jobType string, handler worker.Perform)
- func (f *Faktotum) RegisterJobHook(jobType, name string, hook Hook) error
- func (f *Faktotum) Scheduler() *Scheduler
- func (f *Faktotum) Start(ctx context.Context) error
- func (f *Faktotum) Stop(_ context.Context) error
- func (f *Faktotum) UnregisterGlobalHook(name string) error
- func (f *Faktotum) UnregisterJobHook(jobType string, name string) error
- func (f *Faktotum) WrapWithHooks(jobType string, handler worker.Perform) worker.Perform
- func (f *Faktotum) WrapWithPanicRecovery(jobType string, handler worker.Perform) worker.Perform
- type Hook
- type HookRegistry
- func (r *HookRegistry) GetGlobalHooks() map[string]Hook
- func (r *HookRegistry) GetHooks(jobType string) []Hook
- func (r *HookRegistry) GetJobTypeHooks(jobType string) map[string]Hook
- func (r *HookRegistry) RegisterGlobalHook(name string, hook Hook) error
- func (r *HookRegistry) RegisterJobHook(jobType string, name string, hook Hook) error
- func (r *HookRegistry) UnregisterGlobalHook(name string) error
- func (r *HookRegistry) UnregisterJobHook(jobType string, name string) error
- type Job
- type JobBuilder
- func (b *JobBuilder) Backtrace(lines int) *JobBuilder
- func (b *JobBuilder) Build() *faktory.Job
- func (b *JobBuilder) Custom(data map[string]interface{}) *JobBuilder
- func (b *JobBuilder) Queue(queue string) *JobBuilder
- func (b *JobBuilder) ReserveFor(duration time.Duration) *JobBuilder
- func (b *JobBuilder) Retry(count int) *JobBuilder
- func (b *JobBuilder) Schedule(at time.Time) *JobBuilder
- type LoggingHook
- type MetricsHook
- type NilPayloadError
- type Option
- type PanicError
- type ScheduleOptions
- type Scheduler
- func (s *Scheduler) ID() string
- func (s *Scheduler) Init() error
- func (s *Scheduler) ListJobs() []string
- func (s *Scheduler) Schedule(opts ScheduleOptions) error
- func (s *Scheduler) ScheduleDaily(name string, job *faktory.Job, interval uint, atTimes gocron.AtTimes, ...) error
- func (s *Scheduler) ScheduleEvery(name string, job *faktory.Job, duration time.Duration, ...) error
- func (s *Scheduler) ScheduleMonthly(name string, job *faktory.Job, interval uint, ...) error
- func (s *Scheduler) ScheduleWeekly(name string, job *faktory.Job, interval uint, daysOfTheWeek gocron.Weekdays, ...) error
- func (s *Scheduler) Start(ctx context.Context) error
- func (s *Scheduler) Stop(_ context.Context) error
- func (s *Scheduler) Unschedule(name string) error
- type SchedulerConfig
- type TypedHandler
Constants ¶
const ( AttrJobID = "job_id" AttrJobType = "job_type" AttrError = "error" AttrQueueName = "queue" AttrRetryCount = "retry_count" )
Common attribute keys for consistency
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BulkEnqueueResult ¶
BulkEnqueueResult represents the result of a bulk enqueue operation
type Client ¶
type Client interface {
// Push enqueues a job
Push(job *faktory.Job) error
// Close closes the client
Close()
// Cleanup cleans up the client
Cleanup()
}
Client defines the interface for job operations. It is a wrapper around the Faktory client, so that we can mock it later.
type ClientFactory ¶
ClientFactory defines a function that creates a new Client and a cleanup function
type Config ¶
type Config struct {
// Logger is the logger to use
Logger *slog.Logger
// WorkerCount is the number of concurrent workers
WorkerCount int
// Queues are the queues to process, in order of precedence
Queues []string
// QueueWeights maps queue names to their weights (optional). If provided, the worker will process queues in weighted order.
// If not provided, the worker will process queues in strict order.
QueueWeights map[string]int
// Labels to attach to this worker pool
Labels []string
// ShutdownTimeout is how long to wait for jobs to finish during shutdown
ShutdownTimeout time.Duration
}
Config holds configuration for the Faktory worker module
type FaktoryLogger ¶
type FaktoryLogger struct {
// contains filtered or unexported fields
}
FaktoryLogger is a logger that implements the Logger interface from the faktory_worker package. It wraps the slog.Logger type from the slog package.
func NewFaktoryLogger ¶
func NewFaktoryLogger(logger *slog.Logger) *FaktoryLogger
NewFaktoryLogger creates a new FaktoryLogger.
func (*FaktoryLogger) Debug ¶
func (l *FaktoryLogger) Debug(v ...interface{})
Debug logs a message at the debug level.
func (*FaktoryLogger) Debugf ¶
func (l *FaktoryLogger) Debugf(format string, args ...interface{})
Debugf logs a message at the debug level with a format string.
func (*FaktoryLogger) Error ¶
func (l *FaktoryLogger) Error(v ...interface{})
Error logs a message at the error level.
func (*FaktoryLogger) Errorf ¶
func (l *FaktoryLogger) Errorf(format string, args ...interface{})
Errorf logs a message at the error level with a format string.
func (*FaktoryLogger) Fatal ¶
func (l *FaktoryLogger) Fatal(v ...interface{})
Fatal logs a message at the fatal level and exits the program.
func (*FaktoryLogger) Fatalf ¶
func (l *FaktoryLogger) Fatalf(format string, args ...interface{})
Fatalf logs a message at the fatal level with a format string and exits the program.
func (*FaktoryLogger) Info ¶
func (l *FaktoryLogger) Info(v ...interface{})
Info logs a message at the info level.
func (*FaktoryLogger) Infof ¶
func (l *FaktoryLogger) Infof(format string, args ...interface{})
Infof logs a message at the info level with a format string.
func (*FaktoryLogger) Warn ¶
func (l *FaktoryLogger) Warn(v ...interface{})
Warn logs a message at the warn level.
func (*FaktoryLogger) Warnf ¶
func (l *FaktoryLogger) Warnf(format string, args ...interface{})
Warnf logs a message at the warn level with a format string.
type Faktotum ¶
type Faktotum struct {
// contains filtered or unexported fields
}
Faktotum implements the Module interfaces for Faktory worker integration
func (*Faktotum) BulkEnqueue ¶
BulkEnqueue enqueues multiple jobs in parallel
func (*Faktotum) EnqueueJob ¶
EnqueueJob pushes a job to Faktory
func (*Faktotum) GetGlobalHooks ¶
GetGlobalHooks returns all global hooks
func (*Faktotum) GetJobTypeHooks ¶
GetJobTypeHooks returns all hooks for a specific job type
func (*Faktotum) RegisterGlobalHook ¶
RegisterGlobalHook adds a new hook
func (*Faktotum) RegisterJob ¶
RegisterJob registers a job handler with hooks and panic recovery
func (*Faktotum) RegisterJobHook ¶
RegisterJobHook adds a new hook for a specific job type
func (*Faktotum) Scheduler ¶ added in v0.0.2
Scheduler returns the scheduler, if one is configured. If no scheduler is configured, this will return nil.
This method is safe for concurrent access.
The scheduler is not started automatically. It must be started by the caller and added via the WithScheduler option.
If no scheduler is configured, this will return nil. The caller should check for nil before using the scheduler.
Example:
if s := m.Scheduler(); s != nil {
s.ScheduleDaily("my-job", "0 0 * * *", myJobHandler)
}
func (*Faktotum) UnregisterGlobalHook ¶
UnregisterGlobalHook removes a global hook
func (*Faktotum) UnregisterJobHook ¶
UnregisterJobHook removes a job-specific hook
func (*Faktotum) WrapWithHooks ¶
WrapWithHooks wraps a job handler with hook processing and logging
type Hook ¶
type Hook interface {
BeforeJob(ctx context.Context, job *faktory.Job) error
AfterJob(ctx context.Context, job *faktory.Job, err error)
}
Hook defines the interface for job processing hooks
type HookRegistry ¶
type HookRegistry struct {
// contains filtered or unexported fields
}
HookRegistry manages both global and job-specific hooks
func NewHookRegistry ¶
func NewHookRegistry() *HookRegistry
NewHookRegistry creates a new hook registry
func (*HookRegistry) GetGlobalHooks ¶
func (r *HookRegistry) GetGlobalHooks() map[string]Hook
GetGlobalHooks returns a copy of the global hooks map
func (*HookRegistry) GetHooks ¶
func (r *HookRegistry) GetHooks(jobType string) []Hook
GetHooks returns all hooks that should run for a job
func (*HookRegistry) GetJobTypeHooks ¶
func (r *HookRegistry) GetJobTypeHooks(jobType string) map[string]Hook
GetJobTypeHooks returns a copy of the hooks map for a specific job type
func (*HookRegistry) RegisterGlobalHook ¶
func (r *HookRegistry) RegisterGlobalHook(name string, hook Hook) error
RegisterGlobalHook adds a hook that runs for all jobs
func (*HookRegistry) RegisterJobHook ¶
func (r *HookRegistry) RegisterJobHook(jobType string, name string, hook Hook) error
RegisterJobHook adds a hook for a specific job type
func (*HookRegistry) UnregisterGlobalHook ¶
func (r *HookRegistry) UnregisterGlobalHook(name string) error
UnregisterGlobalHook removes a global hook by name
func (*HookRegistry) UnregisterJobHook ¶
func (r *HookRegistry) UnregisterJobHook(jobType string, name string) error
UnregisterJobHook removes a job-specific hook
type JobBuilder ¶
type JobBuilder struct {
// contains filtered or unexported fields
}
JobBuilder provides a fluent interface for building Faktory jobs
func NewJob ¶
func NewJob(jobType string, args ...interface{}) *JobBuilder
NewJob creates a new JobBuilder with the given job type and arguments
func (*JobBuilder) Backtrace ¶
func (b *JobBuilder) Backtrace(lines int) *JobBuilder
Backtrace sets the number of backtrace lines to retain on errors
func (*JobBuilder) Build ¶
func (b *JobBuilder) Build() *faktory.Job
Build returns the configured Faktory job
func (*JobBuilder) Custom ¶
func (b *JobBuilder) Custom(data map[string]interface{}) *JobBuilder
Custom sets custom metadata for the job
func (*JobBuilder) Queue ¶
func (b *JobBuilder) Queue(queue string) *JobBuilder
Queue sets the job queue
func (*JobBuilder) ReserveFor ¶
func (b *JobBuilder) ReserveFor(duration time.Duration) *JobBuilder
ReserveFor sets how long the job should be reserved for (in seconds)
func (*JobBuilder) Retry ¶
func (b *JobBuilder) Retry(count int) *JobBuilder
Retry sets the number of times to retry the job Use 0 for no retries, -1 for infinite retries
func (*JobBuilder) Schedule ¶
func (b *JobBuilder) Schedule(at time.Time) *JobBuilder
Schedule sets when the job should be executed
type LoggingHook ¶
type LoggingHook struct {
// contains filtered or unexported fields
}
LoggingHook implements Hook to provide logging of job execution
func NewLoggingHook ¶
func NewLoggingHook(logger *log.Logger) *LoggingHook
type MetricsHook ¶
type MetricsHook struct {
// contains filtered or unexported fields
}
MetricsHook implements Hook to collect metrics about job execution
type NilPayloadError ¶
type NilPayloadError struct{}
NilPayloadError represents an error when a nil payload is received
func (*NilPayloadError) Error ¶
func (e *NilPayloadError) Error() string
type Option ¶
type Option func(module *Faktotum)
Option represents a functional option for configuring the Faktotum
func WithClientFactory ¶
func WithClientFactory(factory ClientFactory) Option
WithClientFactory allows injection of a custom client creation function
func WithScheduler ¶ added in v0.0.2
func WithScheduler(config SchedulerConfig) Option
WithScheduler adds a scheduler to the Faktotum
type PanicError ¶
PanicError is returned when a panic occurs during job execution
func (*PanicError) Error ¶
func (e *PanicError) Error() string
type ScheduleOptions ¶
type ScheduleOptions struct {
Name string
Job *faktory.Job
Schedule string // Cron expression
WithSeconds bool // Whether the cron expression includes seconds
JobOptions []gocron.JobOption
}
ScheduleOptions holds options for scheduling a job
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler manages periodic job scheduling for Faktotum
func NewScheduler ¶
func NewScheduler(f *Faktotum, cfg *SchedulerConfig) (*Scheduler, error)
NewScheduler creates a new Scheduler
func (*Scheduler) Init ¶
Init initializes the scheduler. This implements the module interface for hop. It's a no-op for the scheduler.
func (*Scheduler) ListJobs ¶
ListJobs returns all scheduled job names, validating against the scheduler
func (*Scheduler) Schedule ¶
func (s *Scheduler) Schedule(opts ScheduleOptions) error
Schedule schedules a job using a cron expression
func (*Scheduler) ScheduleDaily ¶
func (s *Scheduler) ScheduleDaily(name string, job *faktory.Job, interval uint, atTimes gocron.AtTimes, options ...gocron.JobOption) error
ScheduleDaily schedules a job to run daily at specific times
func (*Scheduler) ScheduleEvery ¶
func (s *Scheduler) ScheduleEvery(name string, job *faktory.Job, duration time.Duration, options ...gocron.JobOption) error
ScheduleEvery schedules a job to run at a fixed duration
func (*Scheduler) ScheduleMonthly ¶
func (s *Scheduler) ScheduleMonthly(name string, job *faktory.Job, interval uint, daysOfTheMonth gocron.DaysOfTheMonth, atTimes gocron.AtTimes, options ...gocron.JobOption) error
ScheduleMonthly schedules a job to run monthly on specific days and times
func (*Scheduler) ScheduleWeekly ¶
func (s *Scheduler) ScheduleWeekly(name string, job *faktory.Job, interval uint, daysOfTheWeek gocron.Weekdays, atTimes gocron.AtTimes, options ...gocron.JobOption) error
ScheduleWeekly schedules a job to run weekly on specific days and times
func (*Scheduler) Unschedule ¶
type SchedulerConfig ¶
SchedulerConfig holds configuration for the scheduler
func DefaultSchedulerConfig ¶
func DefaultSchedulerConfig() *SchedulerConfig
DefaultSchedulerConfig returns the default scheduler configuration
type TypedHandler ¶
type TypedHandler[T any] struct { // contains filtered or unexported fields }
TypedHandler helps create type-safe job handlers
func NewTypedHandler ¶
func NewTypedHandler[T any](handler func(context.Context, T) error) *TypedHandler[T]
NewTypedHandler creates a new typed handler