Class: Shoryuken::Later::Poller

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/shoryuken/later/poller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_name) ⇒ Poller

Returns a new instance of Poller.



10
11
12
# File 'lib/shoryuken/later/poller.rb', line 10

def initialize(table_name)
  @table_name = table_name
end

Instance Attribute Details

#table_nameObject (readonly)

Returns the value of attribute table_name.



8
9
10
# File 'lib/shoryuken/later/poller.rb', line 8

def table_name
  @table_name
end

Instance Method Details

#pollObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/shoryuken/later/poller.rb', line 14

def poll
  watchdog('Later::Poller#poll died') do
    started_at = Time.now
    
    logger.debug { "Polling for scheduled messages in '#{table_name}'" }
    
    begin
      while item = next_item
        id = item['id']
        logger.info "Found message #{id} from '#{table_name}'"
        if sent_msg = process_item(item)
          logger.debug { "Enqueued message #{id} from '#{table_name}'" }
        else
          logger.debug { "Skipping already queued message #{id} from '#{table_name}'" }
        end
      end
  
      logger.debug { "Poller for '#{table_name}' completed in #{elapsed(started_at)} ms" }
    rescue => ex
      logger.error "Error fetching message: #{ex}"
      logger.error ex.backtrace.first
    end
  end
end