From d483058fda6feb5c2fa7a586dd04cdc01f936d28 Mon Sep 17 00:00:00 2001 From: Nakamura Kosuke Date: Mon, 30 Jul 2018 12:53:06 +0900 Subject: [PATCH] Configurable Guzzle client timeout --- README.md | 1 + src/Notifier.php | 2 +- tests/NotifierTest.php | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b81a949..eedc95f 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ $notifier = new Faultline\Notifier([ 'project' => 'faultline-php', 'apiKey' => 'xxxxXXXXXxXxXXxxXXXXXXXxxxxXXXXXX', 'endpoint' => 'https://xxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/v0', + 'timeout' => '30.0', 'notifications' => [ [ 'type'=> 'slack', diff --git a/src/Notifier.php b/src/Notifier.php index 7f8c761..76a9ee1 100644 --- a/src/Notifier.php +++ b/src/Notifier.php @@ -69,7 +69,7 @@ protected function postNotice($url, $notice) 'x-api-key' => $this->opt['apiKey'] ], 'json' => $notice, - 'timeout' => 5.0, + 'timeout' => (isset($this->opt['timeout']) ? $this->opt['timeout'] : 5.0), ]; if (preg_match('/^5/', \GuzzleHttp\Client::VERSION)) { $config['exceptions'] = false; diff --git a/tests/NotifierTest.php b/tests/NotifierTest.php index 520ba2a..fc40d11 100644 --- a/tests/NotifierTest.php +++ b/tests/NotifierTest.php @@ -17,6 +17,7 @@ public function testNotify() 'project' => 'faultline-test', 'apiKey' => 'xxxxXXXXXxXxXXxxXXXXXXXxxxxXXXXXX', 'endpoint' => 'https://xxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/v0', + 'timeout' => '30.0', 'notifications' => [ [ 'type'=> 'slack', @@ -49,6 +50,7 @@ public function testNotifyErrorShouldBeBoolean() 'project' => 'faultline-test', 'apiKey' => 'xxxxXXXXXxXxXXxxXXXXXXXxxxxXXXXXX', 'endpoint' => 'https://example.com/v0', + 'timeout' => '30.0', 'notifications' => [ [ 'type'=> 'slack',