Documentation ¶
Index ¶
- func CheckEnv[T any](key string, v T) any
- func ETCustomEventFn(ctx context.Context, p *Process) func()
- func ETReadFileFn(ctx context.Context, p *Process) func()
- func NewUUID() string
- func WrapperCustomCmd(command []string) func(ctx context.Context, p *Process) func()
- type Buffer
- type Config
- type ETFunc
- type Event
- type EventOpt
- type EventRW
- type EventType
- type PidVsProcMap
- type Process
- func NewDynProcess(ctx context.Context, parentP Process, event EventType, fn ETFunc) *Process
- func NewErrProcess(ctx context.Context, parentP Process, event EventType, fn ETFunc) *Process
- func NewProcess(ctx context.Context, parentP Process, event EventType, fn ETFunc) *Process
- func NewRootProcess(ctx context.Context) *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 ETCustomEventFn ¶
func ETReadFileFn ¶
func WrapperCustomCmd ¶
Wrapper around creating an etFunc. The use of this wrapper function is to insert some predefined values into the cmd to be executed when a process for the eventType is created. When an event later is reveived, the content of the Event.Cmd field is appended to what is already defined there from earlier. An example of this is that we define the content of the command to be executed when the process is defined to contain []string{"/bin/bash","-c"}. When an event later is received and handled by this function, the contend of the .Cmd field is appended to the predefined fields, and will for example give a result to be executed like []string{"/bin/bash","-c","ls -l|grep file.txt"}.
Types ¶
type ETFunc ¶
Function type describing the signature of a function that is to be used when creating a new process.
type Event ¶
type Event struct { Nr int // EventType is a unique name to identify the type of the event. EventType EventType `json:"eventType" yaml:"eventType"` // Cmd is usually used for giving instructions or parameters for // what an event shall do. Cmd []string `json:"cmd" yaml:"cmd"` // 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"` // Err is used for defining the error message when the event is used // as an error event. Err error `json:"error" yaml:"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:"event" yaml:"event"` }
Event defines an event. It holds:
- The EventType, 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 EventType, 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.
type EventRW ¶
func NewEventRW ¶
NewEventRW will return a type that adds Read and Write methods to the Event type.
type EventType ¶
type EventType string
EventType 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 EDRouter EventType = "EDRouter"
Router for normal events.
const ERDebug EventType = "ERDebug"
Log debug errors.
const ERFatal EventType = "ERFatal"
Log and exit system.
const ERLog EventType = "ERLog"
Log errors.
const ERRouter EventType = "ERRouter"
Router for error events.
const ERTest EventType = "ERTest"
Log and exit system.
const ETCustomEvent EventType = "ETCustomEvent"
ETCustomEvent are used when reading custom user defined events to create processes from disk. It expects it's input in the Data field of the event to be the JSON serialized data of a custom Event. The unmarshaled custom event will then be used to prepare and start up a process for the new EventType.
const ETDone EventType = "ETDone"
Done don't currently do anything.
const ETExit EventType = "ETExit"
Will exit and kill all processes.
const ETOsCmd EventType = "etOsCmd"
Execute OS commands. The command to execute should be put in the first slot of the arrat at Event.Cmd[0], and all arguments should be put int the sub sequent slots. To make it simpler to run commands without splitting the up on Linux like operating systems use the -c flag with bash. Example, Event{EventType: etOsCmd, Cmd: ["bash","-c","ls -l|grep myfile"]}.
const ETOsSignal EventType = "ETOsSignal"
Press ctrl+c to exit.
const ETPid EventType = "ETPid"
Handling pids within the system. The structure of the ev.Cmd is a slice of string: []string{"action","pid","process name"}
const ETPidGetAll EventType = "ETPidGetAll"
Get all the current processes running. Will return a json encoded PidVsProcMap.
const ETPrint EventType = "ETPrint"
Print the content of the .Data field of the event to stdout.
const ETProfiling EventType = "ETprofiling"
Profiling.
const ETReadFile EventType = "ETReadFile"
Read file. The path path to read should be in Event.Cmd[0].
const ETRoot EventType = "ETRoot"
The main Root process.
const ETRouter EventType = "ETRouter"
Router for normal events.
const ETTestCh EventType = "ETTestCh"
Will forward the incomming event to the Process.TestCh.
const ETWatchEventFile EventType = "ETWatchEventFile"
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. EventCh chan Event `json:"-"` // Channel to send error events. ErrorCh chan Event `json:"-"` // Channel for getting the result in tests. TestCh chan Event `json:"-"` // Channel to use for routing events for dynamic processes. DynCh chan Event `json:"-"` // The event type for the process. Event EventType // Maps for various process information. Processes *processes // Map of dynamic processes DynProcesses *dynProcesses // Maps for various errProcess information ErrProcesses *errProcesses // Holding all configuration settings. Config *Config // PID of the process PID pidnr // Cancel func Cancel context.CancelFunc `json:"-"` // contains filtered or unexported fields }
Process defines a process.
func NewDynProcess ¶
func NewErrProcess ¶
NewErrProcess will prepare and return a *Process. It will copy channels and map structures from the root 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) AddDynEvent ¶
Will add an event to be handled by the processes.