Class: ContainedMr::Mock::Runner
- Inherits:
-
Object
- Object
- ContainedMr::Mock::Runner
- Includes:
- RunnerLogic
- Defined in:
- lib/contained_mr/mock/runner.rb
Overview
Instance Attribute Summary collapse
-
#_container_options ⇒ Hash<String, Object>
readonly
The options passed to the constructor.
-
#_output_path ⇒ Hash<String, Object>
readonly
The output path passed to the constructor.
-
#_time_limit ⇒ Hash<String, Object>
readonly
The time limit passed to the constructor.
Attributes included from RunnerLogic
#container_id, #ended_at, #output, #started_at, #status_code, #stderr, #stdout, #timed_out
Instance Method Summary collapse
-
#_logs ⇒ Number
Convenience method for looking up the log size limit in container options.
-
#_mock_set(attributes) ⇒ ContainedMr::Runner
Sets the container execution data returned by the mock.
-
#_ram_limit ⇒ Number
Convenience method for looking up the RAM limit in the container options.
-
#_swap_limit ⇒ Number
Convenience method for looking up the swap limit in the container options.
-
#_ulimit(name) ⇒ Number
Convenience method for looking up an ulimit in the container options.
-
#_vcpus ⇒ Number
Convenience method for looking up CPU allocation in the container options.
- #destroy! ⇒ Object
-
#destroyed? ⇒ Boolean
True if #destroy! was called.
-
#initialize(container_options, time_limit, output_path) ⇒ Runner
constructor
A new instance of Runner.
- #perform ⇒ Object
-
#performed? ⇒ Boolean
True if #perform was called.
Methods included from RunnerLogic
Constructor Details
#initialize(container_options, time_limit, output_path) ⇒ Runner
Returns a new instance of Runner.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/contained_mr/mock/runner.rb', line 23 def initialize(, time_limit, output_path) @_container_options = @_time_limit = time_limit @_output_path = output_path @container_id = nil @started_at = @ended_at = nil @status_code = nil @timed_out = nil @stdout = @stderr = nil @output = nil @performed = false @destroyed = false end |
Instance Attribute Details
#_container_options ⇒ Hash<String, Object> (readonly)
Returns the options passed to the constructor.
4 5 6 |
# File 'lib/contained_mr/mock/runner.rb', line 4 def @_container_options end |
#_output_path ⇒ Hash<String, Object> (readonly)
Returns the output path passed to the constructor.
8 9 10 |
# File 'lib/contained_mr/mock/runner.rb', line 8 def _output_path @_output_path end |
#_time_limit ⇒ Hash<String, Object> (readonly)
Returns the time limit passed to the constructor.
6 7 8 |
# File 'lib/contained_mr/mock/runner.rb', line 6 def _time_limit @_time_limit end |
Instance Method Details
#_logs ⇒ Number
Convenience method for looking up the log size limit in container options.
122 123 124 125 126 127 128 129 |
# File 'lib/contained_mr/mock/runner.rb', line 122 def _logs return nil unless host_config = @_container_options['HostConfig'] return nil unless log_config = host_config['LogConfig'] return nil unless config = log_config['Config'] return nil unless max_size = config['max-size'] max_size.to_i / (1024 * 1024).to_f end |
#_mock_set(attributes) ⇒ ContainedMr::Runner
Sets the container execution data returned by the mock.
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/contained_mr/mock/runner.rb', line 56 def _mock_set(attributes) @started_at = attributes[:started_at] @ended_at = attributes[:ended_at] @status_code = attributes[:status_code] @timed_out = attributes[:timed_out] @stdout = attributes[:stdout] @stderr = attributes[:stderr] @output = attributes[:output] self end |
#_ram_limit ⇒ Number
Convenience method for looking up the RAM limit in the container options.
90 91 92 93 94 |
# File 'lib/contained_mr/mock/runner.rb', line 90 def _ram_limit return nil unless host_config = @_container_options['HostConfig'] return nil unless memory = host_config['Memory'] memory / (1024 * 1024).to_f end |
#_swap_limit ⇒ Number
Convenience method for looking up the swap limit in the container options.
99 100 101 102 103 104 105 |
# File 'lib/contained_mr/mock/runner.rb', line 99 def _swap_limit return nil unless host_config = @_container_options['HostConfig'] return nil unless memory = host_config['Memory'] return nil unless memory_swap = host_config['MemorySwap'] (memory_swap - memory) / (1024 * 1024).to_f end |
#_ulimit(name) ⇒ Number
Convenience method for looking up an ulimit in the container options.
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/contained_mr/mock/runner.rb', line 73 def _ulimit(name) return nil unless ulimits = @_container_options['Ulimits'] ulimits.each do |ulimit| if ulimit['Name'] == name if ulimit['Hard'] != ulimit['Soft'] raise RuntimeError, "Hard/soft ulimit mismatch for #{name}" end return ulimit['Hard'] end end nil end |
#_vcpus ⇒ Number
Convenience method for looking up CPU allocation in the container options.
111 112 113 114 115 116 117 |
# File 'lib/contained_mr/mock/runner.rb', line 111 def _vcpus return nil unless host_config = @_container_options['HostConfig'] return nil unless period = host_config['CpuPeriod'] return nil unless quota = host_config['CpuQuota'] quota / period.to_f end |
#destroy! ⇒ Object
46 47 48 49 |
# File 'lib/contained_mr/mock/runner.rb', line 46 def destroy! @destroyed = true self end |
#destroyed? ⇒ Boolean
Returns true if #destroy! was called.
16 17 18 |
# File 'lib/contained_mr/mock/runner.rb', line 16 def destroyed? @destroyed end |
#perform ⇒ Object
40 41 42 43 |
# File 'lib/contained_mr/mock/runner.rb', line 40 def perform @performed = true self end |
#performed? ⇒ Boolean
Returns true if #perform was called.
11 12 13 |
# File 'lib/contained_mr/mock/runner.rb', line 11 def performed? @performed end |