diff --git a/.env.dist b/.env.dist
index 2829219e..4c0b202a 100644
--- a/.env.dist
+++ b/.env.dist
@@ -28,3 +28,10 @@ RT_SHORTCODE=1234
MQTT_IP_ADDRESS=localhost
MQTT_PORT=8883
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
+#
diff --git a/config/services.yaml b/config/services.yaml
index 154d6708..6c7464e2 100644
--- a/config/services.yaml
+++ b/config/services.yaml
@@ -66,14 +66,19 @@ services:
App\Service\MQTTClient:
arguments:
- $ip_address: "%env(MQTT_IP_ADDRESS)%"
- $port: "%env(MQTT_PORT)%"
- $cert: "%env(MQTT_CERT)%"
+ $redis_client: "@App\\Service\\RedisClientProvider"
App\Service\APNSClient:
arguments:
- $ip_address: "%env(APNS_REDIS_IP_ADDRESS)%"
- $port: "%env(APNS_REDIS_PORT)%"
+ $redis_client: "@App\\Service\\RedisClientProvider"
+
+ 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:
arguments:
diff --git a/src/Command/TestHubCounterCommand.php b/src/Command/TestHubCounterCommand.php
new file mode 100644
index 00000000..e08c11dd
--- /dev/null
+++ b/src/Command/TestHubCounterCommand.php
@@ -0,0 +1,39 @@
+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";
+ }
+}
diff --git a/src/Service/APNSClient.php b/src/Service/APNSClient.php
index 2fc02fe9..4a1e561b 100644
--- a/src/Service/APNSClient.php
+++ b/src/Service/APNSClient.php
@@ -5,7 +5,6 @@ namespace App\Service;
use Mosquitto\Client as MosquittoClient;
use App\Entity\JobOrder;
use App\Ramcar\MobileOSType;
-use Redis;
class APNSClient
{
@@ -14,16 +13,15 @@ class APNSClient
// protected $mclient;
protected $redis;
- public function __construct($ip_address, $port)
+ public function __construct(RedisClientProvider $redis_client)
{
- $this->redis = new Redis();
- $this->redis->connect($ip_address, $port);
+ $this->redis = $redis_client->getRedisClient();
}
- public function __destruct()
- {
+ public function __destruct()
+ {
// $this->mclient->disconnect();
- }
+ }
public function push($token, $message)
{
diff --git a/src/Service/HubCounter.php b/src/Service/HubCounter.php
index 6fa52819..62d663ac 100644
--- a/src/Service/HubCounter.php
+++ b/src/Service/HubCounter.php
@@ -15,13 +15,10 @@ class HubCounter
protected $em;
protected $redis;
- public function __construct(EntityManagerInterface $em)
+ public function __construct(EntityManagerInterface $em, RedisClientProvider $redis_client)
{
$this->em = $em;
-
- // TODO: make it read redis settings from config
- // build a service maybe?
- $this->redis = new Predis\Client();
+ $this->redis = $redis_client->getRedisClient();
}
// get rider key based on id
@@ -45,7 +42,7 @@ class HubCounter
return $value;
// not in cache
- $hub = $em->getRepository(Hub::class)->find($hub_id);
+ $hub = $this->em->getRepository(Hub::class)->find($hub_id);
$riders = $hub->getActiveRiders();
$rider_count = count($riders);
diff --git a/src/Service/MQTTClient.php b/src/Service/MQTTClient.php
index 79fa9dac..aa0932a3 100644
--- a/src/Service/MQTTClient.php
+++ b/src/Service/MQTTClient.php
@@ -4,7 +4,6 @@ namespace App\Service;
use Mosquitto\Client as MosquittoClient;
use App\Entity\JobOrder;
-use Redis;
class MQTTClient
{
@@ -15,27 +14,15 @@ class MQTTClient
// protected $mclient;
protected $redis;
- public function __construct($ip_address, $port, $cert)
+ public function __construct(RedisClientProvider $redis_client)
{
- // we use redis now
- // 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);
- */
+ $this->redis = $redis_client->getRedisClient();
}
- public function __destruct()
- {
+ public function __destruct()
+ {
// $this->mclient->disconnect();
- }
+ }
public function publish($channel, $message)
{
diff --git a/src/Service/RedisClientProvider.php b/src/Service/RedisClientProvider.php
new file mode 100644
index 00000000..04ac1f80
--- /dev/null
+++ b/src/Service/RedisClientProvider.php
@@ -0,0 +1,44 @@
+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;
+ }
+}
diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig
index 352ba4e4..1d3e0275 100644
--- a/templates/job-order/form.html.twig
+++ b/templates/job-order/form.html.twig
@@ -893,7 +893,8 @@
{% endblock %}
{% block scripts %}
-
+
+