Class: Mamiya::Agent::Tasks::Abstract
- Inherits:
-
Object
- Object
- Mamiya::Agent::Tasks::Abstract
- Defined in:
- lib/mamiya/agent/tasks/abstract.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#task ⇒ Object
readonly
Returns the value of attribute task.
-
#task_queue ⇒ Object
readonly
Returns the value of attribute task_queue.
Class Method Summary collapse
Instance Method Summary collapse
- #after ⇒ Object
- #before ⇒ Object
- #errored ⇒ Object
- #execute ⇒ Object
-
#initialize(task_queue, task, agent: nil, logger: Mamiya::Logger.new, raise_error: false) ⇒ Abstract
constructor
A new instance of Abstract.
- #raise_error? ⇒ Boolean
- #run ⇒ Object
- #task_id ⇒ Object
Constructor Details
#initialize(task_queue, task, agent: nil, logger: Mamiya::Logger.new, raise_error: false) ⇒ Abstract
Returns a new instance of Abstract.
7 8 9 10 11 12 13 14 |
# File 'lib/mamiya/agent/tasks/abstract.rb', line 7 def initialize(task_queue, task, agent: nil, logger: Mamiya::Logger.new, raise_error: false) @agent = agent @task_queue = task_queue @task = task.merge('task' => self.class.identifier) @error = nil @raise_error = raise_error @logger = logger["#{self.class.identifier}:#{self.task_id}"] end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
20 21 22 |
# File 'lib/mamiya/agent/tasks/abstract.rb', line 20 def agent @agent end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
20 21 22 |
# File 'lib/mamiya/agent/tasks/abstract.rb', line 20 def error @error end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
20 21 22 |
# File 'lib/mamiya/agent/tasks/abstract.rb', line 20 def logger @logger end |
#task ⇒ Object (readonly)
Returns the value of attribute task.
20 21 22 |
# File 'lib/mamiya/agent/tasks/abstract.rb', line 20 def task @task end |
#task_queue ⇒ Object (readonly)
Returns the value of attribute task_queue.
20 21 22 |
# File 'lib/mamiya/agent/tasks/abstract.rb', line 20 def task_queue @task_queue end |
Class Method Details
.identifier ⇒ Object
16 17 18 |
# File 'lib/mamiya/agent/tasks/abstract.rb', line 16 def self.identifier self.name.split(/::/).last.gsub(/(.)([A-Z])/, '\1_\2').downcase end |
Instance Method Details
#after ⇒ Object
51 52 |
# File 'lib/mamiya/agent/tasks/abstract.rb', line 51 def after end |
#before ⇒ Object
45 46 |
# File 'lib/mamiya/agent/tasks/abstract.rb', line 45 def before end |
#errored ⇒ Object
54 55 |
# File 'lib/mamiya/agent/tasks/abstract.rb', line 54 def errored end |
#execute ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mamiya/agent/tasks/abstract.rb', line 30 def execute @logger.info "Task started: #{task.inspect}" before run rescue Exception => error @error = error raise if raise_error? errored @logger.error "Encountered error: #{error.inspect}\n\t#{error.backtrace.join("\n\t")}" ensure enqueue_chained unless error after @logger.info "Task finished" end |
#raise_error? ⇒ Boolean
22 23 24 |
# File 'lib/mamiya/agent/tasks/abstract.rb', line 22 def raise_error? !!@raise_error end |
#run ⇒ Object
48 49 |
# File 'lib/mamiya/agent/tasks/abstract.rb', line 48 def run end |
#task_id ⇒ Object
26 27 28 |
# File 'lib/mamiya/agent/tasks/abstract.rb', line 26 def task_id task['id'] || "0x#{self.__id__.to_s(16)}" end |