Move rpush init/exit logic into Sidekiq initializer

Co-authored-by: nilsding <nilsding@nilsding.org>
This commit is contained in:
Karina Kwiatek 2022-12-25 23:34:04 +00:00
parent 10c224b2fe
commit 91d3db4034
2 changed files with 13 additions and 5 deletions

View File

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

View File

@ -1,7 +1,19 @@
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|