Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Job ¶
type Job struct {
// contains filtered or unexported fields
}
func (*Job) Create ¶
func (j *Job) Create( queue string, handler string, payload string, available time.Time, ) (*JobModel, error)
Create creates a new job in the database
func (*Job) DeleteOlderJobs ¶
DeleteOlderJobs deletes messages that are older than passed date
func (*Job) DispatchFailedJobs ¶
DispatchFailedJobs update failed jobs to re run again by workers
type JobModel ¶
type JobModel struct { ID uuid.UUID `gorm:"primaryKey;type:uuid;"` Queue string `gorm:"index,default:'default'"` Handler string Payload string `gorm:"type:longtext"` Error string `gorm:"type:longtext"` Attempts uint8 `gorm:"default:0"` ReservedAt sql.NullInt64 FailedAt sql.NullInt64 AvailableAt int64 CreatedAt int64 }
type JobProcessor ¶
type JobProcessor struct { DB *gorm.DB // database instance Handler func(job JobModel, workerId uint8) error // Function to process each job Queue string // The queue to process Workers uint8 // Number of concurrent workers // contains filtered or unexported fields }
JobProcessor holds the configuration for processing jobs with a worker pool
func NewJobProcessor ¶
func NewJobProcessor( ctx *context.Context, handler func(job JobModel, workerId uint8) error, queue string, workers uint8, config *Config, ) *JobProcessor
NewJobProcessor creates a new instance of the job processor
func (*JobProcessor) Start ¶
func (p *JobProcessor) Start()
Start the worker pool and begins processing jobs concurrently
func (*JobProcessor) Stop ¶
func (p *JobProcessor) Stop()
Stop stops the job processor by closing the job channel and waiting for all workers to finish
Click to show internal directories.
Click to hide internal directories.