Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Added minimal support for sending FCM messages in async using HTTP/2 #870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 10, 2025

Conversation

jonathanedey
Copy link
Contributor

@jonathanedey jonathanedey commented Apr 8, 2025

Adds basic logic for sending FCM messages in async using HTTP/2

This initial PR covers:

  • Exporting async method send_each_async()
  • Handling refreshing of google.auth credentials and retrying refresh on 401 errors
  • Basic retry logic for 503 and 500 errors (no backoff)
  • Status and request error mapping to FirebaseErrors
  • Simple unit and integration tests

@jonathanedey jonathanedey added the release:stage Stage a release candidate label Apr 8, 2025
error_dict, message = _parse_platform_error(content, status_code)
exc = None
if handle_func:
exc = handle_func(error, message, error_dict)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed offline, let's confirm if this complex code path is necessary for error handling. If it is not, let's clean it up and keep it simple :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we use this map FCM specific errors like:

FCM_ERROR_TYPES = {
        'APNS_AUTH_ERROR': ThirdPartyAuthError,
        'QUOTA_EXCEEDED': QuotaExceededError,
        'SENDER_ID_MISMATCH': SenderIdMismatchError,
        'THIRD_PARTY_AUTH_ERROR': ThirdPartyAuthError,
        'UNREGISTERED': UnregisteredError,
}

We map to these errors by parsing the error response details. The default handle_func (handle_X_error) is agnostic to the source service of the error and doesn't try to parse based the error response details. FCM is the only service that currently makes use of this optional handle_func but this seems like the correct way to support this scenario.

We could move the logic from the helper function _handle_func_X to handle_platform_error_from_X.

Will merge as is and we can revisit this in a follow up PR if necessary.

pyjwt[crypto] >= 2.5.0
httpx[http2] == 0.28.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add this new dependency to setup.py

@jonathanedey jonathanedey merged commit a4bc029 into fcm-http2 Apr 10, 2025
12 checks passed
@jonathanedey jonathanedey deleted the je-httpx branch April 10, 2025 20:26
jonathanedey added a commit that referenced this pull request Jun 3, 2025
…or FCM async and HTTP/2 support (#882)

* Added minimal support for sending FCM messages in async using HTTP/2 (#870)

* httpx async_send_each prototype

* Clean up code and lint

* fix: Add extra dependancy for http2

* fix: reset message batch limit to 500

* fix: Add new import to `setup.py`

* Refactored retry config into `_retry.py` and added support for exponential backoff and `Retry-After` header (#871)

* Refactored retry config to `_retry.py` and added support for backoff and Retry-After

* Added unit tests for `_retry.py`

* Updated unit tests for HTTPX request errors

* Address review comments

* Added `HttpxAsyncClient` wrapper for `httpx.AsyncClient` and support for `send_each_for_multicast_async()` (#878)

* Refactored retry config to `_retry.py` and added support for backoff and Retry-After

* Added unit tests for `_retry.py`

* Updated unit tests for HTTPX request errors

* Add HttpxAsyncClient to wrap httpx.AsyncClient

* Added forced refresh to google auth credential flow and fixed lint

* Added unit tests for `GoogleAuthCredentialFlow` and `HttpxAsyncClient`

* Removed duplicate export

* Added support for `send_each_for_multicast_async()` and updated doc string and type hints

* Remove duplicate auth class

* Cover auth request error case when `requests` request fails in HTTPX auth flow

* Update test for `send_each_for_multicast_async()`

* Address review comments

* fix lint and some types

* Address review comments and removed unused code

* Update metric header test logic for `TestHttpxAsyncClient`

* Add `send_each_for_multicast_async` to `__all__`

* Apply suggestions from TW review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:stage Stage a release candidate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants