Skip to content

Instantly share code, notes, and snippets.

@rmccullagh
Last active May 28, 2019 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmccullagh/2e5ab30a2c8b02ffde3aeca89224ffaf to your computer and use it in GitHub Desktop.
Save rmccullagh/2e5ab30a2c8b02ffde3aeca89224ffaf to your computer and use it in GitHub Desktop.
<?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