Documentation
¶
Index ¶
- func CheckEnv[T any](key string, v T) any
- func ETReadFileFn(ctx context.Context, p *Process) func()
- func NewUUID() string
- func RegisterProcessesInESProcesses(p *Process, pi *registerProcessInfo)
- type Buffer
- type Config
- type ESProcessesMap
- type ETFunc
- type Event
- type EventName
- type EventOpt
- type EventRW
- type Instruction
- type Node
- type PidVsProcMap
- type Process
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckEnv ¶
Check if an env variable is set. If found, return the value. Takes the name of the env variable, and the actual variable containing a default value as it's input.
func ETReadFileFn ¶
func RegisterProcessesInESProcesses ¶
func RegisterProcessesInESProcesses(p *Process, pi *registerProcessInfo)
Register all the processes in ESProcesses.
Types ¶
type Config ¶
type Config struct {
CustomEvents bool
Metrics bool
CustomEventsPath string
NodeName Node
LogLevel string
}
Config holds all the configuration settings for the actress system.
func NewConfig ¶
New config prepare a *Config, and a *flag.FlagSet, and return the resulting actress *Config and *flag.FlagSet. The flags are checked for env variables, and if not found, the default value is used. The flagset needs to be parsed for the flags to be set.
The logLevel is the default log level for the system, and can be provided as an input argument.
type ESProcessesMap ¶
type ETFunc ¶
Function type describing the signature of a function that is to be used when creating a new process.
func EDSyncFn ¶
func EDSyncFn(syncCh chan struct{}) ETFunc
EtSyncFn is the function that will be used to syncronize events. It takes a channel that will be used to send a signal on when the EDSync event is executed.
In general EDSync is used to syncronize one-off events, so delete the process after it is done with it's sync job.
type Event ¶
type Event struct {
Nr int
// Name is a unique name to identify the type of the event.
Name EventName `json:"name" yaml:"name" cbor:"name"`
// Cmd is usually used for giving instructions or parameters for
// what an event shall do.
Cmd []string `json:"cmd" yaml:"cmd" cbor:"cmd"`
// Instruction got the underlying type of string. This field can
// be used to give for example an instruction of a single word.
// For example in switch statements at the receiving actor, or other.
Instruction Instruction
// Data usually carries the data from one process to the next. Example
// could be a file read on process1 is put in the Data field, and
// passed on to process2 to be unmarshaled.
Data []byte `json:"data" yaml:"data" cbor:"data"`
// Data to be transfered internally. Example is to send config directly via
// the channel between internal actors.
InternalCh chan chan []byte `json:"-" yaml:"-" cbor:"-"`
// Err is used for defining the error message when the event is used
// as an error event.
Err error `json:"error" yaml:"error" cbor:"error"`
// NextEvent defines a series of events to be executed like a workflow.
// The receiving process should check this field for what kind of event
// to create as the next step in the workflow.
NextEvent *Event `json:"nextEvent" yaml:"nextEvent" cbor:"nextEvent"`
// PreviousEvent allows for keeping information about the previous event if needed.
PreviousEvent *Event `json:"previousEvent" yaml:"previousEvent" cbor:"previousEvent"`
// Dst node.
DstNode Node `json:"dstNode" yaml:"dstNode" cbor:"dstNode"`
// Src node.
SrcNode Node `json:"srcNode" yaml:"srcNode" cbor:"srcNode"`
}
Event defines an event. It holds:
- The Name, which specifies the process are meant for.
- The Cmd, are meant to but not limited to be a way to give instructions for what a process should do. The receiving process are responsible for parsing the string slice into something useful.
- The Data field are ment to carry the result from the work done by a process, to the next process.
- Both Cmd and Data can be used interchangeably if it makes more sense for a given scenario. No strict rules for this exist. Just make sure to document the use of the given Name, so the structure of how to use the fields exist.
- Err, are used by the error event type (ER).
- NextEvent are used when we want to define a chain of events to be executed. The processes must make use of the field for this to work. Check out the examples folder for a simple example for how it could be implemented.
func CopyEventFields ¶
Copy all the descriptive meta data fields of the Event, not channels or Data.
type EventName ¶
type EventName string
Name is a unique name used to identify events. It is used both for creating processes and also for routing messages to the correct process.
const ECGeneralDelivery EventName = "ECGeneralDelivery"
Primarily used for testing to check that the ECRouter properly routes events, and that custom processes start up correctly.
const ECRouter EventName = "ECRouter"
Router for custom events.
const EDRouter EventName = "EDRouter"
Router for normal events.
const EDSync EventName = "EDSync"
EDSync is used to syncronize events. The EDSyncFn that is to be used with this event type takes a signal channel, we can then use this event type to signal that another event is done before we continue by setting this event type as the NextEvent.
const ERLog EventName = "ERLog"
Log errors.
const ERNone EventName = "ERNone"
Will drop the event if it is an error event.
const ERRouter EventName = "ERRouter"
Router for error events.
const ERTest EventName = "ERTest"
Log and exit system.
const ESProcesses EventName = "ESProcesses"
Handles information about the currently running processes in the local Actress system.
const ESRouter EventName = "ESRouter"
Router for supervisor events.
const ETDone EventName = "ETDone"
Done don't currently do anything.
const ETExit EventName = "ETExit"
Will exit and kill all processes.
const ETOsSignal EventName = "ETOsSignal"
Press ctrl+c to exit.
const ETPid EventName = "ETPid"
Handling pids within the system. The structure of the ev.Cmd is a slice of string: []string{"action","pid","process name"}
const ETPidGetAll EventName = "ETPidGetAll"
Get all the current processes running. Will return a json encoded PidVsProcMap.
const ETPrint EventName = "ETPrint"
Print the content of the .Data field of the event to stdout.
const ETReadFile EventName = "ETReadFile"
Read file. The path path to read should be in Event.Cmd[0].
const ETRemote EventName = "ETRemote"
ETRemote is an Name that will be used if an event should be delivered to a remote node.
There are no ETFunc defined for ETRemote in Actress, so it is up to the user to write this function, and attach their own ETFunc when they create the process to handle the ETRemote Name.
ETRemote are for example used in the AddEvent function, and will be prepended to the current event if it should not be handled locally.
const ETRoot EventName = "ETRoot"
The main Root process. By default the root process don't have an ETFunc registered with it to handle the ETRoot eventtype, but one can be created with the normal ETFunc function signature, and defined when creating a new root process.
const ETRouter EventName = "ETRouter"
Router for normal events.
const ETTest EventName = "ETTest"
The ETTest eventype are used for testing.
const ETTestCh EventName = "ETTestCh"
Will forward the incomming event to the builtin .TestCh of the process.
type EventRW ¶
func NewEventRW ¶
NewEventRW will return a type that adds Read and Write methods to the Event type.
type Instruction ¶
type Instruction string
const InstructionCmdEOF Instruction = "InstructionCmdEOF"
const InstructionDebug Instruction = "InstructionDebug"
const InstructionESProcessesAdd Instruction = "InstructionESProcessesAdd"
Will instruct to get all information about all processes.
const InstructionESProcessesDelete Instruction = "InstructionESProcessesDelete"
const InstructionESProcessesGetAll Instruction = "InstructionESProcessesGetAll"
const InstructionError Instruction = "InstructionError"
Instructions for error logging.
const InstructionFatal Instruction = "InstructionFatal"
const InstructionInfo Instruction = "InstructionInfo"
type PidVsProcMap ¶
type PidVsProcMap map[pidnr]*Process
type Process ¶
type Process struct {
// Channel to receive events into the process function.
InCh chan Event `json:"-"`
// Channel to send events to be picked up by other processes.
StaticEventCh chan Event `json:"-"`
// Channel to send error events.
ErrorEventCh chan Event `json:"-"`
// Channel for getting the result in tests.
TestCh chan Event `json:"-"`
// Channel to use for routing events for dynamic processes.
DynamicEventCh chan Event `json:"-"`
// Channel to use for routing events for custom processes.
CustomEventCh chan Event `json:"-"`
// Channel to use for routing supervisor events
SupervisorEventCh chan Event `json:"-"`
// The event type for the process.
Event EventName
// Maps for various staticProcess information.
// NB: Added a Mutex on this structure, though it should really not be needed,
// since there is only reads from the static procMap. Decide later if we should
// remove it again.
StaticProcesses *staticProcesses
// Map of dynamic processes
DynamicProcesses *dynamicProcesses
// Map of custom processes
CustomProcesses *customProcesses
// Maps for various errProcess information
ErrorProcesses *errorProcesses
// The main counter used for assigning Nr to events.
EventNr *eventNr
// Holding all configuration settings.
Config *Config
// PID of the process
PID pidnr
// The context of the process
Ctx context.Context `json:"-"`
// Cancel func for context of the process
Cancel context.CancelFunc `json:"-"`
// contains filtered or unexported fields
}
Process defines a process.
func NewProcess ¶
NewProcess will prepare and return a *Process. It will copy channels and map structures from the root process.
func NewRootProcess ¶
NewRootProcess will prepare and return the root process which holds all the core elements needed, like the main channels for events and errors, and varouis registers or maps holding information about the system. Later created processes will reference these elements when they are created. The root process will also start up all the essential other processes needed, like the event router, and various standard error handling processes.
func (*Process) Act ¶
Will start the ETFunc attached to the process.
If no ETFunc is defined for the process will just return after calling this function. The process can still be used and we can communicate with it via it's channels.
func (*Process) AddEvent ¶
AddEvent will deliver the event to the correct router based on the specified Kind of the Event. If the Kind are missing the event will be handled as a static event. If the event is to be delivered to a remote node, AddEvent will also take care of that and ship the event off to the ETRemote process.
func (*Process) CurrentEventNr ¶
CurrentEventNr returns the current value of the shared event counter without modifying it.
func (*Process) IncrementEventNr ¶
IncrementEventNr atomically increments the shared event counter and returns the new value.
func (*Process) Stop ¶
Will Cancel the context attached to the process. Will delete the process from the processes map. Will delete the pid from the pids map.
func (*Process) WaitForReady ¶
func (p *Process) WaitForReady()
Wait for the process function to be ready and started for the specific process.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
2actresses
command
|
|
|
childprocess
command
|
|
|
httpget
command
|
|
|
httpget-predfined-next-event
command
|
|
|
print-all-processes
command
|
|
|
proxy
command
|
|
|
reader-writer
command
|