summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-04-18 17:35:17 +0300
committerValery Piashchynski <[email protected]>2021-04-18 17:35:17 +0300
commitf5210c3f0739c03e9284c857d65dde3d97f3d84d (patch)
tree3a54f93b823487b5746467f2f4821d1d9ffd0ee5 /plugins
parent4e6dfc00c5619c4e749602d345fd2829ab0a3f07 (diff)
- Add more comments to the code
Diffstat (limited to 'plugins')
-rw-r--r--plugins/service/plugin.go2
-rw-r--r--plugins/service/process.go13
2 files changed, 9 insertions, 6 deletions
diff --git a/plugins/service/plugin.go b/plugins/service/plugin.go
index 75e849a3..bc72dbaf 100644
--- a/plugins/service/plugin.go
+++ b/plugins/service/plugin.go
@@ -49,7 +49,7 @@ func (service *Plugin) Serve() chan error {
// create needed number of the processes
for i := 0; i < service.cfg.Services[k].ProcessNum; i++ {
// create processor structure, which will process all the services
- service.processes = append(service.processes, NewFatProcess(
+ service.processes = append(service.processes, NewServiceProcess(
service.cfg.Services[k].RestartAfterExit,
service.cfg.Services[k].ExecTimeout,
service.cfg.Services[k].RestartDelay,
diff --git a/plugins/service/process.go b/plugins/service/process.go
index 449f005e..5a5eb32b 100644
--- a/plugins/service/process.go
+++ b/plugins/service/process.go
@@ -31,8 +31,9 @@ type Process struct {
stopCh chan struct{}
}
-func NewFatProcess(restartAfterExit bool, execTimeout, restartDelay time.Duration, command string, l logger.Logger, errCh chan error) *Process {
- p := &Process{
+// NewServiceProcess constructs service process structure
+func NewServiceProcess(restartAfterExit bool, execTimeout, restartDelay time.Duration, command string, l logger.Logger, errCh chan error) *Process {
+ return &Process{
rawCmd: command,
RestartDelay: restartDelay,
ExecTimeout: execTimeout,
@@ -41,8 +42,6 @@ func NewFatProcess(restartAfterExit bool, execTimeout, restartDelay time.Duratio
stopCh: make(chan struct{}),
log: l,
}
- // stderr redirect to the logger
- return p
}
// write message to the log (stderr)
@@ -57,7 +56,7 @@ func (p *Process) start() {
const op = errors.Op("processor_start")
- // cmdArgs contain command arguments if the command in form of: php <command> or ls <command> -i -b
+ // crate fat-process here
p.createProcess()
err := p.command.Start()
@@ -73,6 +72,7 @@ func (p *Process) start() {
}
func (p *Process) createProcess() {
+ // cmdArgs contain command arguments if the command in form of: php <command> or ls <command> -i -b
var cmdArgs []string
cmdArgs = append(cmdArgs, strings.Split(p.rawCmd, " ")...)
if len(cmdArgs) < 2 {
@@ -106,6 +106,7 @@ func (p *Process) execHandler() {
for {
select {
case <-tt.C:
+ // lock here, because p.startTime could be changed during the check
p.Lock()
// if the exec timeout is set
if p.ExecTimeout != 0 {
@@ -129,6 +130,8 @@ func (p *Process) execHandler() {
}
}
+// unsafe and fast []byte to string convert
+//go:inline
func toString(data []byte) string {
return *(*string)(unsafe.Pointer(&data))
}