Remove default API client timeouts, fix time on anime calculation

This commit is contained in:
Timothy Warren 2018-12-06 16:21:02 -05:00
parent 8272cc7240
commit 4b9f97f49e
3 changed files with 20 additions and 9 deletions

View File

@ -97,11 +97,15 @@ final class UserTransformer extends AbstractTransformer {
/**
* Format the time spent on anime in a more readable format
*
* @param int $minutes
* @param int $seconds
* @return string
*/
private function formatAnimeTime(int $minutes): string
private function formatAnimeTime(int $seconds): string
{
// All the seconds left
$remSeconds = $seconds % 60;
$minutes = ($seconds - $remSeconds) / 60;
$minutesPerDay = 1440;
$minutesPerYear = $minutesPerDay * 365;
@ -111,15 +115,13 @@ final class UserTransformer extends AbstractTransformer {
// Minutes short of a day
$extraMinutes = $minutes % $minutesPerDay;
$days = ($minutes - $extraMinutes) / $minutesPerDay;
// Minutes short of an hour
$remMinutes = $extraMinutes % 60;
$hours = ($extraMinutes - $remMinutes) / 60;
$output = "{$days} days, {$hours} hours, and {$remMinutes} minutes.";
$output = "{$days} days, {$hours} hours, {$remMinutes} minutes, and {$remSeconds} seconds.";
if ($years > 0)
{

View File

@ -19,7 +19,7 @@ namespace Aviat\AnimeClient\API;
use function Amp\call;
use function Amp\Promise\{all, wait};
use Amp\Artax\DefaultClient;
use Amp\Artax\{Client, DefaultClient};
/**
* Class to simplify making and validating simultaneous requests
@ -73,6 +73,10 @@ final class ParallelAPIRequest {
public function makeRequests(): array
{
$client = new DefaultClient();
// Timeouts suck
$client->setOption(Client::OP_TRANSFER_TIMEOUT, 0);
$promises = [];
foreach ($this->requests as $key => $url)
@ -95,6 +99,10 @@ final class ParallelAPIRequest {
public function getResponses(): array
{
$client = new DefaultClient();
// Timeouts suck
$client->setOption(Client::OP_TRANSFER_TIMEOUT, 0);
$promises = [];
foreach ($this->requests as $key => $url)

View File

@ -18,8 +18,7 @@ namespace Aviat\AnimeClient;
use function Amp\Promise\wait;
use Amp\Artax\DefaultClient;
use Amp\Artax\Response;
use Amp\Artax\{Client, DefaultClient, Response};
use Aviat\Ion\ConfigInterface;
use Yosymfony\Toml\{Toml, TomlBuilder};
@ -217,7 +216,9 @@ function checkFolderPermissions(ConfigInterface $config): array
*/
function getResponse ($request): Response
{
return wait((new DefaultClient)->request($request));
$client = new DefaultClient;
$client->setOption(Client::OP_TRANSFER_TIMEOUT, 0);
return wait($client->request($request));
}
/**