system

package
v0.0.0-...-1a2fedf Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CronJobLocationUTC     = "UTC"
	CronJobLocationBeijing = "Asia/Shanghai"
)
View Source
const CronJobProcess = gen.Atom("extensions_cron")
View Source
const DaemonMonitorProcess = gen.Atom("extensions_daemon")
View Source
const Supervisor = gen.Atom("extensions_sup")
View Source
const (
	WhereIsProcess = gen.Atom("extensions_whereis")
)

Variables

View Source
var ErrNoAvailableNodes = errors.New("no available nodes")

Functions

func RegisterLauncher

func RegisterLauncher(name gen.Atom, launcher Launcher) error

RegisterLauncher registers a launcher with the given name.

func UnregisterLauncher

func UnregisterLauncher(name gen.Atom)

UnregisterLauncher unregisters a launcher by its name.

Types

type AddressBook

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

AddressBook is a registry for all processes running on all nodes in the cluster. It's used to locate processes by their registered names.

func NewAddressBook

func NewAddressBook() *AddressBook

NewAddressBook creates a new AddressBook

func (*AddressBook) AddProcess

func (book *AddressBook) AddProcess(node gen.Atom, ps ...ProcessInfo) error

AddProcess adds a list of processes for the given node.

func (*AddressBook) GetAvailableNodes

func (book *AddressBook) GetAvailableNodes() *NodeList

GetAvailableNodes returns a list of available nodes.

func (*AddressBook) GetProcessList

func (book *AddressBook) GetProcessList(node gen.Atom) (list ProcessInfoList, err error)

GetProcessList returns a list of processes running on the given node.

func (*AddressBook) LocateLocal

func (book *AddressBook) LocateLocal(process gen.Atom) (gen.Atom, bool)

LocateLocal returns a process information by its registered name. Note: this only contains local data and should not be used for global process discovery.

func (*AddressBook) PickDirectoryNode

func (book *AddressBook) PickDirectoryNode(process gen.Atom) gen.Atom

PickDirectoryNode returns a directory node name by the given process name using consistent hashing.

func (*AddressBook) PickNode

func (book *AddressBook) PickNode(process gen.Atom) gen.Atom

PickNode returns a node name by the given process name using consistent hashing.

func (*AddressBook) QueryBy

func (book *AddressBook) QueryBy(caller gen.Process, option QueryOption) IAddressBookQuery

Locate returns a process information by its registered name.

func (*AddressBook) RemoveProcess

func (book *AddressBook) RemoveProcess(node gen.Atom, ps ...ProcessInfo) error

RemoveProcess removes a list of processes from the given node.

func (*AddressBook) SetAvailableNodes

func (book *AddressBook) SetAvailableNodes(nodes *NodeList) error

SetAvailableNodes sets a list of available nodes.

func (*AddressBook) SetProcess

func (book *AddressBook) SetProcess(node gen.Atom, ps ...ProcessInfo) error

SetProcess sets a list of processes for the given node. It removes all previously registered processes for this node.

type ApplicationMemberSpecOptions

type ApplicationMemberSpecOptions struct {
	AddressBook             *AddressBook
	CronJobs                []CronJob
	SyncAddressBookInterval time.Duration
}

type AtomicValue

type AtomicValue[T any] struct {
	// contains filtered or unexported fields
}

func NewAtomicValue

func NewAtomicValue[T any](v ...T) *AtomicValue[T]

func (*AtomicValue[T]) Load

func (self *AtomicValue[T]) Load() T

func (*AtomicValue[T]) Store

func (self *AtomicValue[T]) Store(v T) T

type CronJob

type CronJob struct {
	// Name is the unique name of the cron job.
	Name gen.Atom
	// Spec is the cron expression (e.g., "* * * * *").
	Spec string
	// Location specifies the timezone for the schedule, default is UTC.
	Location string
	// TriggerProcess is the name of the process to receive the trigger message.
	TriggerProcess gen.Atom
	// Scope defines whether the job runs on a single node or across the cluster.
	Scope CronJobScope
}

CronJob defines a cron job configuration.

type CronJobScope

type CronJobScope int
const (
	CronJobScopeCluster CronJobScope = iota
	CronJobScopeNode
)

type DaemonIterator

type DaemonIterator func() ([]DaemonProcess, bool, error)

type DaemonIteratorFactory

type DaemonIteratorFactory func() DaemonIterator

func SingletonDaemon

func SingletonDaemon(name gen.Atom, args []any) DaemonIteratorFactory

type DaemonProcess

type DaemonProcess struct {
	// ProcessName is the name of the process.
	ProcessName gen.Atom
	// Args are the arguments to start the process.
	Args []any
}

type IAddressBook

