Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrProviderStopped is returned when a provider has been stopped. ErrProviderStopped = errors.NewKind("provider stopped") // ErrProviderStop is returned when a provider fails on Stop. ErrProviderStop = errors.NewKind("provider failed on stop") )
var ( // ErrNewJobsNotFound is returned if there's no more jobs to schedule. ErrNewJobsNotFound = errors.NewKind( "couldn't find new jobs to schedule") // ErrClosedChannel is returned if the jobs source is closed. ErrClosedChannel = errors.NewKind("channel is closed") )
Functions ¶
This section is empty.
Types ¶
type Job ¶
type Job interface {
// Process perform the necessary work on the job.
Process(context.Context) error
}
Job represents a gitcollector task.
type JobScheduler ¶
type JobScheduler struct {
// contains filtered or unexported fields
}
JobScheduler schedules the Jobs to be processed.
func NewJobScheduler ¶
func NewJobScheduler( schedule ScheduleFn, opts *JobSchedulerOpts, ) *JobScheduler
NewJobScheduler builds a new JobScheduler.
func (*JobScheduler) Jobs ¶
func (s *JobScheduler) Jobs() chan Job
Jobs returns the channel where the JobScheduler will schedule the Jobs.
type JobSchedulerOpts ¶
type JobSchedulerOpts struct {
Capacity int
NotWaitNewJobs bool
NewJobTimeout time.Duration
JobTimeout time.Duration
}
JobSchedulerOpts are configuration options for a JobScheduler.
type MetricsCollector ¶
type MetricsCollector interface {
// Start starts collecting metrics.
Start()
// Stop stops collectingMetrincs.
Stop(immediate bool)
// Success registers metrics about successfully processed Job.
Success(Job)
// Faile register metrics about a failed processed Job.
Fail(Job)
// Discover register metrics about a discovered Job.
Discover(Job)
}
MetricsCollector represents a component in charge to collect jobs metrics.
type ScheduleFn ¶
type ScheduleFn func(*JobSchedulerOpts) (Job, error)
ScheduleFn is a function to schedule the next Job.
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker is in charge of process gitcollector.Jobs.
func NewWorker ¶
func NewWorker(jobs chan Job, metrics MetricsCollector) *Worker
NewWorker builds a new Worker.
type WorkerPool ¶
type WorkerPool struct {
// contains filtered or unexported fields
}
WorkerPool holds a pool of workers to process Jobs.
func NewWorkerPool ¶
func NewWorkerPool( scheduler *JobScheduler, metrics MetricsCollector, ) *WorkerPool
NewWorkerPool builds a new WorkerPool.
func (*WorkerPool) Close ¶
func (wp *WorkerPool) Close()
Close stops all the workers in the pool waiting for the jobs to finish.
func (*WorkerPool) SetWorkers ¶
func (wp *WorkerPool) SetWorkers(n int)
SetWorkers set the number of Workers in the pool to n.
func (*WorkerPool) Size ¶
func (wp *WorkerPool) Size() int
Size returns the current number of workers in the pool.
func (*WorkerPool) Stop ¶
func (wp *WorkerPool) Stop()
Stop stops all the workers in the pool immediately.
func (*WorkerPool) Wait ¶
func (wp *WorkerPool) Wait()
Wait waits for the workers to finish. A worker will finish when the queue to retrieve jobs from is closed.
