Last active
February 25, 2021 11:48
-
-
Save shbodya/b6e4fe1cc0b7cfd57222cebe26c1d43b to your computer and use it in GitHub Desktop.
Rpush check & reload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| while read line | |
| do | |
| treads+=("$line") | |
| done < <(su -c "source /home/qb_app/.rvm/scripts/rvm && cd /home/qb_app/QuickBlox-Server && bundle exec rpush status -e production " qb_app | grep thread_status) | |
| for i in "${treads[@]}" | |
| do | |
| THREAD=`echo $i | awk '{print $2}'` | |
| if [[ $THREAD == "sleep" ]] | |
| then | |
| # Fix Rpush | |
| su -c "source /home/qb_app/.rvm/scripts/rvm && cd /home/qb_app/QuickBlox-Server && bundle exec rails runner -e production /etc/zabbix/scripts/rpush_reload_stuck_notifications.rb" qb_app > /dev/null 2>&1 | |
| # Return '1' to zabbix | |
| printf "1" && exit 0 | |
| fi | |
| done | |
| printf "0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #puts "Restoring stuck Rpush notifications..." | |
| batch_size = YAML.load_file("#{Rails.root}/config/rpush.yml")[Rails.env]['batch_size'] * 5 | |
| rpush_dump_file = File.open("#{Rails.root}/log/rpush.dump", 'a') | |
| config = YAML.load_file("#{::Rails.root}/config/redis.yml")[::Rails.env] | |
| client = Redis.new config | |
| notification_ids = client.smembers('rpush:notifications:all').map(&:to_i).sort.reverse | |
| # This is the standard set where Rpush stores notifications, that will be processed | |
| # It acts like a queue | |
| pending_notification_ids = client.zrange('rpush:notifications:pending', 0, -1).map(&:to_i) | |
| notifications_restored = [] | |
| notification_ids.each_with_index do |id, index| | |
| # Skip if notification is already marked for being processed soon | |
| next if pending_notification_ids.include?(id) | |
| notification = Rpush::Notification.find(id) rescue nil | |
| next unless notification | |
| if notification.delivered || notification.failed | |
| # Check for at least one batch size of notifications for being delivered | |
| break if index > batch_size | |
| next | |
| end | |
| if notifications_restored.empty? | |
| rpush_dump_file.write("Writing dump at #{Time.now.utc}\n") | |
| end | |
| rpush_dump_file.write("#{notification.attributes}\n") | |
| client.zadd('rpush:notifications:pending', 0, id) | |
| notifications_restored << id | |
| end | |
| rpush_dump_file.write("Current rpush status:\n") | |
| rpush_state = `bundle exec rpush status -e #{Rails.env}` | |
| rpush_dump_file.write("#{rpush_state}\n") | |
| rpush_dump_file.write("Rpush memory usage:\n") | |
| rpush_dump_file.write("#{`ps aux | grep 'rpush.*dispatchers' | grep -v grep`}\n") | |
| rpush_dump_file.write("Overall memory usage:\n") | |
| rpush_dump_file.write("#{`free`}\n\n") | |
| rpush_dump_file.close | |
| system("RAILS_ENV=#{Rails.env} bundle exec god restart rpush") | |
| #puts "#{notifications_restored.count} notifications restored" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment