Class: Rpush::Daemon::Feeder
- Inherits:
-
Object
- Object
- Rpush::Daemon::Feeder
- Extended by:
- Reflectable
- Defined in:
- lib/rpush/daemon/feeder.rb
Class Attribute Summary collapse
-
.should_stop ⇒ Object
Returns the value of attribute should_stop.
Class Method Summary collapse
- .enqueue_notifications ⇒ Object
- .feed_forever ⇒ Object
- .interruptible_sleeper ⇒ Object
- .start ⇒ Object
- .stop ⇒ Object
- .wakeup ⇒ Object
Methods included from Reflectable
Class Attribute Details
.should_stop ⇒ Object
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_notifications ⇒ Object
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_forever ⇒ Object
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_sleeper ⇒ Object
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 |
.start ⇒ Object
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 |
.stop ⇒ Object
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 |
.wakeup ⇒ Object
17 18 19 |
# File 'lib/rpush/daemon/feeder.rb', line 17 def self.wakeup interruptible_sleeper.wakeup end |