paraduct 0.0.1.beta7 → 0.0.1.beta8

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,20 +15,17 @@ module Paraduct
15
15
  ======================================================
16
16
  START matrix test
17
17
  EOS
18
- product_variables.each do |params|
19
- Paraduct.logger.info "params: #{params.map{ |key, value| "#{key}=#{value}" }.join(", ")}"
20
- end
21
18
 
22
19
  pool = Thread.pool(Paraduct.config.max_threads)
23
20
  begin
24
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
+ runner.logger.info "[START] params: #{runner.formatted_params}"
25
28
  pool.process do
26
- runner = Paraduct::Runner.new(
27
- script: script,
28
- params: params,
29
- base_job_dir: base_job_dir,
30
- )
31
-
32
29
  runner.setup_dir
33
30
  begin
34
31
  stdout = runner.perform
@@ -38,14 +35,7 @@ START matrix test
38
35
  successful = false
39
36
  end
40
37
 
41
- Paraduct.logger.info <<-EOS
42
- ======================================================
43
- params: #{runner.formatted_params}
44
- job_name: #{runner.job_name}
45
- job_dir: #{runner.job_dir}
46
-
47
- #{stdout}
48
- EOS
38
+ runner.logger.info "[END] params: #{runner.formatted_params}"
49
39
 
50
40
  test_response.jobs_push(
51
41
  job_name: runner.job_name,
@@ -56,7 +46,6 @@ job_dir: #{runner.job_dir}
56
46
  )
57
47
  end
58
48
  end
59
-
60
49
  ensure
61
50
  pool.shutdown
62
51
  end
@@ -3,7 +3,7 @@ module Paraduct
3
3
  require "open3"
4
4
 
5
5
  class Runner
6
- attr_reader :script, :params, :base_job_dir
6
+ attr_reader :script, :params, :base_job_dir, :logger
7
7
 
8
8
  # @param args
9
9
  # @option args :script [String, Array<String>] script file, script(s)
@@ -13,7 +13,7 @@ module Paraduct
13
13
  @script = args[:script]
14
14
  @params = args[:params]
15
15
  @base_job_dir = args[:base_job_dir]
16
- @color = Paraduct::Runner.next_color
16
+ @logger = Paraduct::ThreadLogger.new
17
17
  end
18
18
 
19
19
  def setup_dir
@@ -57,37 +57,13 @@ module Paraduct
57
57
  end
58
58
  end
59
59
 
60
- COLORS = [
61
- :cyan,
62
- :yellow,
63
- :green,
64
- :magenta,
65
- :red,
66
- :blue,
67
- :light,
68
- :cyan,
69
- :light_yellow,
70
- :light_green,
71
- :light_magenta,
72
- :light_red,
73
- :light_blue,
74
- ]
75
- def self.next_color
76
- @@color_index ||= -1
77
- @@color_index = (@@color_index + 1) % COLORS.length
78
- COLORS[@@color_index]
79
- end
80
-
81
60
  private
82
61
  def run_command(command)
83
- thread_id = Thread.current.object_id.to_s
84
- console_label = "[#{thread_id.colorize(@color)}]"
85
-
86
62
  lines = ""
87
63
 
88
64
  IO.popen(command) do |io|
89
65
  while line = io.gets
90
- Paraduct.logger.info "#{console_label} #{line.strip}"
66
+ @logger.info(line)
91
67
  lines << line
92
68
  end
93
69
  end
@@ -0,0 +1,41 @@
1
+ module Paraduct
2
+ class ThreadLogger < ::Logger
3
+ def initialize(logdev = STDOUT)
4
+ super(logdev)
5
+ thread_id = Thread.current.object_id.to_s
6
+ color = Paraduct::ThreadLogger.next_color
7
+ @label = "[#{thread_id.colorize(color)}]"
8
+ @formatter = ActiveSupport::Logger::SimpleFormatter.new
9
+ end
10
+
11
+ [:debug, :info, :warn, :error, :fatal].each do |severity|
12
+ define_method "#{severity}_with_label" do |message|
13
+ message.each_line do |line|
14
+ send "#{severity}_without_label", "#{@label} #{line.strip}" unless line.blank?
15
+ end
16
+ end
17
+ alias_method_chain severity, :label
18
+ end
19
+
20
+ COLORS = [
21
+ :cyan,
22
+ :yellow,
23
+ :green,
24
+ :magenta,
25
+ :red,
26
+ :blue,
27
+ :light,
28
+ :cyan,
29
+ :light_yellow,
30
+ :light_green,
31
+ :light_magenta,
32
+ :light_red,
33
+ :light_blue,
34
+ ]
35
+ def self.next_color
36
+ @@color_index ||= -1
37
+ @@color_index = (@@color_index + 1) % COLORS.length
38
+ COLORS[@@color_index]
39
+ end
40
+ end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module Paraduct
2
- VERSION = "0.0.1.beta7"
2
+ VERSION = "0.0.1.beta8"
3
3
  end
data/lib/paraduct.rb CHANGED
@@ -10,6 +10,7 @@ module Paraduct
10
10
  autoload :Runner , 'paraduct/runner'
11
11
  autoload :SyncUtils , 'paraduct/sync_utils'
12
12
  autoload :TestResponse , 'paraduct/test_response'
13
+ autoload :ThreadLogger , 'paraduct/thread_logger'
13
14
  autoload :VariableConverter, 'paraduct/variable_converter'
14
15
  autoload :Version , 'paraduct/version'
15
16
 
@@ -75,12 +75,4 @@ DATABASE=mysql
75
75
 
76
76
  it{ should eq "ruby=1.9, database=mysql" }
77
77
  end
78
-
79
- describe "#next_color" do
80
- it "can call many times" do
81
- 20.times do
82
- expect(Paraduct::Runner.next_color).to be_an_instance_of Symbol
83
- end
84
- end
85
- end
86
78
  end
@@ -0,0 +1,9 @@
1
+ describe Paraduct::ThreadLogger do
2
+ describe "#next_color" do
3
+ it "can call many times" do
4
+ 20.times do
5
+ expect(Paraduct::ThreadLogger.next_color).to be_an_instance_of Symbol
6
+ end
7
+ end
8
+ end
9
+ 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.beta7
4
+ version: 0.0.1.beta8
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -329,6 +329,7 @@ files:
329
329
  - lib/paraduct/templates/.paraduct.yml.tt
330
330
  - lib/paraduct/templates/.paraduct_rsync_exclude.txt.tt
331
331
  - lib/paraduct/test_response.rb
332
+ - lib/paraduct/thread_logger.rb
332
333
  - lib/paraduct/variable_converter.rb
333
334
  - lib/paraduct/version.rb
334
335
  - paraduct.gemspec
@@ -341,6 +342,7 @@ files:
341
342
  - spec/paraduct/runner_spec.rb
342
343
  - spec/paraduct/sync_utils_spec.rb
343
344
  - spec/paraduct/test_response_spec.rb
345
+ - spec/paraduct/thread_logger_spec.rb
344
346
  - spec/paraduct/variable_converter_spec.rb
345
347
  - spec/paraduct_spec.rb
346
348
  - spec/script/build_error.sh
@@ -367,7 +369,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
367
369
  version: '0'
368
370
  segments:
369
371
  - 0
370
- hash: 3862644888547862433
372
+ hash: 965454421282758881
371
373
  required_rubygems_version: !ruby/object:Gem::Requirement
372
374
  none: false
373
375
  requirements:
@@ -390,6 +392,7 @@ test_files:
390
392
  - spec/paraduct/runner_spec.rb
391
393
  - spec/paraduct/sync_utils_spec.rb
392
394
  - spec/paraduct/test_response_spec.rb
395
+ - spec/paraduct/thread_logger_spec.rb
393
396
  - spec/paraduct/variable_converter_spec.rb
394
397
  - spec/paraduct_spec.rb
395
398
  - spec/script/build_error.sh