Class: Jp::Server::Unlocker
- Inherits:
-
Object
- Object
- Jp::Server::Unlocker
- Includes:
- MongoConnection, Pools
- Defined in:
- lib/rb/jp/server/unlocker.rb
Instance Attribute Summary
Attributes included from Pools
Attributes included from MongoConnection
Instance Method Summary collapse
- #clean(pool_name) ⇒ Object
-
#initialize(options = {}) ⇒ Unlocker
constructor
A new instance of Unlocker.
- #run ⇒ Object
Methods included from MongoConnection
Constructor Details
#initialize(options = {}) ⇒ Unlocker
Returns a new instance of Unlocker.
14 15 16 17 |
# File 'lib/rb/jp/server/unlocker.rb', line 14 def initialize = {} load_pools() connect_to_mongo() end |
Instance Method Details
#clean(pool_name) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rb/jp/server/unlocker.rb', line 19 def clean pool_name raise Jp::NoSuchPool unless @pools.member? pool_name @database[pool_name].update( { 'locked_until' => { '$lte' => Time.new.to_i } }, { '$set' => { 'locked' => false } }, multi: true ) end |
#run ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rb/jp/server/unlocker.rb', line 32 def run l = Rev::Loop.new @pools.each do |name, data| t = Rev::TimerWatcher.new data[:cleanup_interval], true def t.on_timer &block if block_given? @block = block else @block.call end end t.on_timer { clean name } t.attach l end l.run end |