mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat(filters): log external filter exec cmd output (#1029)
This commit is contained in:
parent
c3cbe0e8ba
commit
3755881c40
1 changed files with 42 additions and 6 deletions
|
@ -603,16 +603,52 @@ func (s *service) execCmd(ctx context.Context, external domain.FilterExternal, r
|
||||||
// setup command and args
|
// setup command and args
|
||||||
command := exec.Command(cmd, commandArgs...)
|
command := exec.Command(cmd, commandArgs...)
|
||||||
|
|
||||||
err = command.Run()
|
s.log.Debug().Msgf("script: %s args: %s", cmd, strings.Join(commandArgs, " "))
|
||||||
var exitErr *exec.ExitError
|
|
||||||
if errors.As(err, &exitErr) {
|
// Create a pipe to capture the standard output of the command
|
||||||
s.log.Debug().Msgf("filter script command exited with non zero code: %d", exitErr.ExitCode())
|
cmdOutput, err := command.StdoutPipe()
|
||||||
return exitErr.ExitCode(), nil
|
if err != nil {
|
||||||
|
s.log.Error().Err(err).Msg("could not create stdout pipe")
|
||||||
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
duration := time.Since(start)
|
duration := time.Since(start)
|
||||||
|
|
||||||
s.log.Debug().Msgf("executed external script: (%s), args: (%s) for release: (%s) indexer: (%s) total time (%s)", cmd, external.ExecArgs, release.TorrentName, release.Indexer, duration)
|
// Start the command
|
||||||
|
if err := command.Start(); err != nil {
|
||||||
|
s.log.Error().Err(err).Msg("error starting command")
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a buffer to store the output
|
||||||
|
outputBuffer := make([]byte, 4096)
|
||||||
|
|
||||||
|
execLogger := s.log.With().Str("release", release.TorrentName).Str("filter", release.FilterName).Logger()
|
||||||
|
|
||||||
|
for {
|
||||||
|
// Read the output into the buffer
|
||||||
|
n, err := cmdOutput.Read(outputBuffer)
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write the output to the logger
|
||||||
|
execLogger.Trace().Msg(string(outputBuffer[:n]))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for the command to finish and check for any errors
|
||||||
|
if err := command.Wait(); err != nil {
|
||||||
|
var exitErr *exec.ExitError
|
||||||
|
if errors.As(err, &exitErr) {
|
||||||
|
s.log.Debug().Msgf("filter script command exited with non zero code: %v", exitErr.ExitCode())
|
||||||
|
return exitErr.ExitCode(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
s.log.Error().Err(err).Msg("error waiting for command")
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
s.log.Debug().Msgf("executed external script: (%s), args: (%s) for release: (%s) indexer: (%s) total time (%s)", cmd, parsedArgs, release.TorrentName, release.Indexer, duration)
|
||||||
|
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue