Class: CopycopterClient::Poller

Inherits:
Object
  • Object
show all
Defined in:
lib/copycopter_client/poller.rb

Overview

Starts a background thread that continually resynchronizes with the remote server using the given Cache after a set delay.

Instance Method Summary collapse

Constructor Details

#initialize(cache, options) ⇒ Poller

Returns a new instance of Poller.

Parameters:

  • options (Hash)

Options Hash (options):

  • :logger (Logger)

    where errors should be logged

  • :polling_delay (Fixnum)

    how long to wait in between requests



11
12
13
14
15
16
# File 'lib/copycopter_client/poller.rb', line 11

def initialize(cache, options)
  @cache         = cache
  @polling_delay = options[:polling_delay]
  @logger        = options[:logger]
  @stop          = false
end

Instance Method Details

#startObject



18
19
20
# File 'lib/copycopter_client/poller.rb', line 18

def start
  Thread.new { poll } or logger.error("Couldn't start poller thread")
end

#stopObject



22
23
24
# File 'lib/copycopter_client/poller.rb', line 22

def stop
  @stop = true
end