Class: Jp::Server::Unlocker

Inherits:
Object
  • Object
show all
Includes:
MongoConnection, Pools
Defined in:
lib/rb/jp/server/unlocker.rb

Instance Attribute Summary

Attributes included from Pools

#pools

Attributes included from MongoConnection

#database

Instance Method Summary collapse

Methods included from MongoConnection

#connect_to_mongo

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 options = {}
   load_pools(options)
   connect_to_mongo(options)
end

Instance Method Details

#clean(pool_name) ⇒ Object

Raises:



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

#runObject



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