feat: Add push provider throttle and push priority processing
New Pull Request Checklist
- [x] I am not disclosing a vulnerability.
- [x] I am creating this PR in reference to an issue.
Issue Description
Pushes are sent out as fast as possible when calling Parse.Push.send() in Parse Server Cloud Code. A push provider may have API request limits that when exceeded cause requests being rejected.
Approach
Pushes can now be throttled per provider using a queue configuration to prevent exceeding rate limits imposed by services like APNS and FCM.
Example for parallel sending 5 pushes every 500ms, effectively allowing up to 10 pushes per second in 2 controlled bursts:
const parseServerOptions = {
push: {
adapter: new ParsePushAdapter({
ios: {
// ...
queue: {
concurrency: 5,
intervalCapacity: 5,
interval: 500,
},
}
})
}
};
[!NOTE] This feature has been implemented specifically in the push adapter, not in Parse Server where there is also a
PushQueue. The push queue in Parse Server is responsible for gathering the push recipients' device tokens from the database in controlled batches, and then sending them off to the push adapter and tracking the push status. Since throttling is a push provider API topic, the feature of throttling is implemented as closely as possible to the push provider API, which is the push adapter.
TODOs before merging
- [x] Add tests
- [x] Add changes to documentation (guides, repository pages, in-code descriptions)
Summary by CodeRabbit
-
New Features
- Added throttling and prioritization for push notifications, allowing control over sending rates and queue order per push type.
- Introduced support for per-push time-to-live (TTL) and priority options.
-
Documentation
- Extended README with detailed instructions and examples for configuring push queue throttling and options.
-
Tests
- Added comprehensive tests for push queue throttling, TTL expiry, and priority handling.
- Introduced a new test suite for the throttling queue.
-
Chores
- Updated dependencies to include the
p-queuepackage.
- Updated dependencies to include the