Class: Lipsiadmin::Loops::Base
- Inherits:
-
Object
- Object
- Lipsiadmin::Loops::Base
- Defined in:
- lib/loops/base.rb
Overview
This is the base class for make a simple loop with its own custom run method
Examples:
class SimpleLoop < Lipsiadmin::Loops::Base
def run
debug(Time.now)
end
end
Instance Attribute Summary collapse
-
#config ⇒ Object
:nodoc:.
-
#logger ⇒ Object
:nodoc:.
-
#name ⇒ Object
:nodoc:.
Class Method Summary collapse
-
.check_dependencies ⇒ Object
Ovveride this method for check dependencies.
Instance Method Summary collapse
-
#initialize(logger) ⇒ Base
constructor
The initialize method, default we pass the logger.
-
#with_lock(entity_id, loop_id, timeout, entity_name = '') ⇒ Object
:nodoc:.
Constructor Details
#initialize(logger) ⇒ Base
The initialize method, default we pass the logger
17 18 19 |
# File 'lib/loops/base.rb', line 17 def initialize(logger) self.logger = logger end |
Instance Attribute Details
#config ⇒ Object
:nodoc:
14 15 16 |
# File 'lib/loops/base.rb', line 14 def config @config end |
#logger ⇒ Object
:nodoc:
14 15 16 |
# File 'lib/loops/base.rb', line 14 def logger @logger end |
#name ⇒ Object
:nodoc:
14 15 16 |
# File 'lib/loops/base.rb', line 14 def name @name end |
Class Method Details
.check_dependencies ⇒ Object
Ovveride this method for check dependencies
22 |
# File 'lib/loops/base.rb', line 22 def self.check_dependencies; end |
Instance Method Details
#with_lock(entity_id, loop_id, timeout, entity_name = '') ⇒ Object
:nodoc:
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/loops/base.rb', line 33 def with_lock(entity_id, loop_id, timeout, entity_name = '')#:nodoc: entity_name = 'item' if entity_name.to_s.empty? debug("Locking #{entity_name} #{entity_id}") lock = LoopLock.lock(:entity_id => entity_id, :loop => loop_id.to_s, :timeout => timeout) unless lock warn("Race condition detected for the #{entity_name}: #{entity_id}. Skipping the item.") return end begin yield ensure debug("Unlocking #{entity_name} #{entity_id}") LoopLock.unlock(:entity_id => entity_id, :loop => loop_id.to_s) end end |