Skip to content

Commit

Permalink
refactor: community requests (Cloudbox#61)
Browse files Browse the repository at this point in the history
* refactor: delay consecutive requests

* refactor(plex): warning on no library match

* refactor: consistently wait 15 seconds

* build: remove lint workflow

Co-authored-by: James Bayliss <l3uddz@gmail.com>
  • Loading branch information
m-rots and l3uddz authored Nov 26, 2020
1 parent 42137fb commit 7c0cbf9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 46 deletions.
14 changes: 0 additions & 14 deletions .github/workflows/lint.yml

This file was deleted.

64 changes: 34 additions & 30 deletions cmd/autoscan/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,43 +332,47 @@ func main() {
}

err = proc.Process(targets)
if err != nil {
switch {
case errors.Is(err, autoscan.ErrNoScans):
// No scans currently available, let's wait a couple of seconds
log.Trace().Msg("Waiting 5 seconds as no scans are available")
time.Sleep(5 * time.Second)
switch {
case err == nil:
// Sleep 5 seconds between successful requests to reduce the load on targets.
time.Sleep(5 * time.Second)

case errors.Is(err, autoscan.ErrAnchorUnavailable):
log.Error().
Err(err).
Msg("Not all anchor files are available, retrying in 5 seconds...")
case errors.Is(err, autoscan.ErrNoScans):
// No scans currently available, let's wait a couple of seconds
log.Trace().
Msg("No scans are available, retrying in 15 seconds...")

time.Sleep(5 * time.Second)
time.Sleep(15 * time.Second)

case errors.Is(err, autoscan.ErrFatal):
// fatal error occurred, processor must stop (however, triggers must not)
log.Error().
Err(err).
Msg("Fatal error occurred while processing targets, processor stopped, triggers will continue...")
case errors.Is(err, autoscan.ErrAnchorUnavailable):
log.Error().
Err(err).
Msg("Not all anchor files are available, retrying in 15 seconds...")

// sleep indefinitely
select {}
time.Sleep(15 * time.Second)

case errors.Is(err, autoscan.ErrTargetUnavailable):
targetsAvailable = false
log.Error().
Err(err).
Msg("Not all targets are available, retrying in 15 seconds...")
case errors.Is(err, autoscan.ErrTargetUnavailable):
targetsAvailable = false
log.Error().
Err(err).
Msg("Not all targets are available, retrying in 15 seconds...")

time.Sleep(15 * time.Second)
time.Sleep(15 * time.Second)

default:
// unexpected error
log.Fatal().
Err(err).
Msg("Failed processing targets")
}
case errors.Is(err, autoscan.ErrFatal):
// fatal error occurred, processor must stop (however, triggers must not)
log.Error().
Err(err).
Msg("Fatal error occurred while processing targets, processor stopped, triggers will continue...")

// sleep indefinitely
select {}

default:
// unexpected error
log.Fatal().
Err(err).
Msg("Failed processing targets")
}
}
}
5 changes: 3 additions & 2 deletions targets/plex/plex.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ func (t target) Scan(scan autoscan.Scan) error {

libs, err := t.getScanLibrary(scanFolder)
if err != nil {
t.log.Error().
t.log.Warn().
Err(err).
Msg("No target libraries found")
return fmt.Errorf("no target libraries found: %v: %w", err, autoscan.ErrFatal)

return nil
}

// send scan request
Expand Down

0 comments on commit 7c0cbf9

Please # to comment.