Class: Timely::Sync::Poller
- Inherits:
-
Object
- Object
- Timely::Sync::Poller
- Defined in:
- lib/timely/sync/poller.rb
Instance Method Summary collapse
- #clear_refresh_flag ⇒ Object
-
#initialize(db, config) ⇒ Poller
constructor
A new instance of Poller.
- #needs_refresh? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(db, config) ⇒ Poller
Returns a new instance of Poller.
4 5 6 7 8 9 10 |
# File 'lib/timely/sync/poller.rb', line 4 def initialize(db, config) @db = db @config = config @running = false @needs_refresh = false @thread = nil end |
Instance Method Details
#clear_refresh_flag ⇒ Object
39 40 41 |
# File 'lib/timely/sync/poller.rb', line 39 def clear_refresh_flag @needs_refresh = false end |
#needs_refresh? ⇒ Boolean
35 36 37 |
# File 'lib/timely/sync/poller.rb', line 35 def needs_refresh? @needs_refresh end |
#start ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/timely/sync/poller.rb', line 12 def start return if @running @running = true interval = @config.get('google.sync_interval', 300) @thread = Thread.new do while @running begin sync_cycle rescue => e File.open('/tmp/timely-sync.log', 'a') { |f| f.puts "#{Time.now} Sync error: #{e.}" } end # Sleep in short intervals so we can exit quickly (interval / 2).times { break unless @running; sleep 2 } end end end |
#stop ⇒ Object
30 31 32 33 |
# File 'lib/timely/sync/poller.rb', line 30 def stop @running = false @thread&.kill end |