Last active
February 25, 2021 11:48
-
-
Save shbodya/b6e4fe1cc0b7cfd57222cebe26c1d43b to your computer and use it in GitHub Desktop.
Revisions
-
Bogdan revised this gist
Mar 24, 2017 . 2 changed files with 4 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ done < <(su -c "source /home/qb_app/.rvm/scripts/rvm && cd /home/qb_app/QuickBlo 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 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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,9 @@ 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 -
Bogdan revised this gist
Mar 10, 2017 . No changes.There are no files selected for viewing
-
Bogdan created this gist
Mar 10, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ #!/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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ #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') client = Redis.new 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"