From 91d3db4034b40ebe5b0523bb8e88e772e092040c Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sun, 25 Dec 2022 23:34:04 +0000 Subject: [PATCH] Move rpush init/exit logic into Sidekiq initializer Co-authored-by: nilsding --- app/workers/push_notification_worker.rb | 4 ---- config/initializers/15_sidekiq.rb | 14 +++++++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/workers/push_notification_worker.rb b/app/workers/push_notification_worker.rb index 34902d41..7bc08cd4 100644 --- a/app/workers/push_notification_worker.rb +++ b/app/workers/push_notification_worker.rb @@ -8,10 +8,6 @@ class PushNotificationWorker 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/initializers/15_sidekiq.rb b/config/initializers/15_sidekiq.rb index f0985236..d2045cf4 100644 --- a/config/initializers/15_sidekiq.rb +++ b/config/initializers/15_sidekiq.rb @@ -1,9 +1,21 @@ +require "rpush/daemon" +require "rpush/daemon/store/active_record" +require "rpush/client/active_record" + redis_url = ENV.fetch("REDIS_URL") { APP_CONFIG["redis_url"] } Sidekiq.configure_server do |config| config.redis = { url: redis_url } + Rpush.config.push = true + Rpush::Daemon.store = Rpush::Daemon::Store::ActiveRecord.new + Rpush::Daemon.common_init + Rpush::Daemon::Synchronizer.sync + + at_exit do + Rpush::Daemon::AppRunner.stop + end end Sidekiq.configure_client do |config| config.redis = { url: redis_url } -end \ No newline at end of file +end