class Rpush::Daemon::Store::Redis
Constants
- DEFAULT_MARK_OPTIONS
Public Instance Methods
all_apps()
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 11 def all_apps Rpush::Client::Redis::App.all end
app(app_id)
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 7 def app(app_id) Rpush::Client::Redis::App.find(app_id) end
create_adm_notification(attrs, data, registration_ids, deliver_after, app)
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 96 def create_adm_notification(attrs, data, registration_ids, deliver_after, app) notification = Rpush::Client::Redis::Adm::Notification.new create_adm_like_notification(notification, attrs, data, registration_ids, deliver_after, app) end
create_fcm_notification(attrs, data, app)
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 91 def create_fcm_notification(attrs, data, app) notification = Rpush::Client::Redis::Fcm::Notification.new create_fcm_like_notification(notification, attrs, data, app) end
deliverable_notifications(limit)
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 15 def deliverable_notifications(limit) retryable_ids = retryable_notification_ids limit -= retryable_ids.size pending_ids = limit > 0 ? pending_notification_ids(limit) : [] ids = retryable_ids + pending_ids ids.map { |id| find_notification_by_id(id) }.compact end
mark_batch_delivered(notifications)
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 30 def mark_batch_delivered(notifications) now = Time.now notifications.each { |n| mark_delivered(n, now) } end
mark_batch_failed(notifications, code, description)
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 46 def mark_batch_failed(notifications, code, description) now = Time.now notifications.each { |n| mark_failed(n, code, description, now) } end
mark_batch_retryable(notifications, deliver_after)
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 78 def mark_batch_retryable(notifications, deliver_after) notifications.each { |n| mark_retryable(n, deliver_after) } end
mark_delivered(notification, time, opts = {})
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 23 def mark_delivered(notification, time, opts = {}) opts = DEFAULT_MARK_OPTIONS.dup.merge(opts) notification.delivered = true notification.delivered_at = time notification.save!(validate: false) if opts[:persist] end
mark_failed(notification, code, description, time, opts = {})
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 35 def mark_failed(notification, code, description, time, opts = {}) opts = DEFAULT_MARK_OPTIONS.dup.merge(opts) notification.delivered = false notification.delivered_at = nil notification.failed = true notification.failed_at = time notification.error_code = code notification.error_description = description notification.save!(validate: false) if opts[:persist] end
mark_ids_failed(ids, code, description, time)
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 51 def mark_ids_failed(ids, code, description, time) ids.each do |id| notification = find_notification_by_id(id) next unless notification mark_failed(notification, code, description, time) end end
mark_ids_retryable(ids, deliver_after)
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 82 def mark_ids_retryable(ids, deliver_after) ids.each do |id| notification = find_notification_by_id(id) next unless notification mark_retryable(notification, deliver_after) end end
mark_retryable(notification, deliver_after, opts = {})
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 60 def mark_retryable(notification, deliver_after, opts = {}) opts = DEFAULT_MARK_OPTIONS.dup.merge(opts) notification.delivered = false notification.delivered_at = nil notification.failed = false notification.failed_at = nil notification.retries += 1 notification.deliver_after = deliver_after return unless opts[:persist] notification.save!(validate: false) namespace = Rpush::Client::Redis::Notification.absolute_retryable_namespace Modis.with_connection do |redis| redis.zadd(namespace, deliver_after.to_i, notification.id) end end
pending_delivery_count()
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 115 def pending_delivery_count Modis.with_connection do |redis| pending = redis.zrange(Rpush::Client::Redis::Notification.absolute_pending_namespace, 0, -1) retryable = redis.zrangebyscore(Rpush::Client::Redis::Notification.absolute_retryable_namespace, 0, Time.now.to_i) pending.count + retryable.count end end
release_connection()
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 109 def release_connection end
reopen_log()
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 112 def reopen_log end
translate_integer_notification_id(id)
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 124 def translate_integer_notification_id(id) id end
update_app(app)
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 101 def update_app(app) app.save! end
update_notification(notification)
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 105 def update_notification(notification) notification.save! end
Private Instance Methods
create_adm_like_notification(notification, attrs, data, registration_ids, deliver_after, app)
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 145 def create_adm_like_notification(notification, attrs, data, registration_ids, deliver_after, app) # rubocop:disable Metrics/ParameterLists notification.assign_attributes(attrs) notification.data = data notification.registration_ids = registration_ids notification.deliver_after = deliver_after notification.app = app notification.save! notification end
create_fcm_like_notification(notification, attrs, data, app)
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 137 def create_fcm_like_notification(notification, attrs, data, app) # rubocop:disable Metrics/ParameterLists notification.assign_attributes(attrs) notification.data = data notification.app = app notification.save! notification end
find_notification_by_id(id)
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 130 def find_notification_by_id(id) Rpush::Client::Redis::Notification.find(id) rescue Modis::RecordNotFound Rpush.logger.warn("Couldn't find Rpush::Client::Redis::Notification with id=#{id}") nil end
pending_notification_ids(limit)
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 169 def pending_notification_ids(limit) limit = [0, limit - 1].max # 'zrange key 0 1' will return 2 values, not 1. pending_ns = Rpush::Client::Redis::Notification.absolute_pending_namespace Modis.with_connection do |redis| pending_results = redis.multi do |transaction| transaction.zrange(pending_ns, 0, limit) transaction.zremrangebyrank(pending_ns, 0, limit) end pending_results.first end end
retryable_notification_ids()
click to toggle source
# File lib/rpush/daemon/store/redis.rb, line 155 def retryable_notification_ids retryable_ns = Rpush::Client::Redis::Notification.absolute_retryable_namespace Modis.with_connection do |redis| retryable_results = redis.multi do |transaction| now = Time.now.to_i transaction.zrangebyscore(retryable_ns, 0, now) transaction.zremrangebyscore(retryable_ns, 0, now) end retryable_results.first end end