Merge branch '206-redis-service' into 'master'
Resolve "Redis service" Closes #206 See merge request jankstudio/resq!241
This commit is contained in:
commit
f62a904822
8 changed files with 115 additions and 37 deletions
|
|
@ -28,3 +28,10 @@ RT_SHORTCODE=1234
|
||||||
MQTT_IP_ADDRESS=localhost
|
MQTT_IP_ADDRESS=localhost
|
||||||
MQTT_PORT=8883
|
MQTT_PORT=8883
|
||||||
MQTT_CERT=/location/of/cert/file.crt
|
MQTT_CERT=/location/of/cert/file.crt
|
||||||
|
|
||||||
|
# redis client
|
||||||
|
REDIS_CLIENT_SCHEME=tcp
|
||||||
|
REDIS_CLIENT_HOST=127.0.0.1
|
||||||
|
REDIS_CLIENT_PORT=6379
|
||||||
|
REDIS_CLIENT_PASSWORD=foobared
|
||||||
|
#
|
||||||
|
|
|
||||||
|
|
@ -66,14 +66,19 @@ services:
|
||||||
|
|
||||||
App\Service\MQTTClient:
|
App\Service\MQTTClient:
|
||||||
arguments:
|
arguments:
|
||||||
$ip_address: "%env(MQTT_IP_ADDRESS)%"
|
$redis_client: "@App\\Service\\RedisClientProvider"
|
||||||
$port: "%env(MQTT_PORT)%"
|
|
||||||
$cert: "%env(MQTT_CERT)%"
|
|
||||||
|
|
||||||
App\Service\APNSClient:
|
App\Service\APNSClient:
|
||||||
arguments:
|
arguments:
|
||||||
$ip_address: "%env(APNS_REDIS_IP_ADDRESS)%"
|
$redis_client: "@App\\Service\\RedisClientProvider"
|
||||||
$port: "%env(APNS_REDIS_PORT)%"
|
|
||||||
|
App\Service\RedisClientProvider:
|
||||||
|
arguments:
|
||||||
|
$scheme: "%env(REDIS_CLIENT_SCHEME)%"
|
||||||
|
$host: "%env(REDIS_CLIENT_HOST)%"
|
||||||
|
$port: "%env(REDIS_CLIENT_PORT)%"
|
||||||
|
$password: "%env(REDIS_CLIENT_PASSWORD)%"
|
||||||
|
$env_flag: "dev"
|
||||||
|
|
||||||
Catalyst\APIBundle\Security\APIKeyUserProvider:
|
Catalyst\APIBundle\Security\APIKeyUserProvider:
|
||||||
arguments:
|
arguments:
|
||||||
|
|
|
||||||
39
src/Command/TestHubCounterCommand.php
Normal file
39
src/Command/TestHubCounterCommand.php
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Command;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
use App\Service\HubCounter;
|
||||||
|
|
||||||
|
class TestHubCounterCommand extends Command
|
||||||
|
{
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this->setName('test:hubcounter')
|
||||||
|
->setDescription('Test hubcounter service. Currently tests addAvailableRider and getAvailableRiderCount.')
|
||||||
|
->setHelp('Test hubcounter service. Currently tests addAvailableRider and getAvailableRiderCount.')
|
||||||
|
->addArgument('hub_id', InputArgument::REQUIRED, 'Hub ID');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __construct(HubCounter $hc)
|
||||||
|
{
|
||||||
|
$this->hc = $hc;
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
$hub_id = $input->getArgument('hub_id');
|
||||||
|
|
||||||
|
$this->hc->addAvailableRider($hub_id);
|
||||||
|
|
||||||
|
$available_rc = $this->hc->getAvailableRiderCount($hub_id);
|
||||||
|
|
||||||
|
echo "Available Riders in Hub: " . $available_rc . "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,7 +5,6 @@ namespace App\Service;
|
||||||
use Mosquitto\Client as MosquittoClient;
|
use Mosquitto\Client as MosquittoClient;
|
||||||
use App\Entity\JobOrder;
|
use App\Entity\JobOrder;
|
||||||
use App\Ramcar\MobileOSType;
|
use App\Ramcar\MobileOSType;
|
||||||
use Redis;
|
|
||||||
|
|
||||||
class APNSClient
|
class APNSClient
|
||||||
{
|
{
|
||||||
|
|
@ -14,16 +13,15 @@ class APNSClient
|
||||||
// protected $mclient;
|
// protected $mclient;
|
||||||
protected $redis;
|
protected $redis;
|
||||||
|
|
||||||
public function __construct($ip_address, $port)
|
public function __construct(RedisClientProvider $redis_client)
|
||||||
{
|
{
|
||||||
$this->redis = new Redis();
|
$this->redis = $redis_client->getRedisClient();
|
||||||
$this->redis->connect($ip_address, $port);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __destruct()
|
public function __destruct()
|
||||||
{
|
{
|
||||||
// $this->mclient->disconnect();
|
// $this->mclient->disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function push($token, $message)
|
public function push($token, $message)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,10 @@ class HubCounter
|
||||||
protected $em;
|
protected $em;
|
||||||
protected $redis;
|
protected $redis;
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $em)
|
public function __construct(EntityManagerInterface $em, RedisClientProvider $redis_client)
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
|
$this->redis = $redis_client->getRedisClient();
|
||||||
// TODO: make it read redis settings from config
|
|
||||||
// build a service maybe?
|
|
||||||
$this->redis = new Predis\Client();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get rider key based on id
|
// get rider key based on id
|
||||||
|
|
@ -45,7 +42,7 @@ class HubCounter
|
||||||
return $value;
|
return $value;
|
||||||
|
|
||||||
// not in cache
|
// not in cache
|
||||||
$hub = $em->getRepository(Hub::class)->find($hub_id);
|
$hub = $this->em->getRepository(Hub::class)->find($hub_id);
|
||||||
$riders = $hub->getActiveRiders();
|
$riders = $hub->getActiveRiders();
|
||||||
$rider_count = count($riders);
|
$rider_count = count($riders);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ namespace App\Service;
|
||||||
|
|
||||||
use Mosquitto\Client as MosquittoClient;
|
use Mosquitto\Client as MosquittoClient;
|
||||||
use App\Entity\JobOrder;
|
use App\Entity\JobOrder;
|
||||||
use Redis;
|
|
||||||
|
|
||||||
class MQTTClient
|
class MQTTClient
|
||||||
{
|
{
|
||||||
|
|
@ -15,27 +14,15 @@ class MQTTClient
|
||||||
// protected $mclient;
|
// protected $mclient;
|
||||||
protected $redis;
|
protected $redis;
|
||||||
|
|
||||||
public function __construct($ip_address, $port, $cert)
|
public function __construct(RedisClientProvider $redis_client)
|
||||||
{
|
{
|
||||||
// we use redis now
|
$this->redis = $redis_client->getRedisClient();
|
||||||
// we have an mqtt server listening on redis and sending to mqtt
|
|
||||||
$this->redis = new Redis();
|
|
||||||
$this->redis->connect('127.0.0.1', 6379);
|
|
||||||
|
|
||||||
/*
|
|
||||||
error_log("connecting to mqtt server - $ip_address : $port");
|
|
||||||
error_log("using $cert");
|
|
||||||
$this->mclient = new MosquittoClient();
|
|
||||||
$this->mclient->setTlsCertificates($cert);
|
|
||||||
$this->mclient->setTlsOptions(MosquittoClient::SSL_VERIFY_NONE, 'tlsv1');
|
|
||||||
$this->mclient->connect($ip_address, $port);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __destruct()
|
public function __destruct()
|
||||||
{
|
{
|
||||||
// $this->mclient->disconnect();
|
// $this->mclient->disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function publish($channel, $message)
|
public function publish($channel, $message)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
44
src/Service/RedisClientProvider.php
Normal file
44
src/Service/RedisClientProvider.php
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
use Predis\Client as PredisClient;
|
||||||
|
|
||||||
|
class RedisClientProvider
|
||||||
|
{
|
||||||
|
protected $redis;
|
||||||
|
protected $scheme;
|
||||||
|
protected $host;
|
||||||
|
protected $port;
|
||||||
|
protected $password;
|
||||||
|
protected $env_flag;
|
||||||
|
|
||||||
|
public function __construct($scheme, $host, $port, $password, $env_flag)
|
||||||
|
{
|
||||||
|
$this->scheme = $scheme;
|
||||||
|
$this->host = $host;
|
||||||
|
$this->port = $port;
|
||||||
|
$this->password = $password;
|
||||||
|
$this->env_flag = $env_flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRedisClient()
|
||||||
|
{
|
||||||
|
if ($this->env_flag == 'dev')
|
||||||
|
{
|
||||||
|
$this->redis = new PredisClient([
|
||||||
|
"scheme"=>$this->scheme,
|
||||||
|
"host"=>$this->host,
|
||||||
|
"port"=>$this->port]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->redis = new PredisClient([
|
||||||
|
"scheme"=>$this->scheme,
|
||||||
|
"host"=>$this->host,
|
||||||
|
"port"=>$this->port,
|
||||||
|
"password"=>$this->password]);
|
||||||
|
}
|
||||||
|
return $this->redis;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -893,7 +893,8 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script src="//maps.google.com/maps/api/js?key={{ gmaps_api_key }}" type="text/javascript"></script>
|
<!-- <script src="//maps.google.com/maps/api/js?key={{ gmaps_api_key }}" type="text/javascript"></script> -->
|
||||||
|
<script src="//maps.googleapis.com/maps/api/js?key={{ gmaps_api_key }}" type="text/javascript"></script>
|
||||||
<script src="/assets/vendors/custom/gmaps/gmaps.js" type="text/javascript"></script>
|
<script src="/assets/vendors/custom/gmaps/gmaps.js" type="text/javascript"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue