scheduler

package module
v0.0.0-...-507d93a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

README

scheduler

scheduler library provides a simple golang job scheduler based on a dynamic pool of goroutines

Documentation

Overview

scheduler package provides a simple scheduler for concurrent execution of jobs.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var ErrQueueFull = errors.New("queue full")

Functions

This section is empty.

Types

type Runnable

type Runnable interface {
	// Run a job
	Run()
}

Runnable interface for scheduled jobs.

type Scheduler

type Scheduler interface {
	// Schedule a job for execution, which may commence immediately, or at a later time, when a concurrent goroutine
	// becomes available. Jobs are started in FIFO fashion.
	// When the job queue is full, function returns ErrQueueFull.
	Schedule(job Runnable) error

	// Stop scheduler and accept no more Schedule() requests.
	// Completes the outstanding jobs, shuts down worker goroutines, and exits.
	// Consequent calls to Stop() will have no effect.
	Stop()
}

Scheduler manages a dynamic pool of concurrent goroutines and dispatches Runnable jobs to them.

func NewScheduler

func NewScheduler(maxConcurrency, maxQueueSize int) (Scheduler, error)

NewScheduler creates and returns a new Scheduler. - maxConcurrency limits the maximum allowed number of goroutines. Value 0 indicates no limit (in which case all incoming jobs will be run concurrently immediately). - maxQueueSize limits the maximum allowed number of jobs waiting execution. One of the return values is always nil.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL