Class: CC::Analyzer::Engine
- Inherits:
-
Object
- Object
- CC::Analyzer::Engine
- Defined in:
- lib/cc/analyzer/engine.rb
Constant Summary collapse
- TIMEOUT =
15m
15 * 60
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, metadata, code_path, config_json, label) ⇒ Engine
constructor
A new instance of Engine.
- #run(stdout_io, stderr_io = StringIO.new) ⇒ Object
Constructor Details
#initialize(name, metadata, code_path, config_json, label) ⇒ Engine
Returns a new instance of Engine.
11 12 13 14 15 16 17 |
# File 'lib/cc/analyzer/engine.rb', line 11 def initialize(name, , code_path, config_json, label) @name = name @metadata = @code_path = code_path @config_json = config_json @label = label.to_s end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/cc/analyzer/engine.rb', line 7 def name @name end |
Instance Method Details
#run(stdout_io, stderr_io = StringIO.new) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/cc/analyzer/engine.rb', line 19 def run(stdout_io, stderr_io = StringIO.new) pid, _, out, err = POSIX::Spawn.popen4(*docker_run_command) engine_running = true Analyzer.statsd.increment("cli.engines.started") t_out = Thread.new do out.each_line("\0") do |chunk| stdout_io.write(chunk.chomp("\0")) end end t_err = Thread.new do err.each_line do |line| if stderr_io stderr_io.write(line) end end end Thread.new do sleep TIMEOUT if engine_running Thread.current.abort_on_exception = true run_command("docker kill #{container_name}") Analyzer.statsd.increment("cli.engines.result.error") Analyzer.statsd.increment("cli.engines.result.error.timeout") Analyzer.statsd.increment("cli.engines.names.#{name}.result.error") Analyzer.statsd.increment("cli.engines.names.#{name}.result.error.timeout") raise EngineTimeout, "engine #{name} ran past #{TIMEOUT} seconds and was killed" end end pid, status = Process.waitpid2(pid) engine_running = false Analyzer.statsd.increment("cli.engines.finished") if status.success? Analyzer.statsd.increment("cli.engines.names.#{name}.result.success") Analyzer.statsd.increment("cli.engines.result.success") else Analyzer.statsd.increment("cli.engines.names.#{name}.result.error") Analyzer.statsd.increment("cli.engines.result.error") raise EngineFailure, "engine #{name} failed with status #{status.exitstatus} and stderr #{stderr_io.string.inspect}" end ensure t_out.join if t_out t_err.join if t_err end |