mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-09-01 01:35:10 +00:00
log failed prefinery gets
This commit is contained in:
parent
2bcf13b750
commit
6af882a969
1 changed files with 26 additions and 12 deletions
|
@ -26,7 +26,7 @@ class Prefinery
|
||||||
$apcEnabled = extension_loaded('apc') && ini_get('apc.enabled');
|
$apcEnabled = extension_loaded('apc') && ini_get('apc.enabled');
|
||||||
if ($useApc && $apcEnabled)
|
if ($useApc && $apcEnabled)
|
||||||
{
|
{
|
||||||
$cached = apc_fetch('prefinery-user-'.$emailOrId, $success);
|
$cached = apc_fetch('prefinery-user-' . $emailOrId, $success);
|
||||||
if ($success)
|
if ($success)
|
||||||
{
|
{
|
||||||
return $cached;
|
return $cached;
|
||||||
|
@ -39,7 +39,7 @@ class Prefinery
|
||||||
unset($user['invitation_code']); // so we dont leak it
|
unset($user['invitation_code']); // so we dont leak it
|
||||||
if ($useApc && $apcEnabled)
|
if ($useApc && $apcEnabled)
|
||||||
{
|
{
|
||||||
apc_store('prefinery-user-'.$emailOrId, $user, 3600);
|
apc_store('prefinery-user-' . $emailOrId, $user, 3600);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,11 +76,11 @@ class Prefinery
|
||||||
if (!$user)
|
if (!$user)
|
||||||
{
|
{
|
||||||
// dont record ip for lbry.io addresses, for testing
|
// dont record ip for lbry.io addresses, for testing
|
||||||
$ip = !preg_match('/@lbry\.io$/', $email) ? Request::getOriginalIp() : null;
|
$ip = !preg_match('/@lbry\.io$/', $email) ? Request::getOriginalIp() : null;
|
||||||
$ua = Request::getUserAgent();
|
$ua = Request::getUserAgent();
|
||||||
$user = Prefinery::createTester(array_filter([
|
$user = Prefinery::createTester(array_filter([
|
||||||
'email' => $email,
|
'email' => $email,
|
||||||
'status' => $inviteCode ? static::STATE_ACTIVE: static::STATE_APPLIED, # yes, has to be ACTIVE to validate invite code
|
'status' => $inviteCode ? static::STATE_ACTIVE : static::STATE_APPLIED, # yes, has to be ACTIVE to validate invite code
|
||||||
'invitation_code' => $inviteCode,
|
'invitation_code' => $inviteCode,
|
||||||
'referrer_id' => $referrerId,
|
'referrer_id' => $referrerId,
|
||||||
'profile' => ['ip' => $ip, 'user_agent' => $ua]
|
'profile' => ['ip' => $ip, 'user_agent' => $ua]
|
||||||
|
@ -116,15 +116,15 @@ class Prefinery
|
||||||
$apcEnabled = extension_loaded('apc') && ini_get('apc.enabled');
|
$apcEnabled = extension_loaded('apc') && ini_get('apc.enabled');
|
||||||
if ($apcEnabled)
|
if ($apcEnabled)
|
||||||
{
|
{
|
||||||
apc_delete('prefinery-user-'.$testerData['id']);
|
apc_delete('prefinery-user-' . $testerData['id']);
|
||||||
}
|
}
|
||||||
return static::put('/testers/' . $testerData['id'], ['tester' => array_diff_key(array_filter($testerData), ['id' => null])], false);
|
return static::put('/testers/' . $testerData['id'], ['tester' => array_diff_key(array_filter($testerData), ['id' => null])], false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function put($endpoint, array $data = [])
|
protected static function put($endpoint, array $data = [])
|
||||||
{
|
{
|
||||||
$apiKey = Config::get('prefinery_key');
|
$apiKey = Config::get('prefinery_key');
|
||||||
$options = static::$curlOptions;
|
$options = static::$curlOptions;
|
||||||
$options['headers'][] = 'X-HTTP-Method-Override: PUT';
|
$options['headers'][] = 'X-HTTP-Method-Override: PUT';
|
||||||
return static::decodePrefineryResponse(
|
return static::decodePrefineryResponse(
|
||||||
Curl::put(static::DOMAIN . static::PREFIX . $endpoint . '.json?api_key=' . $apiKey, $data, $options)
|
Curl::put(static::DOMAIN . static::PREFIX . $endpoint . '.json?api_key=' . $apiKey, $data, $options)
|
||||||
|
@ -133,10 +133,24 @@ class Prefinery
|
||||||
|
|
||||||
protected static function get($endpoint, array $data = [])
|
protected static function get($endpoint, array $data = [])
|
||||||
{
|
{
|
||||||
$apiKey = Config::get('prefinery_key');
|
$apiKey = Config::get('prefinery_key');
|
||||||
return static::decodePrefineryResponse(
|
$tries = 0;
|
||||||
Curl::get(static::DOMAIN . static::PREFIX . $endpoint . '.json?api_key=' . $apiKey, $data, array_merge(static::$curlOptions, ['retry' => 3]))
|
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function post($endpoint, array $data = [], $allowEmptyResponse = true)
|
protected static function post($endpoint, array $data = [], $allowEmptyResponse = true)
|
||||||
|
|
Loading…
Add table
Reference in a new issue