Handle push notifications in Sidekiq job

This commit is contained in:
Karina Kwiatek 2022-12-25 18:08:55 +00:00
parent 185c454da0
commit 89008364d9
3 changed files with 20 additions and 0 deletions

View File

@ -12,6 +12,8 @@ module User::PushNotificationMethods
message: resource.as_push_notification.to_json
}
n.save!
PushNotificationWorker.perform_async(n.id)
end
end
end

View File

@ -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

View File

@ -12,4 +12,5 @@ production:
- mailers
- question
- export
- push_notification