Class: AethernalAgent::Operation
- Inherits:
-
Object
- Object
- AethernalAgent::Operation
- Defined in:
- lib/aethernal_agent/operation.rb
Instance Attribute Summary collapse
-
#backtrace ⇒ Object
Returns the value of attribute backtrace.
-
#completed_at ⇒ Object
Returns the value of attribute completed_at.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#exception ⇒ Object
Returns the value of attribute exception.
-
#method ⇒ Object
Returns the value of attribute method.
-
#options ⇒ Object
Returns the value of attribute options.
-
#plugin_name ⇒ Object
Returns the value of attribute plugin_name.
-
#result ⇒ Object
Returns the value of attribute result.
-
#started_at ⇒ Object
Returns the value of attribute started_at.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Instance Method Summary collapse
- #attributes ⇒ Object
- #failed? ⇒ Boolean
-
#initialize(plugin_name, method, options) ⇒ Operation
constructor
A new instance of Operation.
- #is_completed? ⇒ Boolean
- #is_started? ⇒ Boolean
- #run ⇒ Object
- #success? ⇒ Boolean
- #to_json(options = {}) ⇒ Object
Constructor Details
#initialize(plugin_name, method, options) ⇒ Operation
Returns a new instance of Operation.
4 5 6 7 8 9 |
# File 'lib/aethernal_agent/operation.rb', line 4 def initialize(plugin_name, method, ) self.plugin_name = plugin_name self.method = method self. = self.uuid = SecureRandom.uuid end |
Instance Attribute Details
#backtrace ⇒ Object
Returns the value of attribute backtrace.
2 3 4 |
# File 'lib/aethernal_agent/operation.rb', line 2 def backtrace @backtrace end |
#completed_at ⇒ Object
Returns the value of attribute completed_at.
2 3 4 |
# File 'lib/aethernal_agent/operation.rb', line 2 def completed_at @completed_at end |
#errors ⇒ Object
Returns the value of attribute errors.
2 3 4 |
# File 'lib/aethernal_agent/operation.rb', line 2 def errors @errors end |
#exception ⇒ Object
Returns the value of attribute exception.
2 3 4 |
# File 'lib/aethernal_agent/operation.rb', line 2 def exception @exception end |
#method ⇒ Object
Returns the value of attribute method.
2 3 4 |
# File 'lib/aethernal_agent/operation.rb', line 2 def method @method end |
#options ⇒ Object
Returns the value of attribute options.
2 3 4 |
# File 'lib/aethernal_agent/operation.rb', line 2 def @options end |
#plugin_name ⇒ Object
Returns the value of attribute plugin_name.
2 3 4 |
# File 'lib/aethernal_agent/operation.rb', line 2 def plugin_name @plugin_name end |
#result ⇒ Object
Returns the value of attribute result.
2 3 4 |
# File 'lib/aethernal_agent/operation.rb', line 2 def result @result end |
#started_at ⇒ Object
Returns the value of attribute started_at.
2 3 4 |
# File 'lib/aethernal_agent/operation.rb', line 2 def started_at @started_at end |
#uuid ⇒ Object
Returns the value of attribute uuid.
2 3 4 |
# File 'lib/aethernal_agent/operation.rb', line 2 def uuid @uuid end |
Instance Method Details
#attributes ⇒ Object
44 45 46 |
# File 'lib/aethernal_agent/operation.rb', line 44 def attributes {method: self.method, plugin_name: self.plugin_name, options: self., uuid: self.uuid, result: self.result, success: self.success?, failed: self.failed?, is_completed: self.is_completed?, errors: self.errors, exception: self.exception, backtrace: self.backtrace, completed_at: self.completed_at, started_at: self.started_at} end |
#failed? ⇒ Boolean
32 33 34 |
# File 'lib/aethernal_agent/operation.rb', line 32 def failed? !self.exception.nil? || !self.errors.blank? end |
#is_completed? ⇒ Boolean
36 37 38 |
# File 'lib/aethernal_agent/operation.rb', line 36 def is_completed? !self.completed_at.nil? end |
#is_started? ⇒ Boolean
40 41 42 |
# File 'lib/aethernal_agent/operation.rb', line 40 def is_started? !self.started_at.nil? end |
#run ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/aethernal_agent/operation.rb', line 11 def run self.started_at = Time.now begin plugin = "AethernalAgent::#{self.plugin_name.camelcase}".constantize.new(self.) self.result = plugin.send(self.method, self.) if self.result.is_a?(Hash) && self.result.has_key?(:errors) self.errors = self.result[:errors] end rescue StandardError => e self.exception = e. self.backtrace = e.backtrace end self.completed_at = Time.now end |
#success? ⇒ Boolean
28 29 30 |
# File 'lib/aethernal_agent/operation.rb', line 28 def success? !self.failed? end |
#to_json(options = {}) ⇒ Object
48 49 50 |
# File 'lib/aethernal_agent/operation.rb', line 48 def to_json( ={}) self.attributes.to_json end |