Skip to content

Commit 3df1b3d

Browse files
committed
Trying to add better error log and limit max 100 messages for each request
1 parent 464a86d commit 3df1b3d

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
gem "exponent-server-sdk"
1+
gem 'exponent-server-sdk', git: 'https://github.com/gtt-project/expo-server-sdk-ruby.git', tag: 'v0.1.0-dev1'

lib/redmine_expo_push/notification.rb

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ def add_recipient(user)
1717
@recipients << user
1818
end
1919

20-
# https://docs.expo.io/versions/latest/guides/push-notifications/
20+
# https://docs.expo.io/push-notifications/sending-notifications/
2121
# https://github.com/expo/expo-server-sdk-ruby
22-
# https://docs.expo.io/versions/latest/guides/push-notifications/#message-format
22+
# https://docs.expo.io/push-notifications/sending-notifications/#message-request-format
2323
def deliver
2424
messages = @recipients.map do |user|
2525
ExpoPushToken.where(user: user).map do |token|
@@ -34,11 +34,19 @@ def deliver
3434
messages.flatten!
3535

3636
if messages.any?
37-
begin
38-
Exponent::Push::Client.new(gzip: true).send_messages messages
39-
rescue Exception
40-
Rails.logger.error "error sending push notifications:\n#{$!}\n" + $!.backtrace.join("\n")
41-
end
37+
messages.each_slice(100) {|message_list|
38+
begin
39+
handler = Exponent::Push::Client.new(gzip: true).send_messages message_list
40+
if handler.errors.present?
41+
Rails.logger.error "handler.errors:#{handler.errors}"
42+
end
43+
if handler.receipt_ids.present?
44+
Rails.logger.info "handler.receipt_ids:#{handler.receipt_ids}"
45+
end
46+
rescue Exception
47+
Rails.logger.error "error sending push notifications:\n#{$!}\n" + $!.backtrace.join("\n")
48+
end
49+
}
4250
end
4351
end
4452
end

0 commit comments

Comments
 (0)