jobcontroller

package
v0.0.0-...-e2521e0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JobController

type JobController struct {
	Job struct {
		// Add job that would be awaited before server shutdown
		Add func(delta int)
		// Mark a job as done
		Done func()
	}

	// Current context to use
	context.Context
	// Server shutdown context, Done on demand to shutdown
	ShutdownCtx context.Context
	// Server cleanup context, Done on force
	CleanupCtx context.Context

	//
	IsShuttingDown func() bool
	ShutdownStatus func() ShutdownStatus

	// Current logger to use
	Logger *mylog.Logger
	// contains filtered or unexported fields
}

One global object to manage the state of the system

func (JobController) AddLoggerPrefix

func (jc JobController) AddLoggerPrefix(prefix string) JobController

func (JobController) NewCtx

func (jc JobController) NewCtx(ctx context.Context) JobController

func (JobController) ShutdownRequested

func (jc JobController) ShutdownRequested() <-chan struct{}

type Option

type Option func(*ShutdownController) error

func DemandDeadline

func DemandDeadline(duration time.Duration) Option

Force demand (demand without cleanup) after duration

func InterruptHandler

func InterruptHandler(logger *mylog.Logger) Option

Force demand (demand without cleanup) after duration

func RequestDeadline

func RequestDeadline(duration time.Duration) Option

Turn Request into Demand (force-shutdown connections) after duration

type ShutdownController

type ShutdownController struct {
	ShutdownCtx context.Context

	CleanupCtx context.Context
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, options ...Option) (sc *ShutdownController, err error)

func (*ShutdownController) Demand

func (sc *ShutdownController) Demand()

Servers should terminate connections and cleanup

func (*ShutdownController) Done

func (sc *ShutdownController) Done() <-chan struct{}

func (*ShutdownController) Force

func (sc *ShutdownController) Force()

Extreme measure. Shutdown w/o cleanup

func (*ShutdownController) GetJobController

func (sc *ShutdownController) GetJobController(logger *mylog.Logger) JobController

func (*ShutdownController) IsShuttingDown

func (sc *ShutdownController) IsShuttingDown() bool

func (*ShutdownController) Request

func (sc *ShutdownController) Request()

Servers should deny new connections

func (*ShutdownController) ShutdownRequested

func (sc *ShutdownController) ShutdownRequested() <-chan struct{}

func (*ShutdownController) ShutdownStatus

func (sc *ShutdownController) ShutdownStatus() ShutdownStatus

type ShutdownStatus

type ShutdownStatus uint8
const (
	Working ShutdownStatus = iota
	Requested
	Demanded
	Forced
	Done
)

Jump to

Keyboard shortcuts

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