service

package
v0.0.0-...-28654c7 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Build

type Build struct {
	BuildNumber int    `json:"buildNumber"`
	Hash        string `json:"hash"`
	ShortHash   string `json:"shortHash"`
}

func (*Build) BuildHash

func (b *Build) BuildHash() string

type Flagger

type Flagger interface {
	// Parse reads flags into the flagger struct. It should be invoked after flag.Parse() which is typically handled by
	// the derezzolution platform service.
	Parse()

	// Run oneshot flags (flags that terminate and don't agument service).
	Run()
}

type Flags

type Flags struct {
	Flagger

	BuildInfo         bool
	DoesShowTimestamp bool
	Property          string
	Version           bool
	// contains filtered or unexported fields
}

func NewFlags

func NewFlags(service *Service) *Flags

NewFlags creates a new Flags struct (use Parse to read in flags to the struct).

func (*Flags) HasProperty

func (f *Flags) HasProperty() bool

HasProperty returns whether we're attempting to read a property from the config.

func (*Flags) Parse

func (f *Flags) Parse()

Parse reads flags into the flagger struct. It should be invoked after flag.Parse() which is typically handled by the derezzolution platform service.

func (*Flags) Run

func (f *Flags) Run()

Run oneshot flags (flags that terminate and don't agument service) that are specific to platform.

func (*Flags) RunWithConfigurer

func (f *Flags) RunWithConfigurer(configurer config.Configurer)

RunWithConfigurer runs oneshot flags (flags that terminate and don't agument service) that are specific to platform and have dependencies on an additional configurer.

func (*Flags) RunWithFlagger

func (f *Flags) RunWithFlagger(flagger Flagger)

RunWithFlagger runs oneshot flags (flags that terminate and don't augment service) that are specific to platform consumers (typically )

type Runner

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

Runners control how workers are executed at a periodicity. For a usage example, check out ExampleRunner.

func NewRunner

func NewRunner(service *Service, config RunnerConfig) *Runner

NewRunner creates a new runner with clean-up behaviors.

func (*Runner) Errorf

func (r *Runner) Errorf(pattern string, args ...interface{}) error

func (*Runner) FullName

func (r *Runner) FullName() string

func (*Runner) IsStopping

func (r *Runner) IsStopping() bool

func (*Runner) Logf

func (r *Runner) Logf(pattern string, args ...interface{})

func (*Runner) StartNewWorker

func (r *Runner) StartNewWorker(worker func() error)

func (*Runner) Stop

func (r *Runner) Stop() error

type RunnerConfig

type RunnerConfig struct {
	// InitDelayDuration is the duration before a worker is started initially.
	// Total start time of a worker is InitDelayDuration +
	// rand(InitDelayJitterDuration).
	InitDelayDuration time.Duration

	// InitDelayJitterDuration is a random duration added to InitDelayDuration
	// before a worker is started initially. Total start time of a worker is
	// InitDelayDuration + rand(InitDelayJitterDuration).
	InitDelayJitterDuration time.Duration

	// MaximumCleanUpDuration is the maximum amount of time all workers can
	// take for clean up. If more workers don't finish within this duration,
	// they're forcefully stopped.
	MaximumCleanUpDuration time.Duration

	// Name of the runner (used in logging).
	Name string

	// WorkerSleepDuration is how much time a worker sleeps after a run, before
	// it starts again.
	WorkerSleepDuration time.Duration
}

type Service

type Service struct {
	Config  *config.Config
	Flags   *Flags
	Version *Version
	// contains filtered or unexported fields
}

Service holding foundational harness. Each process should only ever have 1 instance of this structure.

func NewService

func NewService(packageFS *embed.FS) *Service

NewService creates a new service by initializing foundational harness.

func NewServiceWithOptions

func NewServiceWithOptions(packageFS *embed.FS, options *ServiceOptions) *Service

NewService creates a new service by initializing foundational harness using additional config.

func (*Service) AddInterruptListener

func (s *Service) AddInterruptListener(listener func())

Add interrupt listener adds a callback to be invoke immediately after receiving os interrupt signals triggering service termination. Callback does not block.

func (*Service) Run

func (s *Service) Run()

Run the service with a blocking busy-wait watching for OS Signals.

func (*Service) RunWithCleanUp

func (s *Service) RunWithCleanUp(cleanUpFunc func() error)

Run the service with a blocking busy-wait watching for OS Signals.

Upon os signal interrupt, the service winds down in the following order: 1. Notify all interrupt listeners async 2. Stop all runners one-by-one in LIFO fashion 3. Run cleanUpFun blocking 4. OS terminate (returning non-zero if error in 2 or 3)

type ServiceOptions

type ServiceOptions struct {
	// AdditionalConfigurer can be used for additional configurers (configurations from services that use platform). It
	// could make sense for this to be an array of configurers.
	AdditionalConfigurer config.Configurer

	// AdditionalFlagger can be used for additional flaggers (flag structs from services that use platform). It could
	// make sense for this to be an array of flaggers.
	AdditionalFlagger Flagger
}

ServiceOptions allow additional service configurability with the NewServiceWithOptions constructor.

type Version

type Version struct {
	// Build is the primary service build information.
	Build Build `json:"build"`

	// BuildTime is the time that the build happened (ideally aligns with the package timestamp),
	// e.g.: $(date -u +"%Y-%m-%dT%H:%M:%SZ") -> "2023-02-26T07:49:35Z" (UTC)
	BuildTime time.Time `json:"buildTime"`

	// Pipeline provides the build method, e.g.: "manual", "github_actions", "bitbucket_pipelines"
	Pipeline string `json:"pipeline"`

	// (Optional) If supplied, provides the build information for the resource bundle.
	Resources Build `json:"resources"`
}

func NewVersion

func NewVersion(packageFS *embed.FS) (*Version, error)

NewVersion creates a new version given a package file system (which must contain version.json).

func (*Version) LogSummary

func (v *Version) LogSummary()

func (*Version) ToJson

func (v *Version) ToJson() (string, error)

func (*Version) VersionHash

func (v *Version) VersionHash() string

Jump to

Keyboard shortcuts

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