why were we retrying those prefinery searches...

This commit is contained in:
Alex Grintsvayg 2016-10-12 12:02:30 -04:00
parent 67cc0a2086
commit a337dd5e33
2 changed files with 18 additions and 26 deletions

View file

@ -13,11 +13,11 @@ class Prefinery
const PREFIX = '/api/v2/betas/8679';
protected static $curlOptions = [
'headers' => [
'headers' => [
'Accept: application/json',
'Content-type: application/json'
],
'json_data' => true,
'json_data' => true,
'json_response' => true
];
@ -132,31 +132,19 @@ class Prefinery
protected static function get($endpoint, array $data = [])
{
$apiKey = Config::get('prefinery_key');
$tries = 0;
$response = null;
while (!$response && $tries < 3)
{
$tries++;
list($status, $headers, $response) = Curl::doCurl(Curl::GET,
static::DOMAIN . static::PREFIX . $endpoint . '.json?api_key=' . $apiKey, $data, array_merge(static::$curlOptions, ['retry' => 3]));
if (!$response)
{
Controller::queueToRunAfterResponse(function() use($status, $headers, $tries) {
Slack::sendErrorIfProd('Empty prefinery get response. Try ' . $tries . '. Status: ' . $status . '. Headers: ' . var_export($headers, true));
});
}
}
return static::decodePrefineryResponse($response);
return static::decodePrefineryResponse(
Curl::get(static::DOMAIN . static::PREFIX . $endpoint . '.json?api_key=' . Config::get('prefinery_key'),
$data, array_merge(static::$curlOptions, ['retry' => 3])
)
);
}
protected static function post($endpoint, array $data = [], $allowEmptyResponse = true)
protected static function post($endpoint, array $data = [], bool $allowEmptyResponse = true)
{
$apiKey = Config::get('prefinery_key');
return static::decodePrefineryResponse(
Curl::post(static::DOMAIN . static::PREFIX . $endpoint . '.json?api_key=' . $apiKey, $data, array_merge(static::$curlOptions, ['retry' => 3])),
Curl::post(static::DOMAIN . static::PREFIX . $endpoint . '.json?api_key=' . Config::get('prefinery_key'),
$data, array_merge(static::$curlOptions, ['retry' => 3])
),
$allowEmptyResponse
);
}
@ -182,9 +170,10 @@ class Prefinery
if (isset($data['errors']))
{
throw new PrefineryException($data['errors'] ? implode("\n", array_map(function ($error) {
return $error['message'];
}, (array)$data['errors'])) : 'Received empty error array.');
throw new PrefineryException($data['errors'] ?
implode("\n", array_map(function ($error) { return $error['message']; }, (array)$data['errors'])) :
'Received empty error array.'
);
}
return $data;

View file

@ -69,6 +69,9 @@ class Curl
$ch = curl_init();
// curl_setopt($ch, CURLOPT_VERBOSE, true);
// curl_setopt($ch, CURLOPT_STDERR, fopen('php://temp', 'w+'));
if ($ch === false || $ch === null)
{
throw new LogicException('Unable to initialize cURL');