kreait / laravel-firebase

A Laravel package for the Firebase PHP Admin SDK
https://github.com/kreait/firebase-php
MIT License
1.05k stars 169 forks source link

best way to handle ServerError and ServerUnavailable Exception #45

Closed michaelnguyen2021 closed 4 years ago

michaelnguyen2021 commented 4 years ago

I usually have a queued job to process sending a push notification. When the job gets a ServerError or ServerUnavailable Exception, it will retry immediately until it runs out of the number of tries.

Ideally, if the job gets the ServerError or ServerUnavailable. It should wait for 30s before trying again. I am not sure how to do this? Any suggestions?

jeromegamez commented 4 years ago

Is the retryAfter behavior in the job class perhaps what you‘re after?

https://laravel-news.com/job-based-retry-delay

michaelnguyen2021 commented 4 years ago

@jeromegamez I ended up using

       try {
            app('firebase.messaging')->send($message);
        } catch (NotFound $e) {
            $this->device->delete();
        } catch (ServerError $e) {
            $this->release($this->attempts() * 10);
        }

I have some weird issue with retryAfter where the retryAfter time does not increment by the number of attempts.

This brings me to the next question: how to try and catch for all app('firebase.messaging')->send($message); without copy and paste try/catch where I use app('firebase.messaging')->send($message);

jeromegamez commented 4 years ago

You can catch the MessagingException interface (https://github.com/kreait/firebase-php/blob/main/src/Firebase/Exception/MessagingException.php).

github-actions[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.