Documentation ¶
Index ¶
- Constants
- Variables
- func PermanentFailure(err error) error
- type ExecutorFunc
- type GormStore
- func (s *GormStore) AcceptJob(j *Job, acceptedGracePeriod time.Duration) error
- func (s *GormStore) InsertJob(j *Job) error
- func (s *GormStore) Job(id uuid.UUID) (j Job, err error)
- func (s *GormStore) Jobs(o datastore.ListOptions) (jj []Job, err error)
- func (s *GormStore) SchedulableJobs(acceptedGracePeriod, reSchedulableGracePeriod time.Duration, ...) (jj []Job, err error)
- func (s *GormStore) Status() ([]StatusQuery, error)
- func (s *GormStore) UpdateJob(j *Job) error
- type JSONResponse
- type Job
- type JobOption
- type JobQueueStatus
- type NotificationConfig
- type Result
- type Service
- type ServiceImpl
- type State
- type StatusQuery
- type Store
- type WorkerPool
- type WorkerPoolImpl
- func (wp *WorkerPoolImpl) Capacity() uint
- func (wp *WorkerPoolImpl) CreateJob(jobType, txID string, opts ...JobOption) (*Job, error)
- func (wp *WorkerPoolImpl) QueueSize() uint
- func (wp *WorkerPoolImpl) RegisterExecutor(jobType string, executorF ExecutorFunc)
- func (wp *WorkerPoolImpl) Schedule(j *Job) error
- func (wp *WorkerPoolImpl) Start()
- func (wp *WorkerPoolImpl) Status() (WorkerPoolStatus, error)
- func (wp *WorkerPoolImpl) Stop(wait bool)
- type WorkerPoolOption
- func WithAcceptedGracePeriod(d time.Duration) WorkerPoolOption
- func WithDbJobPollInterval(d time.Duration) WorkerPoolOption
- func WithJobStatusWebhook(u string, timeout time.Duration) WorkerPoolOption
- func WithLogger(logger *log.Logger) WorkerPoolOption
- func WithMaxJobErrorCount(count int) WorkerPoolOption
- func WithReSchedulableGracePeriod(d time.Duration) WorkerPoolOption
- func WithSystemService(svc system.Service) WorkerPoolOption
- type WorkerPoolStatus
Constants ¶
View Source
const SendJobStatusJobType = "send_job_status"
Variables ¶
View Source
var ( ErrInvalidJobType = errors.New("invalid job type") ErrPermanentFailure = errors.New("permanent failure") )
Functions ¶
func PermanentFailure ¶ added in v0.8.0
Types ¶
type GormStore ¶
type GormStore struct {
// contains filtered or unexported fields
}
func (*GormStore) SchedulableJobs ¶ added in v0.8.0
func (*GormStore) Status ¶ added in v0.9.0
func (s *GormStore) Status() ([]StatusQuery, error)
type JSONResponse ¶ added in v0.6.0
type JSONResponse struct { ID uuid.UUID `json:"jobId"` Type string `json:"type"` State State `json:"state"` Error string `json:"error"` Errors []string `json:"errors"` Result string `json:"result"` TransactionID string `json:"transactionId"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` }
Job HTTP response
type Job ¶
type Job struct { ID uuid.UUID `gorm:"column:id;primary_key;type:uuid;"` Type string `gorm:"column:type"` State State `gorm:"column:state;default:INIT;index:idx_jobs_state_updated_at"` Error string `gorm:"column:error"` Errors pq.StringArray `gorm:"column:errors;type:text[]"` Result string `gorm:"column:result"` TransactionID string `gorm:"column:transaction_id"` ExecCount int `gorm:"column:exec_count;default:0"` CreatedAt time.Time `gorm:"column:created_at"` UpdatedAt time.Time `gorm:"column:updated_at;index:idx_jobs_state_updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index"` ShouldSendNotification bool `gorm:"-"` // Whether or not to notify admin (via webhook for example) Attributes datatypes.JSON `gorm:"attributes"` }
Job database model
func (Job) ToJSONResponse ¶ added in v0.6.0
func (j Job) ToJSONResponse() JSONResponse
type JobQueueStatus ¶ added in v0.9.0
type NotificationConfig ¶ added in v0.8.0
type NotificationConfig struct {
// contains filtered or unexported fields
}
func (*NotificationConfig) SendJobStatus ¶ added in v0.8.0
func (cfg *NotificationConfig) SendJobStatus(ctx context.Context, content string) error
func (*NotificationConfig) SendJobStatusWebhook ¶ added in v0.8.0
func (cfg *NotificationConfig) SendJobStatusWebhook(ctx context.Context, content string) error
func (*NotificationConfig) ShouldSendJobStatus ¶ added in v0.8.0
func (cfg *NotificationConfig) ShouldSendJobStatus() bool
type Service ¶
type ServiceImpl ¶ added in v0.10.0
type ServiceImpl struct {
// contains filtered or unexported fields
}
ServiceImpl defines the API for job HTTP handlers.
type StatusQuery ¶ added in v0.9.0
type Store ¶
type Store interface { Jobs(datastore.ListOptions) ([]Job, error) Job(id uuid.UUID) (Job, error) InsertJob(*Job) error UpdateJob(*Job) error AcceptJob(j *Job, acceptedGracePeriod time.Duration) error SchedulableJobs(acceptedGracePeriod, reSchedulableGracePeriod time.Duration, o datastore.ListOptions) ([]Job, error) Status() ([]StatusQuery, error) }
Store manages data regarding jobs.
func NewGormStore ¶
type WorkerPool ¶
type WorkerPool interface { RegisterExecutor(jobType string, executorF ExecutorFunc) CreateJob(jobType, txID string, opts ...JobOption) (*Job, error) Schedule(j *Job) error Status() (WorkerPoolStatus, error) Start() Stop(wait bool) Capacity() uint QueueSize() uint }
func NewWorkerPool ¶
func NewWorkerPool(db Store, capacity uint, workerCount uint, opts ...WorkerPoolOption) WorkerPool
type WorkerPoolImpl ¶ added in v0.10.0
type WorkerPoolImpl struct {
// contains filtered or unexported fields
}
func (*WorkerPoolImpl) Capacity ¶ added in v0.10.0
func (wp *WorkerPoolImpl) Capacity() uint
func (*WorkerPoolImpl) CreateJob ¶ added in v0.10.0
func (wp *WorkerPoolImpl) CreateJob(jobType, txID string, opts ...JobOption) (*Job, error)
CreateJob constructs a new Job for type `jobType` ready for scheduling.
func (*WorkerPoolImpl) QueueSize ¶ added in v0.10.0
func (wp *WorkerPoolImpl) QueueSize() uint
func (*WorkerPoolImpl) RegisterExecutor ¶ added in v0.10.0
func (wp *WorkerPoolImpl) RegisterExecutor(jobType string, executorF ExecutorFunc)
func (*WorkerPoolImpl) Schedule ¶ added in v0.10.0
func (wp *WorkerPoolImpl) Schedule(j *Job) error
Schedule will try to immediately schedule the run of a job
func (*WorkerPoolImpl) Start ¶ added in v0.10.0
func (wp *WorkerPoolImpl) Start()
func (*WorkerPoolImpl) Status ¶ added in v0.10.0
func (wp *WorkerPoolImpl) Status() (WorkerPoolStatus, error)
func (*WorkerPoolImpl) Stop ¶ added in v0.10.0
func (wp *WorkerPoolImpl) Stop(wait bool)
type WorkerPoolOption ¶ added in v0.8.0
type WorkerPoolOption func(*WorkerPoolImpl)
func WithAcceptedGracePeriod ¶ added in v0.9.0
func WithAcceptedGracePeriod(d time.Duration) WorkerPoolOption
func WithDbJobPollInterval ¶ added in v0.9.0
func WithDbJobPollInterval(d time.Duration) WorkerPoolOption
func WithJobStatusWebhook ¶ added in v0.8.0
func WithJobStatusWebhook(u string, timeout time.Duration) WorkerPoolOption
func WithLogger ¶ added in v0.9.0
func WithLogger(logger *log.Logger) WorkerPoolOption
func WithMaxJobErrorCount ¶ added in v0.9.0
func WithMaxJobErrorCount(count int) WorkerPoolOption
func WithReSchedulableGracePeriod ¶ added in v0.9.0
func WithReSchedulableGracePeriod(d time.Duration) WorkerPoolOption
func WithSystemService ¶ added in v0.9.0
func WithSystemService(svc system.Service) WorkerPoolOption
type WorkerPoolStatus ¶ added in v0.9.0
type WorkerPoolStatus struct { JobQueueStatus Capacity int `json:"poolCapacity"` WorkerCount int `json:"workerCount"` }
Click to show internal directories.
Click to hide internal directories.