application

package
Version: v0.0.0-...-29ecac1 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package application define a simple application life cycle which should be robust enough for most of the application or be extended by your own custom implementation if it does not.

The application will start by initializing every given components, linking them to each other with the Inventory.

The components which implements the optional Validator interface will then be validated, any returned error will abort the application.

If no error has been returned, the application will then move to the next phase. Every components which implements the option StartHook interface will be started in the same order than it was given in the call to WithComponents. Returning an error from the Start callback will abort the application.

Finally, the application will run until it receives an interruption signal, or its context has been canceled or expired, or an error has been returned from the Start callback,

Once the application initiate its interruption, the components implementing the StopHook interface will be asked to stop and forcefully stopped if they do not perform after the configured grace period. The components will be stopped in the reverse order than the one given in the call to WithComponents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithComponent

func WithComponent(component scaffolder.Component, opts ...scaffolder.Option) scaffolder.Option

WithComponent is used to attach register a component in the application life cycle.

func WithGracefulPeriod

func WithGracefulPeriod(duration time.Duration) scaffolder.Option

WithGracefulPeriod set the grace period allocated for stopping a component. The default value is one second.

func WithName

func WithName(name string) scaffolder.Option

WithName set the application name, the default value is the binary name.

func WithVersion

func WithVersion(version string) scaffolder.Option

WithVersion set the version of the application, the default value is "0.0.0".

Types

type Application

type Application struct {
	// contains filtered or unexported fields
}

Application should describe your application.

func New

func New(opts ...scaffolder.Option) (*Application, error)

New build an application and customize it with the given Options.

func (*Application) Default

func (a *Application) Default()

Default assign the default variables for the application component.

func (*Application) Run

func (a *Application) Run(ctx context.Context) (err error)

Run the application until it receives an interruption signal, or until its context has been canceled or expired, or until an error has been returned from the Start callback.

The application would return an error if it was unable to Add a component, links the components, validate the components, start the components or stop the components.

func (*Application) String

func (a *Application) String() string

String implements the Stringer interface.

type StartHook

type StartHook interface {
	Start(context.Context) error
}

StartHook define the interface for long running process which must run in parallel with the application.

type StopHook

type StopHook interface {
	Stop(context.Context) error
}

StopHook define the interface for components which require a graceful shutdown.

type Validator

type Validator interface {
	Validate() error
}

Validator define the interface for components which should be validated.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL