Class: Cuboid::RPC::Server::ApplicationWrapper
- Extended by:
- Forwardable
- Includes:
- Utilities
- Defined in:
- lib/cuboid/rpc/server/application_wrapper.rb
Overview
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#application ⇒ Object
readonly
Returns the value of attribute application.
Instance Method Summary collapse
-
#busy? ⇒ Bool
‘true` If the system is scanning, `false` if #run hasn’t been called yet or if the scan has finished.
- #clean_up ⇒ Object
- #error_test(str) ⇒ Object
- #errors(starting_line = 0) ⇒ Array<String>
-
#initialize(application) ⇒ ApplicationWrapper
constructor
A new instance of ApplicationWrapper.
-
#progress(opts = {}) ⇒ Hash
Provides aggregated progress data.
-
#run ⇒ Bool
‘false` if already running, `true` otherwise.
- #valid_options?(options) ⇒ Boolean
Methods included from Utilities
#available_port, available_port_mutex, #bytes_to_kilobytes, #bytes_to_megabytes, #caller_name, #caller_path, #exception_jail, #generate_token, #hms_to_seconds, #port_available?, #rand_port, #random_seed, #regexp_array_match, #remove_constants, #seconds_to_hms
Constructor Details
#initialize(application) ⇒ ApplicationWrapper
Returns a new instance of ApplicationWrapper.
31 32 33 34 35 36 |
# File 'lib/cuboid/rpc/server/application_wrapper.rb', line 31 def initialize( application ) super() @application = application.instance @extended_running = false end |
Instance Attribute Details
#application ⇒ Object (readonly)
Returns the value of attribute application.
15 16 17 |
# File 'lib/cuboid/rpc/server/application_wrapper.rb', line 15 def application @application end |
Instance Method Details
#busy? ⇒ Bool
Returns ‘true` If the system is scanning, `false` if #run hasn’t been called yet or if the scan has finished.
45 46 47 48 |
# File 'lib/cuboid/rpc/server/application_wrapper.rb', line 45 def busy? ![:ready, :done, :suspended].include?( @application.status ) && !!@extended_running end |
#clean_up ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/cuboid/rpc/server/application_wrapper.rb', line 65 def clean_up return false if @rpc_cleaned_up @rpc_cleaned_up = true @extended_running = false @application.clean_up end |
#error_test(str) ⇒ Object
131 132 133 |
# File 'lib/cuboid/rpc/server/application_wrapper.rb', line 131 def error_test( str ) @application.print_error str.to_s end |
#errors(starting_line = 0) ⇒ Array<String>
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/cuboid/rpc/server/application_wrapper.rb', line 78 def errors( starting_line = 0 ) return [] if UI::Output.error_buffer.empty? error_strings = UI::Output.error_buffer if starting_line != 0 error_strings = error_strings[starting_line..-1] end error_strings end |
#progress(opts = {}) ⇒ Hash
Provides aggregated progress data.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/cuboid/rpc/server/application_wrapper.rb', line 102 def progress( opts = {} ) opts = opts.my_symbolize_keys include_statistics = opts[:statistics].nil? ? true : opts[:statistics] include_errors = opts.include?( :errors ) ? (opts[:errors] || 0) : false data = { status: status, busy: running?, application: @application.class.to_s, seed: Utilities.random_seed, agent_url: Cuboid::Options.agent.url, scheduler_url: Cuboid::Options.scheduler.url } if include_statistics data[:statistics] = @application.statistics end if include_errors data[:errors] = errors( include_errors.is_a?( Integer ) ? include_errors : 0 ) end data.merge( messages: ) end |
#run ⇒ Bool
Returns ‘false` if already running, `true` otherwise.
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/cuboid/rpc/server/application_wrapper.rb', line 52 def run # Return if we're already running. return false if busy? @extended_running = true # Start the scan -- we can't block the RPC server so we're using a Thread. Thread.new do @application.run end true end |
#valid_options?(options) ⇒ Boolean
38 39 40 |
# File 'lib/cuboid/rpc/server/application_wrapper.rb', line 38 def ( ) @application.class.( ) end |