paraduct 0.0.1.beta4 → 0.0.1.beta5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -65,6 +65,7 @@ variables:
65
65
  name2:
66
66
  - value2a
67
67
  - value2b
68
+ max_threads: 4
68
69
  ```
69
70
 
70
71
  ### script
@@ -88,6 +89,9 @@ value1a | value2b | NAME1_value1a_NAME2_value2b | tmp/paraduct_workspace/NAME1
88
89
  value1b | value2a | NAME1_value1b_NAME2_value2a | tmp/paraduct_workspace/NAME1_value1b_NAME2_value2a
89
90
  value1b | value2b | NAME1_value1b_NAME2_value2b | tmp/paraduct_workspace/NAME1_value1b_NAME2_value2b
90
91
 
92
+ ### max_threads
93
+ maximum concurrent execution number of jobs
94
+
91
95
  ## Contributing
92
96
 
93
97
  1. Fork it ( https://github.com/sue445/paraduct/fork )
data/lib/paraduct.rb CHANGED
@@ -1,20 +1,25 @@
1
1
  require "active_support"
2
2
  require "active_support/deprecation"
3
3
  require "active_support/core_ext"
4
- require "paraduct/version"
5
- require "paraduct/configuration"
6
- require "paraduct/variable_converter"
7
- require "paraduct/runner"
8
- require "paraduct/parallel_runner"
9
- require "paraduct/errors"
10
- require "paraduct/test_response"
11
4
  require "pathname"
12
5
 
13
6
  module Paraduct
7
+ autoload :Configuration , 'paraduct/configuration'
8
+ autoload :Errors , 'paraduct/errors'
9
+ autoload :ParallelRunner , 'paraduct/parallel_runner'
10
+ autoload :Runner , 'paraduct/runner'
11
+ autoload :TestResponse , 'paraduct/test_response'
12
+ autoload :VariableConverter, 'paraduct/variable_converter'
13
+ autoload :Version , 'paraduct/version'
14
+
14
15
  class << self
15
16
  def configuration
16
17
  Paraduct::Configuration.instance
17
18
  end
18
19
  alias :config :configuration
20
+
21
+ def logger
22
+ @logger ||= ActiveSupport::Logger.new(STDOUT)
23
+ end
19
24
  end
20
25
  end
data/lib/paraduct/cli.rb CHANGED
@@ -15,8 +15,8 @@ module Paraduct
15
15
 
16
16
  product_variables = Paraduct::VariableConverter.product(variables)
17
17
  test_response = Paraduct::ParallelRunner.perform_all(script, product_variables)
18
- puts test_response.detail_message
19
- raise Paraduct::TestFailureError if test_response.failure?
18
+ Paraduct.logger.info test_response.detail_message
19
+ raise Paraduct::Errors::TestFailureError if test_response.failure?
20
20
  end
21
21
 
22
22
  desc "generate", "generate .paraduct.yml"
@@ -20,6 +20,11 @@ module Paraduct
20
20
  @config["script"]
21
21
  end
22
22
 
23
+ # @return [Integer]
24
+ def max_threads
25
+ @config["max_threads"] || 4
26
+ end
27
+
23
28
  # @return [Pathname]
24
29
  def work_dir
25
30
  _work_dir = @config["work_dir"] || "tmp/paraduct_workspace"
@@ -1,14 +1,16 @@
1
1
  module Paraduct
2
- class TestFailureError < StandardError; end
2
+ module Errors
3
+ class TestFailureError < StandardError; end
3
4
 
4
- class ProcessError < StandardError
5
- attr_reader :status
5
+ class ProcessError < StandardError
6
+ attr_reader :status
6
7
 
7
- # @param message [String] stdout and stderr
8
- # @param status [Process::Status]
9
- def initialize(message, status)
10
- super(message)
11
- @status = status
8
+ # @param message [String] stdout and stderr
9
+ # @param status [Process::Status]
10
+ def initialize(message, status)
11
+ super(message)
12
+ @status = status
13
+ end
12
14
  end
13
15
  end
14
16
  end
@@ -1,58 +1,65 @@
1
1
  module Paraduct
2
+ require "thread/pool"
3
+
2
4
  class ParallelRunner
3
5
  # run script with arguments
4
6
  # @param script [String, Array<String>] script file, script(s)
5
7
  # @param product_variables [Array<Hash{String => String}>]
6
8
  # @return [Paraduct::TestResponse]
7
9
  def self.perform_all(script, product_variables)
8
- threads = []
9
10
  test_response = Paraduct::TestResponse.new
10
11
  base_job_dir = Paraduct.config.work_dir
11
12
  FileUtils.mkdir_p(base_job_dir) unless base_job_dir.exist?
12
13
 
13
- puts <<-EOS
14
+ Paraduct.logger.info <<-EOS
14
15
  ======================================================
15
16
  START matrix test
16
17
  EOS
17
18
  product_variables.each do |params|
18
- puts "params: #{params}"
19
+ Paraduct.logger.info "params: #{params}"
19
20
  end
20
21
 
21
- product_variables.each do |params|
22
- runner = Paraduct::Runner.new(
23
- script: script,
24
- params: params,
25
- base_job_dir: base_job_dir,
26
- )
27
- threads << Thread.new(runner) do |_runner|
28
- _runner.setup_dir
29
- begin
30
- stdout = _runner.perform
31
- successful = true
32
- rescue Paraduct::ProcessError => e
33
- stdout = e.message
34
- successful = false
35
- end
22
+ pool = Thread.pool(Paraduct.config.max_threads)
23
+ begin
24
+ product_variables.each do |params|
25
+ pool.process do
26
+ runner = Paraduct::Runner.new(
27
+ script: script,
28
+ params: params,
29
+ base_job_dir: base_job_dir,
30
+ )
31
+
32
+ runner.setup_dir
33
+ begin
34
+ stdout = runner.perform
35
+ successful = true
36
+ rescue Paraduct::Errors::ProcessError => e
37
+ stdout = e.message
38
+ successful = false
39
+ end
36
40
 
37
- puts <<-EOS
41
+ Paraduct.logger.info <<-EOS
38
42
  ======================================================
39
- params: #{_runner.formatted_params}
40
- job_name: #{_runner.job_name}
41
- job_dir: #{_runner.job_dir}
42
-
43
- #{stdout}
44
- EOS
45
-
46
- test_response.jobs_push(
47
- job_name: _runner.job_name,
48
- params: _runner.params,
49
- formatted_params: _runner.formatted_params,
50
- successful: successful,
51
- stdout: stdout,
52
- )
43
+ params: #{runner.formatted_params}
44
+ job_name: #{runner.job_name}
45
+ job_dir: #{runner.job_dir}
46
+
47
+ #{stdout}
48
+ EOS
49
+
50
+ test_response.jobs_push(
51
+ job_name: runner.job_name,
52
+ params: runner.params,
53
+ formatted_params: runner.formatted_params,
54
+ successful: successful,
55
+ stdout: stdout,
56
+ )
57
+ end
53
58
  end
59
+
60
+ ensure
61
+ pool.shutdown
54
62
  end
55
- threads.map(&:join)
56
63
 
57
64
  test_response
58
65
  end
@@ -22,7 +22,7 @@ module Paraduct
22
22
 
23
23
  # run script with params
24
24
  # @return [String] stdout
25
- # @raise [Paraduct::ProcessError] command exited error status
25
+ # @raise [Paraduct::Errors::ProcessError] command exited error status
26
26
  def perform
27
27
  variable_string = key_capitalized_params.map{ |key, value| %(export #{key}="#{value}";) }.join(" ")
28
28
 
@@ -72,7 +72,7 @@ module Paraduct
72
72
  private
73
73
  def run_command(command)
74
74
  stdout, stderr, status = Open3.capture3(command)
75
- raise Paraduct::ProcessError.new("#{stdout}\n#{stderr}", status) unless status.success?
75
+ raise Paraduct::Errors::ProcessError.new("#{stdout}\n#{stderr}", status) unless status.success?
76
76
  stdout
77
77
  end
78
78
  end
@@ -8,3 +8,4 @@ variables:
8
8
  name2:
9
9
  - value2a
10
10
  - value2b
11
+ max_threads: 4
@@ -1,3 +1,3 @@
1
1
  module Paraduct
2
- VERSION = "0.0.1.beta4"
2
+ VERSION = "0.0.1.beta5"
3
3
  end
data/paraduct.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "activesupport"
22
22
  spec.add_dependency "thor"
23
+ spec.add_dependency "thread"
23
24
 
24
25
  spec.add_development_dependency "bundler", ">= 1.5"
25
26
  spec.add_development_dependency "codeclimate-test-reporter"
data/spec/.paraduct.yml CHANGED
@@ -12,3 +12,4 @@ variables:
12
12
  - 3.2.0
13
13
  - 4.0.0
14
14
  - 4.1.0
15
+ max_threads: 4
@@ -51,7 +51,7 @@ describe Paraduct::CLI do
51
51
  allow(Paraduct.config).to receive(:variables){ { status: [0, 1] } }
52
52
  end
53
53
 
54
- it { expect{ subject }.to raise_error Paraduct::TestFailureError }
54
+ it { expect{ subject }.to raise_error Paraduct::Errors::TestFailureError }
55
55
  end
56
56
  end
57
57
 
@@ -44,7 +44,7 @@ DATABASE=mysql
44
44
  EOS
45
45
  end
46
46
 
47
- it { expect{ subject }.to raise_error(Paraduct::ProcessError, stdout) }
47
+ it { expect{ subject }.to raise_error(Paraduct::Errors::ProcessError, stdout) }
48
48
  end
49
49
  end
50
50
 
data/spec/spec_helper.rb CHANGED
@@ -119,6 +119,6 @@ RSpec.configure do |config|
119
119
 
120
120
  config.before do
121
121
  # quiet
122
- allow(Object).to receive(:puts)
122
+ allow(Paraduct.logger).to receive(:info)
123
123
  end
124
124
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paraduct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.beta4
4
+ version: 0.0.1.beta5
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-19 00:00:00.000000000 Z
12
+ date: 2014-10-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: thread
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: bundler
48
64
  requirement: !ruby/object:Gem::Requirement
@@ -313,7 +329,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
313
329
  version: '0'
314
330
  segments:
315
331
  - 0
316
- hash: 3632247312778024801
332
+ hash: 981450971291940130
317
333
  required_rubygems_version: !ruby/object:Gem::Requirement
318
334
  none: false
319
335
  requirements: