Class: Rpush::Daemon::Feeder

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

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Reflectable

reflect

Class Attribute Details

.should_stopObject

Returns the value of attribute should_stop.



22
23
24
# File 'lib/rpush/daemon/feeder.rb', line 22

def should_stop
  @should_stop
end

Class Method Details

.enqueue_notificationsObject



39
40
41
42
43
44
45
46
47
# File 'lib/rpush/daemon/feeder.rb', line 39

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_foreverObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rpush/daemon/feeder.rb', line 25

def self.feed_forever
  @thread = Thread.new do
    loop do
      enqueue_notifications
      interruptible_sleeper.sleep
      break if should_stop
    end

    Rpush::Daemon.store.release_connection
  end

  @thread.join
end

.interruptible_sleeperObject



49
50
51
52
53
54
# File 'lib/rpush/daemon/feeder.rb', line 49

def self.interruptible_sleeper
  return @interruptible_sleeper if @interruptible_sleeper
  @interruptible_sleeper = InterruptibleSleep.new(Rpush.config.push_poll)
  @interruptible_sleeper.start
  @interruptible_sleeper
end

.startObject



6
7
8
9
# File 'lib/rpush/daemon/feeder.rb', line 6

def self.start
  self.should_stop = false
  Rpush.config.push ? enqueue_notifications : feed_forever
end

.stopObject



11
12
13
14
15
# File 'lib/rpush/daemon/feeder.rb', line 11

def self.stop
  self.should_stop = true
  interruptible_sleeper.stop
  @thread.join if @thread
end

.wakeupObject



17
18
19
# File 'lib/rpush/daemon/feeder.rb', line 17

def self.wakeup
  interruptible_sleeper.wakeup
end