Class: Scripter::Base
- Inherits:
-
Object
- Object
- Scripter::Base
- Includes:
- EnvVariables, Errors, IterationHistory, Logger
- Defined in:
- lib/scripter/base.rb
Instance Attribute Summary
Attributes included from IterationHistory
Attributes included from Logger
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize {|_self| ... } ⇒ Base
constructor
A new instance of Base.
- #perform_iteration(iteration_id, iteration_meta = {}, verbose = true) ⇒ Object
- #with_fault_monitoring ⇒ Object
Methods included from IterationHistory
#iteration_processed!, #iteration_processed?
Methods included from EnvVariables
included, #raw_env_variables, #type_cast_env_variable
Methods included from Logger
Methods included from Errors
#add_error, #errors, #errors_count, #errors_grouped, #invalid?, #valid?
Constructor Details
#initialize {|_self| ... } ⇒ Base
Returns a new instance of Base.
19 20 21 22 |
# File 'lib/scripter/base.rb', line 19 def initialize yield self if block_given? self end |
Class Method Details
.execute(iteration_function_name = :execute) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/scripter/base.rb', line 24 def self.execute(iteration_function_name=:execute) self.new do |scripter_instance| # exits immediately without raising an exception on ctrl+c trap("SIGINT") { exit! } scripter_instance.with_fault_monitoring do scripter_instance.public_send(iteration_function_name) end scripter_instance.on_exit if scripter_instance.respond_to?(:on_exit) end end |
.set_custom_executable_name(name) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/scripter/base.rb', line 11 def self.set_custom_executable_name(name) class_eval %{ def self.#{name} self.execute(:#{name}) end } end |
Instance Method Details
#perform_iteration(iteration_id, iteration_meta = {}, verbose = true) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/scripter/base.rb', line 49 def perform_iteration(iteration_id, ={}, verbose=true) @iteration_idx = (@iteration_idx || 0) + 1 begin unless iteration_processed?(iteration_id) yield iteration_processed!(iteration_id) end rescue Exception => error add_error(error, , verbose) if @iteration_idx == 100 && errors_count > 50 raise "Iteration was interrupted as error rate was too big (#{errors_count.to_f / @iteration_idx.to_f * 100.0}%)" end end end |
#with_fault_monitoring ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/scripter/base.rb', line 37 def with_fault_monitoring log :info, "============================================== START ==============================================" begin log :info, "Performing: #{self.inspect}" yield rescue Exception => error add_error(error) ensure log :info, "=============================================== END ===============================================" end end |