Skip to content

Commit

Permalink
ci: Generate code
Browse files Browse the repository at this point in the history
  • Loading branch information
seambot committed Jan 8, 2025
1 parent 1a5763d commit a3a2184
Showing 1 changed file with 39 additions and 61 deletions.
100 changes: 39 additions & 61 deletions src/SeamClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@

use GuzzleHttp\Client as HTTPClient;
use \Exception as Exception;
use Seam\HttpApiError;
use Seam\HttpUnauthorizedError;
use Seam\HttpInvalidInputError;
use Seam\ActionAttemptFailedError;
use Seam\ActionAttemptTimeoutError;

define("LTS_VERSION", "1.0.0");

Expand Down Expand Up @@ -119,60 +124,34 @@ public function request(
} catch (Exception $ignoreError) {
}

if (($res_json->error ?? null) != null) {
throw new Exception(
"Error Calling \"" .
$method .
" " .
$path .
"\" : " .
($res_json->error->type ?? "") .
": " .
$res_json->error->message .
" [Request ID: " .
$request_id .
"]"
);
}

if ($status_code >= 400) {
$error_message = $response->getReasonPhrase();

throw new Exception(
"HTTP Error: " .
$error_message .
" [" .
$status_code .
"] " .
$method .
" " .
$path .
" [Request ID: " .
$request_id .
"]"
);
}
if ($status_code === 401) {
throw new HttpUnauthorizedError($request_id);
}

if ($inner_object) {
if (
!is_array($res_json->$inner_object) &&
($res_json->$inner_object ?? null) == null
) {
throw new Exception(
'Missing Inner Object "' .
$inner_object .
'" for ' .
$method .
" " .
$path .
" [Request ID: " .
$request_id .
"]"
if (($res_json->error ?? null) != null) {
if ($res_json->error->type === "invalid_input") {
throw new HttpInvalidInputError(
$res_json->error,
$status_code,
$request_id
);
}

throw new HttpApiError(
$res_json->error,
$status_code,
$request_id
);
}
return $res_json->$inner_object;

throw GuzzleHttpExceptionRequestException::create(
new GuzzleHttpPsr7Request($method, $path),
$response
);
}
return $res_json;

return $inner_object ? $res_json->$inner_object : $res_json;
}
}

Expand Down Expand Up @@ -2161,29 +2140,28 @@ public function list(array $action_attempt_ids): array

return array_map(fn($r) => ActionAttempt::from_json($r), $res);
}
public function poll_until_ready(string $action_attempt_id): ActionAttempt
{
public function poll_until_ready(
string $action_attempt_id,
float $timeout = 20.0
): ActionAttempt {
$seam = $this->seam;
$time_waiting = 0.0;
$polling_interval = 0.4;
$action_attempt = $seam->action_attempts->get($action_attempt_id);

while ($action_attempt->status == "pending") {
$action_attempt = $seam->action_attempts->get(
$action_attempt->action_attempt_id
);
if ($time_waiting > 20.0) {
throw new Exception(
"Timed out waiting for action attempt to be ready"
);
if ($time_waiting > $timeout) {
throw new ActionAttemptTimeoutError($action_attempt, $timeout);
}
$time_waiting += 0.4;
usleep(400000); // sleep for 0.4 seconds
$time_waiting += $polling_interval;
usleep($polling_interval * 1000000);
}

if ($action_attempt->status == "failed") {
throw new Exception(
"Action Attempt failed: " . $action_attempt->error->message
);
if ($action_attempt->status == "error") {
throw new ActionAttemptFailedError($action_attempt);
}

return $action_attempt;
Expand Down

0 comments on commit a3a2184

Please sign in to comment.