Class: Droonga::Sweeper

Inherits:
Object
  • Object
show all
Defined in:
lib/droonga/sweeper.rb

Constant Summary collapse

SUBSCRIBER_LIFETIME_SECONDS =

10 min

10 * 60

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Sweeper

Returns a new instance of Sweeper.



22
23
24
# File 'lib/droonga/sweeper.rb', line 22

def initialize(context)
  @context = context
end

Instance Method Details

#sweep_expired_subscribers(options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/droonga/sweeper.rb', line 26

def sweep_expired_subscribers(options={})
  now = options[:now] || Time.now
  boundary = now - SUBSCRIBER_LIFETIME_SECONDS
  expired_subscribers = @context["Subscriber"].select do |subscriber|
    subscriber.last_modified < boundary
  end
  expired_subscribers.each do |subscriber|
    watcher.unsubscribe(:subscriber => subscriber._key)
  end
end