Class: Burden::Statistics
- Inherits:
-
Object
- Object
- Burden::Statistics
- Defined in:
- lib/burden/statistics.rb
Instance Attribute Summary collapse
-
#execution_time ⇒ Object
readonly
Returns the value of attribute execution_time.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#success ⇒ Object
readonly
Returns the value of attribute success.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
-
#initialize(params) ⇒ Statistics
constructor
A new instance of Statistics.
- #log_to_stdout(reason = :no_rails) ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(params) ⇒ Statistics
Returns a new instance of Statistics.
5 6 7 8 9 10 |
# File 'lib/burden/statistics.rb', line 5 def initialize(params) @name = params[:name] @success = params[:success] @execution_time = params[:execution_time] @timestamp = params[:timestamp] end |
Instance Attribute Details
#execution_time ⇒ Object (readonly)
Returns the value of attribute execution_time.
3 4 5 |
# File 'lib/burden/statistics.rb', line 3 def execution_time @execution_time end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/burden/statistics.rb', line 3 def name @name end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
3 4 5 |
# File 'lib/burden/statistics.rb', line 3 def success @success end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
3 4 5 |
# File 'lib/burden/statistics.rb', line 3 def @timestamp end |
Instance Method Details
#log_to_stdout(reason = :no_rails) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/burden/statistics.rb', line 28 def log_to_stdout(reason = :no_rails) puts puts "------------------------------------------------------------" case reason when :no_rails puts "Rails environment is not loaded. Sending output to STDOUT" when :failed puts "Failed to persist this run. Sending output to STDOUT" end puts "Task #{name} #{success ? 'finished successfully' : 'failed'}" puts "Execution time: #{execution_time.round(4)}" end |
#save ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/burden/statistics.rb', line 12 def save if defined?(Rails) && Rails.respond_to?(:application) && Rails.application.present? # FIXME: Dirty stuff conf = Rails.configuration.database_configuration[Rails.env] ActiveRecord::Base.establish_connection(conf) begin Storage.run.create(name: name, success: success, execution_time: execution_time, timestamp: ) rescue log_to_stdout(:failed) end else log_to_stdout(:no_rails) end end |