Skip to content

Commit 4b3bc2f

Browse files
authored
Merge pull request #154 from tomaszmrozinski/master
Add option to control timeout of the Guzzle Client
2 parents 495f87b + b88d0ad commit 4b3bc2f

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ You need to fill in your OneSignal *App ID* and *REST API Key* inside your
6767
ONESIGNAL_APP_ID=xxxxxxxxxxxxxxxxxxxx
6868
ONESIGNAL_REST_API_KEY=xxxxxxxxxxxxxxxxxx
6969
```
70+
You can control timeout of the Guzzle client used by OneSignalClient by adding following into your .env file
71+
```
72+
ONESIGNAL_GUZZLE_CLIENT_TIMEOUT=integer_value
73+
```
74+
This param is useful when you are planning to send push notification via [Laravel queues](https://divinglaravel.com/always-set-a-timeout-for-guzzle-requests-inside-a-queued-job)
7075

7176
## Usage
7277

config/onesignal.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,15 @@
1919
|
2020
*/
2121
'rest_api_key' => env('ONESIGNAL_REST_API_KEY'),
22-
'user_auth_key' => env('USER_AUTH_KEY')
22+
'user_auth_key' => env('USER_AUTH_KEY'),
23+
24+
/*
25+
|--------------------------------------------------------------------------
26+
| Guzzle Timeout
27+
|--------------------------------------------------------------------------
28+
|
29+
|
30+
|
31+
*/
32+
'guzzle_client_timeout' => env('ONESIGNAL_GUZZLE_CLIENT_TIMEOUT', 0),
2333
);

src/OneSignalClient.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,21 @@ public function callback(Callable $requestCallback)
6969
return $this;
7070
}
7171

72-
public function __construct($appId, $restApiKey, $userAuthKey)
72+
/**
73+
* @param $appId
74+
* @param $restApiKey
75+
* @param $userAuthKey
76+
* @param int $guzzleClientTimeout
77+
*/
78+
public function __construct($appId, $restApiKey, $userAuthKey, $guzzleClientTimeout = 0)
7379
{
7480
$this->appId = $appId;
7581
$this->restApiKey = $restApiKey;
7682
$this->userAuthKey = $userAuthKey;
7783

7884
$this->client = new Client([
7985
'handler' => $this->createGuzzleHandler(),
86+
'timeout' => $guzzleClientTimeout,
8087
]);
8188
$this->headers = ['headers' => []];
8289
$this->additionalParams = [];

src/OneSignalServiceProvider.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ public function register()
3636
$config = $app['config']['onesignal'] ?: $app['config']['onesignal::config'];
3737
}
3838

39-
$client = new OneSignalClient($config['app_id'], $config['rest_api_key'], $config['user_auth_key']);
40-
41-
return $client;
39+
return new OneSignalClient($config['app_id'], $config['rest_api_key'], $config['user_auth_key'] , $config['guzzle_client_timeout']);
4240
});
4341

4442
$this->app->alias('onesignal', 'Berkayk\OneSignal\OneSignalClient');

0 commit comments

Comments
 (0)