type IAddressBook interface {
	QueryBy(caller gen.Process, option QueryOption) IAddressBookQuery
	PickNode(process gen.Atom) gen.Atom
	PickDirectoryNode(process gen.Atom) gen.Atom
	GetAvailableNodes() *NodeList
}

IAddressBook defines address book interface

type IAddressBookQuery

type IAddressBookQuery interface {
	// Locate performs a global lookup for a process name across the cluster.
	// This operation involves network communication and may fail due to timeouts.
	Locate(processName gen.Atom) (node gen.Atom, err error)
}

IAddressBookQuery defines the interface for performing distributed queries on the address book.

type ImmutableList

type ImmutableList[T comparable] struct {
	// contains filtered or unexported fields
}

func NewImmutableList

func NewImmutableList[T comparable](list []T) *ImmutableList[T]

The caller must not modify list after passing it to NewImmutableList.

func (*ImmutableList[T]) Exist

func (self *ImmutableList[T]) Exist(elem T) bool

func (*ImmutableList[T]) Get

func (self *ImmutableList[T]) Get(i int) (elem T, ok bool)

func (*ImmutableList[T]) GetAll

func (self *ImmutableList[T]) GetAll() (elems []T)

func (*ImmutableList[T]) Len

func (self *ImmutableList[T]) Len() int

func (*ImmutableList[T]) Range

func (self *ImmutableList[T]) Range(fn func(T) bool)

type Launcher

type Launcher struct {
	// Factory is a function that creates a new process.
	Factory gen.ProcessFactory
	// Option provides options for configuring the process.
	Option gen.ProcessOptions

	// RecoveryScanner is an optional function that scans for daemons to recover.
	RecoveryScanner DaemonIteratorFactory // optional
	// contains filtered or unexported fields
}

func GetLauncher

func GetLauncher(name gen.Atom) (Launcher, bool)

GetLauncher retrieves a launcher by its name.

type Member

type Member string

Member is a wrapper for string to implement consistent.Member interface.

func (Member) String

func (m Member) String() string

type MessageAddressBook

type MessageAddressBook struct {
	Owner gen.PID
	Book  IAddressBook
}

type MessageForwardLocate

type MessageForwardLocate struct {
	Name gen.Atom
	From gen.PID
	Ref  gen.Ref
}

type MessageGetAddressBook

type MessageGetAddressBook struct{}

type MessageLaunchAllDaemon

type MessageLaunchAllDaemon struct{}

type MessageLaunchOneDaemon

type MessageLaunchOneDaemon struct {
	Launcher gen.Atom
	Process  DaemonProcess
}

type MessageLocate

type MessageLocate struct {
	Name gen.Atom
}

type MessageLocateResult

type MessageLocateResult struct {
	Name gen.Atom
	Node gen.Atom
}

type MessageProcessChanged

type MessageProcessChanged struct {
	Node        gen.Atom
	UpProcess   []ProcessInfo
	DownProcess []ProcessInfo
	Version     ProcessVersion
	FullSync    bool
}

type NodeList

type NodeList = ImmutableList[gen.Atom]

func NewNodeList

func NewNodeList(list ...gen.Atom) *NodeList

type ProcessInfo

type ProcessInfo struct {
	// Node is the node name hosting this process.
	Node gen.Atom
	// PID is the process identifier.
	PID gen.PID
	// Name is the registered name associated with this process.
	Name gen.Atom
	// BirthAt is the Unix timestamp (seconds) when the process was started.
	BirthAt int64
}

type ProcessInfoList

type ProcessInfoList []ProcessInfo

type ProcessVersion

type ProcessVersion [2]int64

func NewVersion

func NewVersion() ProcessVersion

func (ProcessVersion) Equal

func (v ProcessVersion) Equal(v2 ProcessVersion) bool

func (ProcessVersion) GreaterThan

func (v ProcessVersion) GreaterThan(v2 ProcessVersion) bool

func (ProcessVersion) GreaterThanOrEq

func (v ProcessVersion) GreaterThanOrEq(v2 ProcessVersion) bool

func (ProcessVersion) Incr

func (v ProcessVersion) Incr() ProcessVersion

func (ProcessVersion) String

func (v ProcessVersion) String() string

type QueryOption

type QueryOption struct {
	// Timeout specifies the query timeout in seconds.
	Timeout int
}

QueryOption defines the options for process lookup.

type Spawner

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

func NewSpawner

func NewSpawner(parent gen.Process, launcher gen.Atom) Spawner

func (Spawner) SpawnRegister

func (p Spawner) SpawnRegister(processName gen.Atom, args ...any) (pid gen.PID, err error)

Jump to

Keyboard shortcuts

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