Last active
May 28, 2019 13:38
-
-
Save rmccullagh/2e5ab30a2c8b02ffde3aeca89224ffaf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Api\Site\Progress; | |
use \Illuminate\Redis\Connections\PhpRedisConnection; | |
use \Illuminate\Contracts\Routing\ResponseFactory; | |
use \Psr\Log\LoggerInterface; | |
use App\Http\Api\Constants\AmezmoApi; | |
use App\Http\Api\BaseApiController; | |
use App\Http\Api\Site\Progress\Models\ProgressReport; | |
use App\Utils\JsonEncoder; | |
class SiteProgressController extends BaseApiController | |
{ | |
/** @var \Illuminate\Redis\Connections\PhpRedisConnection */ | |
private $redis; | |
/** @var \Illuminate\Contracts\Routing\ResponseFactory */ | |
private $responseFactory; | |
/** @var \Psr\Log\LoggerInterface $logger*/ | |
private $logger; | |
/** @var \App\Utils\JsonEncoder */ | |
private $json; | |
public function __construct( | |
PhpRedisConnection $redis, | |
JsonEncoder $json, | |
ResponseFactory $response, | |
LoggerInterface $logger | |
) { | |
$this->redis = $redis; | |
$this->json = $json; | |
$this->responseFactory = $response; | |
$this->logger = $logger; | |
$this->ttl = AmezmoApi::PROGRESS_MESSAGE_TTL; | |
} | |
public function report(ProgressReport $report) | |
{ | |
if ($report->step === 0) { | |
$package = ['percentage' => 100, 'message' => 'Failed']; | |
$this->logger->error('got error signal from container instance engine'); | |
} else { | |
$package = ['percentage' => $report->step, 'message' => $report->message]; | |
} | |
$this->redis->setEx(stubbedProgressKey() $this->ttl, $this->json->encode($package)); | |
return $this->responseFactory->noContent(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment