Handle push notifications in Sidekiq job
This commit is contained in:
parent
185c454da0
commit
89008364d9
|
@ -12,6 +12,8 @@ module User::PushNotificationMethods
|
|||
message: resource.as_push_notification.to_json
|
||||
}
|
||||
n.save!
|
||||
|
||||
PushNotificationWorker.perform_async(n.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "rpush/daemon"
|
||||
|
||||
class PushNotificationWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options queue: :push_notification, retry: 0
|
||||
|
||||
def perform(notification_id)
|
||||
Rpush.config.push = true
|
||||
Rpush::Daemon.common_init
|
||||
Rpush::Daemon::Synchronizer.sync
|
||||
Rpush::Daemon::AppRunner.enqueue(Rpush::Client::ActiveRecord::Notification.where(id: notification_id))
|
||||
Rpush::Daemon::AppRunner.stop
|
||||
end
|
||||
end
|
|
@ -12,4 +12,5 @@ production:
|
|||
- mailers
|
||||
- question
|
||||
- export
|
||||
- push_notification
|
||||
|
||||
|
|
Loading…
Reference in New Issue