Skip to content

Commit 12fda9a

Browse files
committed
feat: add configurable timeouts and retry logic to REST and Restlet clients
- Implement connectTimeout() and timeout() using new BRIAR_ROSE_CONNECT_TIMEOUT and BRIAR_ROSE_TIMEOUT environment variables - Add retry logic for GET and HEAD requests with configurable attempts and sleep duration - Fix indentation for environment variable examples in README.md
1 parent aff3431 commit 12fda9a

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ If you have a single RESTlet script deployed, you can set enviromental variables
213213
214214
Set the deploy ID in the environment:
215215
```env
216-
NETSUITE_RESTLET_SCRIPT_ID=... // Script ID of the deployed RESTlet
217-
NETSUITE_RESTLET_DEPLOY_ID=1 // Booleans are 1 or 0
216+
NETSUITE_RESTLET_SCRIPT_ID=... // Script ID of the deployed RESTlet
217+
NETSUITE_RESTLET_DEPLOY_ID=1 // Booleans are 1 or 0
218218
```
219219

220220
```php
@@ -227,7 +227,7 @@ If you have a RESTlet base URL set, you can call it like this:
227227

228228
Set the RESTlet base URL in the environment:
229229
```env
230-
NETSUITE_RESTLET_BASE_URL=... // Be sure to set the Script ID of the RESTlet in the URL.
230+
NETSUITE_RESTLET_BASE_URL=... // Be sure to set the Script ID of the RESTlet in the URL.
231231
```
232232

233233
```php

src/Clients/RestClient.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,17 @@ public function request(string $method, string $path, array $options = []): Resp
4343
'Authorization' => $authHeader,
4444
'Accept' => 'application/json',
4545
'Content-Type' => 'application/json',
46-
]);
46+
])->connectTimeout((int) env('BRIAR_ROSE_CONNECT_TIMEOUT', 10))
47+
->timeout((int) env('BRIAR_ROSE_TIMEOUT', 60))
48+
->retry(
49+
(int) env('BRIAR_ROSE_RETRY', 3),
50+
(int) env('BRIAR_ROSE_RETRY_SLEEP_MS', 250),
51+
function ($exception, $request) use ($method) {
52+
// Retry only safe/idempotent methods by default
53+
return in_array($method, ['GET', 'HEAD'], true);
54+
},
55+
throw: false
56+
);
4757

4858
if (!empty($options['headers']) && is_array($options['headers'])) {
4959
$request = $request->withHeaders($options['headers']);

src/Clients/RestletClient.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,17 @@ protected function send(string $method, string $url, array $data = []): Response
124124
'Authorization' => $authHeader,
125125
'Content-Type' => 'application/json',
126126
'Accept' => 'application/json',
127-
]);
127+
])->connectTimeout((int) env('BRIAR_ROSE_CONNECT_TIMEOUT', 10))
128+
->timeout((int) env('BRIAR_ROSE_TIMEOUT', 60))
129+
->retry(
130+
(int) env('BRIAR_ROSE_RETRY', 3),
131+
(int) env('BRIAR_ROSE_RETRY_SLEEP_MS', 250),
132+
function ($exception, $request) use ($method) {
133+
// Retry only safe/idempotent methods by default
134+
return in_array($method, ['GET', 'HEAD'], true);
135+
},
136+
throw: false
137+
);
128138

129139
if ($method === 'GET') {
130140
if (! empty($data)) {

0 commit comments

Comments
 (0)