diff options
| author | mo khan <mo.khan@gmail.com> | 2020-06-03 23:10:28 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-06-03 23:10:28 -0600 |
| commit | b2f50360e39c73f7de31f4d83cac624fe0171c12 (patch) | |
| tree | 86d3a9b3a81984469b1e56b54839071de14f6f3e | |
| parent | d87fe100bc10acc385c82aa21d151b4ac516cbe4 (diff) | |
Use a threadpool to process each dependency
| -rw-r--r-- | Gemfile.lock | 4 | ||||
| -rw-r--r-- | lib/spandx.rb | 3 | ||||
| -rw-r--r-- | lib/spandx/cli.rb | 1 | ||||
| -rw-r--r-- | lib/spandx/cli/commands/scan.rb | 9 | ||||
| -rw-r--r-- | spandx.gemspec | 1 |
5 files changed, 14 insertions, 4 deletions
diff --git a/Gemfile.lock b/Gemfile.lock index c178a92..46d04df 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -4,6 +4,7 @@ PATH spandx (0.13.4) addressable (~> 2.7) bundler (>= 1.16, < 3.0.0) + concurrent-ruby (~> 1.1) nanospinner (~> 1.0.0) net-hippie (~> 0.3) nokogiri (~> 1.10) @@ -28,6 +29,7 @@ GEM bundler (>= 1.2.0, < 3) thor (~> 0.18) byebug (11.1.3) + concurrent-ruby (1.1.6) crack (0.4.3) safe_yaml (~> 1.0.0) diff-lcs (1.3) @@ -112,7 +114,7 @@ GEM unicode-display_width (~> 1.1, >= 1.1.1) thor (0.20.3) tomlrb (1.3.0) - tty-screen (0.7.1) + tty-screen (0.8.0) unicode-display_width (1.7.0) vcr (5.1.0) webmock (3.8.3) diff --git a/lib/spandx.rb b/lib/spandx.rb index d43ba77..b241864 100644 --- a/lib/spandx.rb +++ b/lib/spandx.rb @@ -2,7 +2,9 @@ require 'addressable/uri' require 'bundler' +require 'concurrent' require 'csv' +require 'etc' require 'forwardable' require 'json' require 'logger' @@ -13,7 +15,6 @@ require 'parslet' require 'pathname' require 'yaml' require 'zeitwerk' -require 'terminal-table' require 'spandx/spandx' loader = Zeitwerk::Loader.for_gem diff --git a/lib/spandx/cli.rb b/lib/spandx/cli.rb index 817ff89..eaab0d6 100644 --- a/lib/spandx/cli.rb +++ b/lib/spandx/cli.rb @@ -3,6 +3,7 @@ require 'nanospinner' require 'thor' require 'tty-screen' +require 'terminal-table' module Spandx module Cli diff --git a/lib/spandx/cli/commands/scan.rb b/lib/spandx/cli/commands/scan.rb index b54e73b..d55d2ce 100644 --- a/lib/spandx/cli/commands/scan.rb +++ b/lib/spandx/cli/commands/scan.rb @@ -16,14 +16,19 @@ module Spandx def execute(output: $stdout) printer = ::Spandx::Core::Printer.for(@options[:format]) printer.print_header(output) + pool = Concurrent::FixedThreadPool.new(Etc.nprocessors) each_file do |file| spinner.spin(file) ::Spandx::Core::Parser.parse(file).each do |dependency| - printer.print_line(enhance(dependency), output) + pool.post do + printer.print_line(enhance(dependency), output) + end end end - printer.print_footer(output) + pool.shutdown + pool.wait_for_termination spinner.stop + printer.print_footer(output) end private diff --git a/spandx.gemspec b/spandx.gemspec index 465b74c..3ea3821 100644 --- a/spandx.gemspec +++ b/spandx.gemspec @@ -34,6 +34,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'addressable', '~> 2.7' spec.add_dependency 'bundler', '>= 1.16', '< 3.0.0' + spec.add_dependency 'concurrent-ruby', '~> 1.1' spec.add_dependency 'nanospinner', '~> 1.0.0' spec.add_dependency 'net-hippie', '~> 0.3' spec.add_dependency 'nokogiri', '~> 1.10' |
