Class: CC::Analyzer::Engine
- Inherits:
-
Object
- Object
- CC::Analyzer::Engine
- Defined in:
- lib/cc/analyzer/engine.rb
Constant Summary collapse
- EngineFailure =
Class.new(StandardError)
- EngineTimeout =
Class.new(StandardError)
- DEFAULT_MEMORY_LIMIT =
512_000_000.freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, metadata, code_path, config, label) ⇒ Engine
constructor
A new instance of Engine.
- #run(stdout_io, container_listener) ⇒ Object
Constructor Details
#initialize(name, metadata, code_path, config, label) ⇒ Engine
Returns a new instance of Engine.
13 14 15 16 17 18 19 |
# File 'lib/cc/analyzer/engine.rb', line 13 def initialize(name, , code_path, config, label) @name = name @metadata = @code_path = code_path @config = config @label = label.to_s end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/cc/analyzer/engine.rb', line 9 def name @name end |
Instance Method Details
#run(stdout_io, container_listener) ⇒ Object
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 |
# File 'lib/cc/analyzer/engine.rb', line 21 def run(stdout_io, container_listener) composite_listener = CompositeContainerListener.new( container_listener, LoggingContainerListener.new(qualified_name, Analyzer.logger), StatsdContainerListener.new(qualified_name.tr(":", "."), Analyzer.statsd), RaisingContainerListener.new(qualified_name, EngineFailure, EngineTimeout), ) container = Container.new( image: @metadata["image"], command: @metadata["command"], name: container_name, listener: composite_listener, ) container.on_output("\0") do |raw_output| CLI.debug("#{qualified_name} engine output: #{raw_output.strip}") output = EngineOutput.new(raw_output) unless output.valid? stdout_io.failed("#{qualified_name} produced invalid output: #{output.error[:message]}") container.stop end unless output_filter.filter?(output) stdout_io.write(output.to_json) || container.stop end end write_config_file CLI.debug("#{qualified_name} engine config: #{config_file.read}") container.run().tap do |result| CLI.debug("#{qualified_name} engine stderr: #{result.stderr}") end rescue Container::ImageRequired # Provide a clearer message given the context we have = "Unable to find an image for #{qualified_name}." << " Available channels: #{@metadata["channels"].keys.inspect}." raise Container::ImageRequired, ensure delete_config_file end |