Class: Rpush::Daemon::Feeder

Inherits:
Object
  • Object
show all
Extended by:
Loggable, Reflectable
Defined in:
lib/rpush/daemon/feeder.rb

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Reflectable

reflect

Methods included from Loggable

log_debug, log_error, log_info, log_warn

Class Attribute Details

.should_stopObject

Returns the value of attribute should_stop.



39
40
41
# File 'lib/rpush/daemon/feeder.rb', line 39

def should_stop
  @should_stop
end

Class Method Details

.enqueue_notificationsObject



54
55
56
57
58
59
60
61
62
# File 'lib/rpush/daemon/feeder.rb', line 54

def self.enqueue_notifications
  batch_size = Rpush.config.batch_size - Rpush::Daemon::AppRunner.total_queued
  return if batch_size <= 0
  notifications = Rpush::Daemon.store.deliverable_notifications(batch_size)
  Rpush::Daemon::AppRunner.enqueue(notifications)
rescue StandardError => e
  Rpush.logger.error(e)
  reflect(:error, e)
end

.feed_allObject



42
43
44
# File 'lib/rpush/daemon/feeder.rb', line 42

def self.feed_all
  enqueue_notifications until Rpush::Daemon.store.pending_delivery_count == 0
end

.feed_foreverObject



46
47
48
49
50
51
52
# File 'lib/rpush/daemon/feeder.rb', line 46

def self.feed_forever
  loop do
    enqueue_notifications
    interruptible_sleeper.sleep(Rpush.config.push_poll)
    return if should_stop
  end
end

.interruptible_sleeperObject



64
65
66
# File 'lib/rpush/daemon/feeder.rb', line 64

def self.interruptible_sleeper
  @interruptible_sleeper ||= InterruptibleSleep.new
end

.start(push_mode = false) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rpush/daemon/feeder.rb', line 7

def self.start(push_mode = false)
  self.should_stop = false

  @thread = Thread.new do
    push_mode ? feed_all : feed_forever
    Rpush::Daemon.store.release_connection
  end

  @thread.join
rescue StandardError => e
  log_error(e)
  reflect(:error, e)
ensure
  @thread = nil
end

.stopObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/rpush/daemon/feeder.rb', line 23

def self.stop
  self.should_stop = true
  interruptible_sleeper.stop
  @thread.join if @thread
rescue StandardError => e
  log_error(e)
  reflect(:error, e)
ensure
  @thread = nil
end

.wakeupObject



34
35
36
# File 'lib/rpush/daemon/feeder.rb', line 34

def self.wakeup
  interruptible_sleeper.stop
end