문제

I'm using a Rails after_save callback in one of my ActiveRecord models to send push notifications to the client, which then triggers a partial refresh. I'm using Pusher. Problem that I have is that I might be creating or updating up to 50 records over 5-10 seconds or whatever, which sends a lot of push notifications and ultimately refreshes. I know pusher has a rate limit of no more than 10 messages per second per client (connection). Is there any way to adjust that rate limit to say no more than 1 message per minute per client (connection)?

도움이 되었습니까?

해결책

Note: I used to work for Pusher

The rate limit you mention is actually when sending events between clients. It doesn't affect sending messages via their REST API.

Client event docs can be found here: http://pusher.com/docs/client_api_guide/client_events#trigger-events

The server docs don't say anything about a rate limit: http://pusher.com/docs/server_api_guide/interact_rest_api#publishing-events

You appear to have four options:

  1. Do something on your server so that you rate limit sending messages to the Pusher API. This will also save you using up your "messages per day" allocation.
  2. Do something on the client; set a timeout that waits for up to 10 seconds to see if any other refresh messages are going to come along. It can therefore ignore them and only refresh when it's sure no more messages are going to arrive and then trigger the refresh yet again after the reload.
  3. When you refresh the page don't connect to Pusher for up to 10 seconds. That way you'll miss all the other refresh messages from the same batch.
  4. If possible, change your code so that the message you send isn't simply to tell the page to refresh but provides the information that is required to change the page dynamically on the client. Since you are doing a partial refresh - probably via an XHR which gets updated content - this may be possible.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top