diff --git a/app/models/user/push_notification_methods.rb b/app/models/user/push_notification_methods.rb index 32b630bd..f2446805 100644 --- a/app/models/user/push_notification_methods.rb +++ b/app/models/user/push_notification_methods.rb @@ -12,6 +12,8 @@ module User::PushNotificationMethods message: resource.as_push_notification.to_json } n.save! + + PushNotificationWorker.perform_async(n.id) end end end diff --git a/app/workers/push_notification_worker.rb b/app/workers/push_notification_worker.rb new file mode 100644 index 00000000..34902d41 --- /dev/null +++ b/app/workers/push_notification_worker.rb @@ -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 diff --git a/config/sidekiq.yml b/config/sidekiq.yml index 2236bdc5..b9c163be 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -12,4 +12,5 @@ production: - mailers - question - export + - push_notification