Class: FlyingSphinx::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/flying_sphinx/action.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier, timeout, &block) ⇒ Action

Returns a new instance of Action.



8
9
10
11
12
# File 'lib/flying_sphinx/action.rb', line 8

def initialize(identifier, timeout, &block)
  @identifier, @timeout, @block = identifier, timeout, block
  @action_id = 0
  @finished  = false
end

Class Method Details

.perform(identifier, timeout = 60, &block) ⇒ Object



4
5
6
# File 'lib/flying_sphinx/action.rb', line 4

def self.perform(identifier, timeout = 60, &block)
  new(identifier, timeout, &block).perform
end

Instance Method Details

#performObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/flying_sphinx/action.rb', line 14

def perform
  Timeout.timeout(timeout) do
    socket.connect true

    subscribe_to_events

    sleep 0.5 until socket.connected
    start
    sleep 0.5 until finished
  end

  true
rescue Timeout::Error => error
  FlyingSphinx.logger.warn "Action timed out. If this is happening regularly, please contact Flying Sphinx support: http://support.flying-sphinx.com"

  return false
ensure
  socket.disconnect
end