services

package
v0.100.2 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Error = fmt.Errorf("services error")
	// StartEvent starts services defined in payload
	StartEvent = events.New("services", "start.services")
	StopEvent  = events.New("services", "stop.services")
)

Functions

func ResolveAddress added in v0.30.0

func ResolveAddress(sess *session.Context, s string) (string, error)

ResolveAddress resolves the given service name or address `s` into a full service address based on the current application’s configuration.

It retrieves the base application address from the session context (`app.address`) and attempts to resolve `s` into a complete service address.

Example:

addr, err := ResolveAddress(sess, "serviceA")
if err != nil {
    log.Fatal("Failed to resolve service address:", err)
}
fmt.Println("Resolved address:", addr)

Returns the resolved service address as a string or an error if resolution fails.

Types

type Container added in v0.25.0

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

func NewContainer added in v0.25.0

func NewContainer(sess *session.Context, addr *address.Address, svc *Service) (*Container, error)

func (*Container) CanRetry added in v0.25.0

func (c *Container) CanRetry() bool

func (*Container) Cancel added in v0.25.0

func (c *Container) Cancel(err error)

func (*Container) Done added in v0.25.0

func (c *Container) Done() <-chan struct{}

func (*Container) HandleEvent added in v0.25.0

func (c *Container) HandleEvent(sess *session.Context, ev events.Event)

func (*Container) HasTick added in v0.25.0

func (c *Container) HasTick() bool

func (*Container) Info added in v0.25.0

func (c *Container) Info() *service.Info

func (*Container) Listeners added in v0.25.0

func (c *Container) Listeners() []string

func (*Container) Register added in v0.25.0

func (c *Container) Register(sess *session.Context) error

func (*Container) Retries added in v0.25.0

func (c *Container) Retries() int

func (*Container) Settings added in v0.25.0

func (c *Container) Settings() service.Config

func (*Container) Start added in v0.25.0

func (c *Container) Start(ectx context.Context, sess *session.Context) (err error)

func (*Container) Stop added in v0.25.0

func (c *Container) Stop(sess *session.Context, e error) (err error)

func (*Container) Tick added in v0.25.0

func (c *Container) Tick(sess *session.Context, ts time.Time, delta time.Duration) error

func (*Container) Tock added in v0.25.0

func (c *Container) Tock(sess *session.Context, delta time.Duration, tps int) error

type CronScheduler added in v0.25.0

type CronScheduler interface {
	Job(name, expr string, cb action.Action)
}

type Info added in v0.25.0

type Info interface {
	Running() bool
	Name() string
	StartedAt() time.Time
	StoppedAt() time.Time
	Addr() *address.Address
	Failed() bool
	Errs() map[time.Time]error
}

type Service added in v0.25.0

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

func New added in v0.25.0

func New(s service.Config) *Service

New cretes new draft service which you can compose before passing it to applciation or providing it from addon.

func (*Service) Cron added in v0.25.0

func (s *Service) Cron(setupFunc func(schedule CronScheduler))

Cron scheduled cron jobs to run when the service is running.

func (*Service) Name added in v0.25.0

func (s *Service) Name() string

func (*Service) OnAnyEvent added in v0.25.0

func (s *Service) OnAnyEvent(cb events.ActionWithEvent[*session.Context])

OnAnyEvent called when any event is received.

func (*Service) OnEvent added in v0.25.0

func (s *Service) OnEvent(scope, key string, cb events.ActionWithEvent[*session.Context])

OnEvent is called when a specific event is received.

func (*Service) OnRegister added in v0.25.0

func (s *Service) OnRegister(action action.Action)

OnRegister is called when app is preparing runtime and attaching services, This does not mean that service will be used or started.

func (*Service) OnStart added in v0.25.0

func (s *Service) OnStart(action action.Action)

OnStart is called when service is requested to be started. For instace when command is requiring this service or whenever service is required on runtime via sess.RequireService call.

Start can be called multiple times in case of service restarts. If you do not want to allow service restarts you should implement your logic in OnStop when it's called first time and check that state OnStart.

func (*Service) OnStop added in v0.25.0

func (s *Service) OnStop(action action.WithPrevErr)

OnStop is called when runtime request to stop the service is recieved.

func (*Service) Slug added in v0.25.0

func (s *Service) Slug() string

func (*Service) StartEvent added in v0.36.0

func (s *Service) StartEvent() events.Event

StartEvent returns the event to start the service.

func (*Service) StopEvent added in v0.36.0

func (s *Service) StopEvent() events.Event

StopEvent returns the event to stop the service.

func (*Service) Tick added in v0.25.0

func (s *Service) Tick(action action.Tick)

OnTick when set will be called every application tick when service is in running state.

func (*Service) Tock added in v0.25.0

func (s *Service) Tock(action action.Tock)

OnTock is called after every tick.

type ServiceLoader added in v0.25.0

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

func NewLoader added in v0.25.0

func NewLoader(sess *session.Context, svcs ...string) *ServiceLoader

NewLoader creates a new ServiceLoader instance that initializes and prepares services for loading.

It accepts a session context and an optional list of service addresses. The loader will attempt to resolve and store service addresses based on the provided session configuration.

Example usage:

loader := NewLoader(sess, "serviceA", "serviceB")
<-loader.Load()
if err := loader.Err(); err != nil {
    log.Fatal("Service loading failed:", err)
}

Returns a pointer to a ServiceLoader instance.

func (*ServiceLoader) Err added in v0.25.0

func (sl *ServiceLoader) Err() error

Err returns an aggregated error if any occurred during the service loading process.

It should be called **after** the Load() channel unlocks to check whether loading was successful.

Example:

loader := NewLoader(sess, "serviceA")
<-loader.Load()
if err := loader.Err(); err != nil {
    log.Fatal("Failed to load services:", err)
}

Returns an error or nil if no errors occurred.

func (*ServiceLoader) Load added in v0.25.0

func (sl *ServiceLoader) Load() <-chan struct{}

Load starts the service loading process and returns a channel that signals when the loading is complete.

This function ensures that all requested services are either started or their failure is logged. If services fail to start within a configured timeout, Load will cancel the process and return an error via Err().

Example:

loader := NewLoader(sess, "serviceA", "serviceB")
<-loader.Load()
if err := loader.Err(); err != nil {
    log.Fatal("Service loading failed:", err)
}

Returns a receive-only channel that signals completion when closed.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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