service

package
v0.0.0-...-53d8ad0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package service implements the base structure of a platform application.

Index

Constants

View Source
const (
	ExitOK = iota
	ExitError
	ExitStartup
)
View Source
const (
	// Max no. of discovery register retries.
	MaxDiscoveryRetries = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type RunFunc

type RunFunc func(context.Context, *Service) error

RunFunc is a function that will be called by Run to initialize a service. If this function returns an error then the server will immediately shut down.

type Service

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

Service represents a platform application.

func New

func New(name string) *Service

New creates a named Service with configurable dependencies.

func (*Service) Config

func (s *Service) Config() *config.Config

Service getter methods.

func (*Service) Creds

func (s *Service) Creds() *credentials.Store

func (*Service) Discovery

func (s *Service) Discovery() *discovery.Service

func (*Service) Error

func (s *Service) Error(err error)

Error sends a given error to the Service's error channel. Services should prefer calling this method instead of manually calling s.Exit() so shutdown can be handled gracefully.

func (*Service) Exit

func (s *Service) Exit(status int)

Exit cancels the service's context in order to signal a shutdown to child processes. It sleeps for a configurable time before signalling the process to exit.

func (*Service) ID

func (s *Service) ID() string

func (*Service) IsLeader

func (s *Service) IsLeader() bool

func (*Service) LoadCredentials

func (s *Service) LoadCredentials(creds ...credentials.Credential)

LoadCredentials attempts to load service credentials from config values into the credentials store. As this method is intended to be ran before service startup, errors are treated as fatal.

func (*Service) LoadDiscoveryConfig

func (s *Service) LoadDiscoveryConfig()

LoadDiscoveryConfig is a helper function for loading service discovery config.

func (*Service) LoadGrpcClientConfig

func (s *Service) LoadGrpcClientConfig()

LoadGrpcClientConfig is a helper function for loading required gRPC server config.

func (*Service) LoadGrpcServerConfig

func (s *Service) LoadGrpcServerConfig()

LoadGrpcServerConfig is a helper function for loading required gRPC server config.

func (*Service) LoadRequiredConfig

func (s *Service) LoadRequiredConfig()

LoadRequiredConfig is a helper function for loading config required by a service.

func (*Service) Name

func (s *Service) Name() string

func (*Service) RegisterDiscovery

func (s *Service) RegisterDiscovery(ctx context.Context)

RegisterDiscovery attempts to periodically register a service with the discovery service.

func (*Service) Run

func (s *Service) Run(run RunFunc)

Run starts the Service and ensures all dependencies are initialised.

By default, it will start the local web server and wait for a stop signal to be received before attempting to gracefully shutdown.

func (*Service) Scheduler

func (s *Service) Scheduler() *sync.WaitGroup

func (*Service) ServeGRPC

func (s *Service) ServeGRPC(ctx context.Context, srv grpc.ServiceServer)

func (*Service) StartDiscovery

func (s *Service) StartDiscovery(ctx context.Context) error

StartDiscovery attempts to establish a new connection to the discovery server.

Jump to

Keyboard shortcuts

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