Restore legacy MQTTClient, add new MQTTClientApiv2 class for new customer api #730
This commit is contained in:
parent
1d278beb35
commit
4f06c02bd4
15 changed files with 213 additions and 81 deletions
|
|
@ -67,6 +67,11 @@ services:
|
|||
$redis_client: "@App\\Service\\RedisClientProvider"
|
||||
$key: "mqtt_events"
|
||||
|
||||
App\Service\MQTTClientApiv2:
|
||||
arguments:
|
||||
$redis_client: "@App\\Service\\RedisClientProvider"
|
||||
$key: "mqtt_events"
|
||||
|
||||
App\Service\APNSClient:
|
||||
arguments:
|
||||
$redis_client: "@App\\Service\\RedisClientProvider"
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use App\Service\MQTTClient;
|
||||
use App\Service\MQTTClientApiv2;
|
||||
|
||||
use App\Entity\JobOrder;
|
||||
use App\Entity\Rider;
|
||||
|
|
@ -21,11 +22,17 @@ class UpdateUnacceptedJobOrdersCommand extends Command
|
|||
protected $em;
|
||||
protected $mclient;
|
||||
|
||||
public function __construct(EntityManagerInterface $em, MQTTClient $mclient)
|
||||
// NOTE: for resq2 app
|
||||
protected $mclientv2;
|
||||
|
||||
public function __construct(EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->mclient = $mclient;
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$this->mclientv2 = $mclientv2;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
|
@ -41,6 +48,9 @@ class UpdateUnacceptedJobOrdersCommand extends Command
|
|||
$em = $this->em;
|
||||
$mclient = $this->mclient;
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$mclientv2 = $this->mclientv2;
|
||||
|
||||
// TODO: get the timeout limit from .env
|
||||
$timeout = 3;
|
||||
$current_status = 'assigned';
|
||||
|
|
@ -107,6 +117,9 @@ class UpdateUnacceptedJobOrdersCommand extends Command
|
|||
'jo_id' => $id,
|
||||
];
|
||||
$mclient->sendEvent($jo, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$mclientv2->sendEvent($jo, $payload);
|
||||
}
|
||||
|
||||
$rider = $jo->getRider();
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ use App\Entity\ApiUser as APIUser;
|
|||
use App\Service\RedisClientProvider;
|
||||
use App\Service\RiderCache;
|
||||
use App\Service\MQTTClient;
|
||||
use App\Service\MQTTClientApiv2;
|
||||
use App\Service\WarrantyHandler;
|
||||
use App\Service\JobOrderHandlerInterface;
|
||||
use App\Service\InvoiceGeneratorInterface;
|
||||
|
|
@ -437,7 +438,7 @@ class RiderAppController extends APIController
|
|||
|
||||
}
|
||||
|
||||
public function cancelJobOrder(Request $req, EntityManagerInterface $em, MQTTClient $mclient)
|
||||
public function cancelJobOrder(Request $req, EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2)
|
||||
{
|
||||
$required_params = ['jo_id'];
|
||||
|
||||
|
|
@ -483,6 +484,9 @@ class RiderAppController extends APIController
|
|||
];
|
||||
$mclient->sendEvent($jo, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$mclientv2->sendEvent($jo, $payload);
|
||||
|
||||
$data = [];
|
||||
return new APIResponse(true, 'Job order requeued.', $data);
|
||||
}
|
||||
|
|
@ -648,7 +652,7 @@ class RiderAppController extends APIController
|
|||
|
||||
}
|
||||
|
||||
public function arrive(Request $req, EntityManagerInterface $em, MQTTClient $mclient)
|
||||
public function arrive(Request $req, EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2)
|
||||
{
|
||||
$required_params = ['jo_id'];
|
||||
|
||||
|
|
@ -698,6 +702,9 @@ class RiderAppController extends APIController
|
|||
];
|
||||
$mclient->sendEvent($jo, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$mclientv2->sendEvent($jo, $payload);
|
||||
|
||||
$data = [];
|
||||
return new APIResponse(true, 'Rider arrived at customer location.', $data);
|
||||
}
|
||||
|
|
@ -749,7 +756,7 @@ class RiderAppController extends APIController
|
|||
}
|
||||
|
||||
public function payment(Request $req, EntityManagerInterface $em, JobOrderHandlerInterface $jo_handler,
|
||||
RisingTideGateway $rt, WarrantyHandler $wh, MQTTClient $mclient, TranslatorInterface $translator)
|
||||
RisingTideGateway $rt, WarrantyHandler $wh, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, TranslatorInterface $translator)
|
||||
{
|
||||
$required_params = ['jo_id'];
|
||||
|
||||
|
|
@ -871,6 +878,9 @@ class RiderAppController extends APIController
|
|||
];
|
||||
$mclient->sendEvent($jo, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$mclientv2->sendEvent($jo, $payload);
|
||||
|
||||
$data = [];
|
||||
return new APIResponse(true, 'Job order paid and fulfilled.', $data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
|||
|
||||
use App\Service\InvoiceGeneratorInterface;
|
||||
use App\Service\MQTTClient;
|
||||
use App\Service\MQTTClientApiv2;
|
||||
use App\Service\RiderTracker;
|
||||
use App\Service\GeofenceTracker;
|
||||
use App\Service\MapTools;
|
||||
|
|
@ -473,7 +474,7 @@ class JobOrderController extends ApiController
|
|||
GeofenceTracker $geo,
|
||||
MapTools $map_tools,
|
||||
InventoryManager $im,
|
||||
MQTTClient $mclient,
|
||||
MQTTClientApiv2 $mclientv2,
|
||||
RiderAssignmentHandlerInterface $rah,
|
||||
PromoLogger $promo_logger,
|
||||
HubSelector $hub_select,
|
||||
|
|
@ -837,7 +838,7 @@ class JobOrderController extends ApiController
|
|||
$payload = [
|
||||
'event' => 'outlet_assign'
|
||||
];
|
||||
$mclient->sendEvent($jo, $payload);
|
||||
$mclientv2->sendEvent($jo, $payload);
|
||||
|
||||
$rah->assignJobOrder($jo, $jo->getRider());
|
||||
}
|
||||
|
|
@ -855,7 +856,7 @@ class JobOrderController extends ApiController
|
|||
$payload = [
|
||||
'event' => 'outlet_assign'
|
||||
];
|
||||
$mclient->sendEvent($jo, $payload);
|
||||
$mclientv2->sendEvent($jo, $payload);
|
||||
}
|
||||
|
||||
$this->em->flush();
|
||||
|
|
@ -929,7 +930,7 @@ class JobOrderController extends ApiController
|
|||
GeofenceTracker $geo,
|
||||
MapTools $map_tools,
|
||||
InventoryManager $im,
|
||||
MQTTClient $mclient,
|
||||
MQTTClientApiv2 $mclientv2,
|
||||
RiderAssignmentHandlerInterface $rah,
|
||||
PromoLogger $promo_logger,
|
||||
HubSelector $hub_select,
|
||||
|
|
@ -1181,7 +1182,7 @@ class JobOrderController extends ApiController
|
|||
$payload = [
|
||||
'event' => 'outlet_assign'
|
||||
];
|
||||
$mclient->sendEvent($jo, $payload);
|
||||
$mclientv2->sendEvent($jo, $payload);
|
||||
|
||||
$rah->assignJobOrder($jo, $jo->getRider());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ use App\Service\JobOrderHandlerInterface;
|
|||
use App\Service\GISManagerInterface;
|
||||
use App\Service\MapTools;
|
||||
use App\Service\MQTTClient;
|
||||
use App\Service\MQTTClientApiv2;
|
||||
use App\Service\APNSClient;
|
||||
use App\Service\InventoryManager;
|
||||
use App\Service\HubSelector;
|
||||
|
|
@ -29,8 +30,6 @@ use App\Service\RiderTracker;
|
|||
use App\Service\MotivConnector;
|
||||
|
||||
use App\Service\GeofenceTracker;
|
||||
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
|
|
@ -355,7 +354,7 @@ class JobOrderController extends Controller
|
|||
return $this->render($template, $params);
|
||||
}
|
||||
|
||||
public function processingSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, $id)
|
||||
public function processingSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, $id)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('jo_proc.list', null, 'No access.');
|
||||
|
||||
|
|
@ -363,7 +362,7 @@ class JobOrderController extends Controller
|
|||
$error_array = [];
|
||||
try
|
||||
{
|
||||
$error_array = $jo_handler->dispatchJobOrder($req, $id, $mclient);
|
||||
$error_array = $jo_handler->dispatchJobOrder($req, $id, $mclient, $mclientv2);
|
||||
}
|
||||
catch (AccessDeniedHttpException $e)
|
||||
{
|
||||
|
|
@ -682,7 +681,7 @@ class JobOrderController extends Controller
|
|||
]);
|
||||
}
|
||||
|
||||
public function cancelJobOrder(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, $id)
|
||||
public function cancelJobOrder(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, $id)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('joborder.cancel', null, 'No access.');
|
||||
|
||||
|
|
@ -699,7 +698,7 @@ class JobOrderController extends Controller
|
|||
|
||||
try
|
||||
{
|
||||
$jo_handler->cancelJobOrder($req, $id, $mclient);
|
||||
$jo_handler->cancelJobOrder($req, $id, $mclient, $mclientv2);
|
||||
}
|
||||
catch (NotFoundHttpException $e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ use App\Ramcar\DeliveryStatus;
|
|||
use App\Service\InvoiceGeneratorInterface;
|
||||
use App\Service\RisingTideGateway;
|
||||
use App\Service\MQTTClient;
|
||||
use App\Service\MQTTClientApiv2;
|
||||
use App\Service\GeofenceTracker;
|
||||
use App\Service\InventoryManager;
|
||||
use App\Service\RiderAssignmentHandlerInterface;
|
||||
|
|
@ -72,7 +73,7 @@ class JobOrderController extends APIController
|
|||
|
||||
// TODO: break this monolithic method down
|
||||
public function requestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
|
||||
InventoryManager $im, MQTTClient $mclient,
|
||||
InventoryManager $im, MQTTClient $mclient, MQTTClientApiv2 $mclientv2,
|
||||
RiderAssignmentHandlerInterface $rah, PromoLogger $promo_logger,
|
||||
HubSelector $hub_select, HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger,
|
||||
HubFilteringGeoChecker $hub_geofence, EntityManagerInterface $em)
|
||||
|
|
@ -353,6 +354,9 @@ class JobOrderController extends APIController
|
|||
];
|
||||
$mclient->sendEvent($jo, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$mclientv2->sendEvent($jo, $payload);
|
||||
|
||||
$rah->assignJobOrder($jo, $jo->getRider());
|
||||
}
|
||||
|
||||
|
|
@ -371,6 +375,9 @@ class JobOrderController extends APIController
|
|||
'event' => 'outlet_assign'
|
||||
];
|
||||
$mclient->sendEvent($jo, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$mclientv2->sendEvent($jo, $payload);
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ use App\Service\RiderAssignmentHandlerInterface;
|
|||
use App\Service\CustomerHandlerInterface;
|
||||
use App\Service\WarrantyHandler;
|
||||
use App\Service\MQTTClient;
|
||||
use App\Service\MQTTClientApiv2;
|
||||
use App\Service\APNSClient;
|
||||
use App\Service\MapTools;
|
||||
|
||||
|
|
@ -668,7 +669,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
|
|||
}
|
||||
|
||||
// dispatch job order
|
||||
public function dispatchJobOrder(Request $req, int $id, MQTTClient $mclient)
|
||||
public function dispatchJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2)
|
||||
{
|
||||
// get object data
|
||||
$em = $this->em;
|
||||
|
|
@ -793,6 +794,9 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
|
|||
'event' => 'outlet_assign'
|
||||
];
|
||||
$mclient->sendEvent($obj, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$mclientv2->sendEvent($obj, $payload);
|
||||
}
|
||||
|
||||
return $error_array;
|
||||
|
|
@ -1027,7 +1031,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
|
|||
}
|
||||
|
||||
// cancel job order
|
||||
public function cancelJobOrder(Request $req, int $id, MQTTClient $mclient)
|
||||
public function cancelJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2)
|
||||
{
|
||||
// get object data
|
||||
$em = $this->em;
|
||||
|
|
@ -1068,10 +1072,13 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
|
|||
];
|
||||
$mclient->sendEvent($obj, $payload);
|
||||
$mclient->sendRiderEvent($obj, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$mclientv2->sendEvent($obj, $payload);
|
||||
}
|
||||
|
||||
// set hub for job order
|
||||
public function setHub($req, $id, $mclient)
|
||||
public function setHub($req, $id, $mclient, $mclientv2)
|
||||
{
|
||||
// get object data
|
||||
$em = $this->em;
|
||||
|
|
@ -1171,6 +1178,9 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
|
|||
'event' => 'outlet_assign'
|
||||
];
|
||||
$mclient->sendEvent($obj, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$mclientv2->sendEvent($obj, $payload);
|
||||
}
|
||||
|
||||
return $error_array;
|
||||
|
|
@ -1272,7 +1282,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
|
|||
}
|
||||
|
||||
// set rider for job order
|
||||
public function setRider($req, $id, $mclient)
|
||||
public function setRider($req, $id, $mclient, $mclientv2)
|
||||
{
|
||||
// initialize error list
|
||||
$error_array = [];
|
||||
|
|
@ -1372,6 +1382,9 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
|
|||
];
|
||||
$mclient->sendEvent($obj, $payload);
|
||||
$mclient->sendRiderEvent($obj, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$mclientv2->sendEvent($obj, $payload);
|
||||
}
|
||||
|
||||
return $error_array;
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ use App\Service\JobOrderHandlerInterface;
|
|||
use App\Service\RiderAssignmentHandlerInterface;
|
||||
use App\Service\WarrantyHandler;
|
||||
use App\Service\MQTTClient;
|
||||
use App\Service\MQTTClientApiv2;
|
||||
use App\Service\APNSClient;
|
||||
use App\Service\MapTools;
|
||||
use App\Service\RisingTideGateway;
|
||||
|
|
@ -803,7 +804,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
}
|
||||
|
||||
// dispatch job order
|
||||
public function dispatchJobOrder(Request $req, int $id, MQTTClient $mclient)
|
||||
public function dispatchJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2)
|
||||
{
|
||||
// get object data
|
||||
$em = $this->em;
|
||||
|
|
@ -982,6 +983,10 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
];
|
||||
$mclient->sendEvent($obj, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$mclientv2->sendEvent($obj, $payload);
|
||||
|
||||
|
||||
// update redis hub jo count
|
||||
$this->hub_dist->incrementJoCountForHub($hub);
|
||||
}
|
||||
|
|
@ -1337,7 +1342,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
}
|
||||
|
||||
// cancel job order
|
||||
public function cancelJobOrder(Request $req, int $id, MQTTClient $mclient)
|
||||
public function cancelJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2)
|
||||
{
|
||||
// get object data
|
||||
$em = $this->em;
|
||||
|
|
@ -1382,10 +1387,13 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
];
|
||||
$mclient->sendEvent($obj, $payload);
|
||||
$mclient->sendRiderEvent($obj, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$mclientv2->sendEvent($obj, $payload);
|
||||
}
|
||||
|
||||
// set hub for job order
|
||||
public function setHub($req, $id, $mclient)
|
||||
public function setHub($req, $id, $mclient, $mclientv2)
|
||||
{
|
||||
// get object data
|
||||
$em = $this->em;
|
||||
|
|
@ -1560,6 +1568,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
];
|
||||
$mclient->sendEvent($obj, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$mclientv2->sendEvent($obj, $payload);
|
||||
|
||||
// update redis hub_jo_count for hub
|
||||
// decrement old hub's count and increment new hub's count
|
||||
if ($old_hub != null)
|
||||
|
|
@ -1667,7 +1678,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
}
|
||||
|
||||
// set rider for job order
|
||||
public function setRider($req, $id, $mclient)
|
||||
public function setRider($req, $id, $mclient, $mclientv2)
|
||||
{
|
||||
// initialize error list
|
||||
$error_array = [];
|
||||
|
|
@ -1840,6 +1851,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
];
|
||||
$mclient->sendEvent($obj, $payload);
|
||||
$mclient->sendRiderEvent($obj, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$mclientv2->sendEvent($obj, $payload);
|
||||
}
|
||||
|
||||
return $error_array;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace App\Service;
|
|||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
use App\Service\MQTTClient;
|
||||
use App\Service\MQTTClientApiv2;
|
||||
use App\Service\APNSClient;
|
||||
use App\Service\MapTools;
|
||||
use App\Service\HubSelector;
|
||||
|
|
@ -29,7 +30,7 @@ interface JobOrderHandlerInterface
|
|||
public function processOneStepJobOrder(Request $req, int $id);
|
||||
|
||||
// dispatch job order
|
||||
public function dispatchJobOrder(Request $req, int $id, MQTTClient $mclient);
|
||||
public function dispatchJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2);
|
||||
|
||||
// assign job order
|
||||
public function assignJobOrder(Request $req, int $id);
|
||||
|
|
@ -38,16 +39,16 @@ interface JobOrderHandlerInterface
|
|||
public function fulfillJobOrder(Request $req, int $id);
|
||||
|
||||
// cancel job order
|
||||
public function cancelJobOrder(Request $req, int $id, MQTTClient $mclient);
|
||||
public function cancelJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2);
|
||||
|
||||
// set hub for job order
|
||||
public function setHub(Request $req, int $id, MQTTClient $mclient);
|
||||
public function setHub(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2);
|
||||
|
||||
// reject hub for job order
|
||||
public function rejectHub(Request $req, int $id);
|
||||
|
||||
// set rider for job order
|
||||
public function setRider(Request $req, int $id, MQTTClient $mclient);
|
||||
public function setRider(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2);
|
||||
|
||||
// unlock processor
|
||||
public function unlockProcessor(int $id);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ use App\Entity\JobOrder;
|
|||
class MQTTClient
|
||||
{
|
||||
const PREFIX = 'motolite.control.';
|
||||
const PREFIX_APIv2 = 'motolite.control.v2.';
|
||||
const RIDER_PREFIX = 'motorider_';
|
||||
|
||||
// protected $mclient;
|
||||
|
|
@ -36,39 +35,11 @@ class MQTTClient
|
|||
|
||||
public function sendEvent(JobOrder $job_order, $payload)
|
||||
{
|
||||
error_log("CUSTOMER ID: " . $job_order->getCustomer()->getID());
|
||||
//error_log('sending mqtt event: ');
|
||||
//error_log(print_r($payload, true));
|
||||
|
||||
// get all new and legacy mobile sessions
|
||||
$legacy_sessions = $job_order->getCustomer()->getMobileSessions();
|
||||
|
||||
$new_sessions = [];
|
||||
$cust_user = $job_order->getCustomer()->getCustomerUser();
|
||||
if (!empty($cust_user)) {
|
||||
error_log("CUSTOMER USER ID: " . $cust_user->getID());
|
||||
$new_sessions = $cust_user->getMobileSessions();
|
||||
}
|
||||
|
||||
// TODO: make this more elegant. looping through each instead of merging the two because doctrine returns PersistentCollection if empty, and array if not
|
||||
$sessions = [];
|
||||
foreach ($legacy_sessions as $sess) {
|
||||
error_log("FOUND LEGACY SESSION: " . $sess->getID());
|
||||
$sessions[] = [
|
||||
'data' => $sess,
|
||||
'legacy' => true,
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($new_sessions as $sess) {
|
||||
error_log("FOUND NEW SESSION: " . $sess->getID());
|
||||
$sessions[] = [
|
||||
'data' => $sess,
|
||||
'legacy' => false,
|
||||
];
|
||||
}
|
||||
|
||||
if (empty($sessions))
|
||||
$sessions = $job_order->getCustomer()->getMobileSessions();
|
||||
if (count($sessions) == 0)
|
||||
{
|
||||
error_log("no sessions to send mqtt event to");
|
||||
return;
|
||||
|
|
@ -79,24 +50,11 @@ class MQTTClient
|
|||
// send to every customer session
|
||||
foreach ($sessions as $sess)
|
||||
{
|
||||
$phone_num = $sess['data']->getPhoneNumber();
|
||||
|
||||
$channel_payload = $payload;
|
||||
|
||||
// keep channel and payload for legacy the same
|
||||
if ($sess['legacy']) {
|
||||
$prefix = self::PREFIX;
|
||||
} else {
|
||||
$prefix = self::PREFIX_APIv2;
|
||||
$channel_payload['jo_id'] = $job_order->getID();
|
||||
}
|
||||
|
||||
$channel = $prefix . $phone_num;
|
||||
|
||||
error_log("SENDING TO CHANNEL: " . $channel);
|
||||
$phone_num = $sess->getPhoneNumber();
|
||||
$channel = self::PREFIX . $phone_num;
|
||||
|
||||
// gather channels, so we only send once
|
||||
$channels[$channel] = json_encode($channel_payload);
|
||||
$channels[$channel] = json_encode($payload);
|
||||
}
|
||||
|
||||
foreach ($channels as $channel => $json_payload)
|
||||
|
|
|
|||
71
src/Service/MQTTClientApiv2.php
Normal file
71
src/Service/MQTTClientApiv2.php
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Mosquitto\Client as MosquittoClient;
|
||||
use App\Entity\JobOrder;
|
||||
|
||||
class MQTTClientApiv2
|
||||
{
|
||||
const PREFIX = 'motolite.control.v2.';
|
||||
|
||||
// protected $mclient;
|
||||
protected $redis;
|
||||
protected $key;
|
||||
|
||||
public function __construct(RedisClientProvider $redis_client, $key)
|
||||
{
|
||||
$this->redis = $redis_client->getRedisClient();
|
||||
$this->key = $key;
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
// $this->mclient->disconnect();
|
||||
}
|
||||
|
||||
public function publish($channel, $message)
|
||||
{
|
||||
// $this->mclient->publish($channel, $message);
|
||||
|
||||
$data = $channel . '|' . $message;
|
||||
$this->redis->lpush($this->key, $data);
|
||||
}
|
||||
|
||||
public function sendEvent(JobOrder $job_order, $payload)
|
||||
{
|
||||
//error_log('sending mqtt event: ');
|
||||
//error_log(print_r($payload, true));
|
||||
|
||||
// get all v2 sessions
|
||||
$sessions = [];
|
||||
$cust_user = $job_order->getCustomer()->getCustomerUser();
|
||||
if (!empty($cust_user)) {
|
||||
$sessions = $cust_user->getMobileSessions();
|
||||
}
|
||||
|
||||
if (empty($sessions)) {
|
||||
error_log("no sessions to send mqtt event to");
|
||||
return;
|
||||
}
|
||||
|
||||
$channels = [];
|
||||
|
||||
// send to every customer session
|
||||
foreach ($sessions as $sess) {
|
||||
$phone_num = $sess->getPhoneNumber();
|
||||
$channel = self::PREFIX . $phone_num;
|
||||
|
||||
// attach jo id to all payloads
|
||||
$payload['jo_id'] = $job_order->getID();
|
||||
|
||||
// gather channels, so we only send once
|
||||
$channels[$channel] = json_encode($payload);
|
||||
}
|
||||
|
||||
foreach ($channels as $channel => $json_payload) {
|
||||
$this->publish($channel, $json_payload);
|
||||
// error_log('sent to ' . $channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,7 @@ use App\Service\RiderAPIHandlerInterface;
|
|||
use App\Service\RedisClientProvider;
|
||||
use App\Service\RiderCache;
|
||||
use App\Service\MQTTClient;
|
||||
use App\Service\MQTTClientApiv2;
|
||||
use App\Service\WarrantyHandler;
|
||||
use App\Service\JobOrderHandlerInterface;
|
||||
use App\Service\InvoiceGeneratorInterface;
|
||||
|
|
@ -42,6 +43,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
protected $rcache;
|
||||
protected $country_code;
|
||||
protected $mclient;
|
||||
protected $mclientv2;
|
||||
protected $wh;
|
||||
protected $jo_handler;
|
||||
protected $ic;
|
||||
|
|
@ -49,7 +51,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
|
||||
public function __construct(EntityManagerInterface $em, RedisClientProvider $redis,
|
||||
EncoderFactoryInterface $ef, RiderCache $rcache,
|
||||
string $country_code, MQTTClient $mclient,
|
||||
string $country_code, MQTTClient $mclient, MQTTClientApiv2 $mclientv2,
|
||||
WarrantyHandler $wh, JobOrderHandlerInterface $jo_handler,
|
||||
InvoiceGeneratorInterface $ic)
|
||||
{
|
||||
|
|
@ -59,6 +61,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
$this->rcache = $rcache;
|
||||
$this->country_code = $country_code;
|
||||
$this->mclient = $mclient;
|
||||
$this->mclientv2 = $mclientv2;
|
||||
$this->wh = $wh;
|
||||
$this->jo_handler = $jo_handler;
|
||||
$this->ic = $ic;
|
||||
|
|
@ -424,6 +427,9 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
];
|
||||
$this->mclient->sendEvent($jo, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$this->mclientv2->sendEvent($jo, $payload);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
|
@ -465,6 +471,9 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
];
|
||||
$this->mclient->sendEvent($jo, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$this->mclientv2->sendEvent($jo, $payload);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
|
@ -578,6 +587,9 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
];
|
||||
$this->mclient->sendEvent($jo, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$this->mclientv2->sendEvent($jo, $payload);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ use App\Service\RiderAPIHandlerInterface;
|
|||
use App\Service\RedisClientProvider;
|
||||
use App\Service\RiderCache;
|
||||
use App\Service\MQTTClient;
|
||||
use App\Service\MQTTClientApiv2;
|
||||
use App\Service\WarrantyHandler;
|
||||
use App\Service\JobOrderHandlerInterface;
|
||||
use App\Service\InvoiceGeneratorInterface;
|
||||
|
|
@ -47,6 +48,7 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
protected $rcache;
|
||||
protected $country_code;
|
||||
protected $mclient;
|
||||
protected $mclientv2;
|
||||
protected $wh;
|
||||
protected $jo_handler;
|
||||
protected $ic;
|
||||
|
|
@ -56,7 +58,7 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
|
||||
public function __construct(EntityManagerInterface $em, RedisClientProvider $redis,
|
||||
EncoderFactoryInterface $ef, RiderCache $rcache,
|
||||
string $country_code, MQTTClient $mclient,
|
||||
string $country_code, MQTTClient $mclient, MQTTClientApiv2 $mclientv2,
|
||||
WarrantyHandler $wh, JobOrderHandlerInterface $jo_handler,
|
||||
InvoiceGeneratorInterface $ic, RisingTideGateway $rt,
|
||||
RiderTracker $rider_tracker, TranslatorInterface $translator)
|
||||
|
|
@ -67,6 +69,7 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
$this->rcache = $rcache;
|
||||
$this->country_code = $country_code;
|
||||
$this->mclient = $mclient;
|
||||
$this->mclientv2 = $mclientv2;
|
||||
$this->wh = $wh;
|
||||
$this->jo_handler = $jo_handler;
|
||||
$this->ic = $ic;
|
||||
|
|
@ -466,6 +469,9 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
];
|
||||
$this->mclient->sendEvent($jo, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$this->mclientv2->sendEvent($jo, $payload);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
|
@ -507,6 +513,9 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
];
|
||||
$this->mclient->sendEvent($jo, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$this->mclientv2->sendEvent($jo, $payload);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
|
@ -661,6 +670,9 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
];
|
||||
$this->mclient->sendEvent($jo, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$this->mclientv2->sendEvent($jo, $payload);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use Doctrine\ORM\EntityManagerInterface;
|
|||
|
||||
use App\Service\RiderAssignmentHandlerInterface;
|
||||
use App\Service\MQTTClient;
|
||||
use App\Service\MQTTClientApiv2;
|
||||
use App\Service\APNSClient;
|
||||
|
||||
use App\Entity\JobOrder;
|
||||
|
|
@ -18,12 +19,13 @@ class CMBRiderAssignmentHandler implements RiderAssignmentHandlerInterface
|
|||
protected $em;
|
||||
protected $aclient;
|
||||
protected $mclient;
|
||||
protected $mclientv2;
|
||||
|
||||
public function __construct(EntityManagerInterface $em, MQTTClient $mclient,
|
||||
APNSClient $aclient)
|
||||
public function __construct(EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, APNSClient $aclient)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->mclient = $mclient;
|
||||
$this->mclientv2 = $mclientv2;
|
||||
$this->aclient = $aclient;
|
||||
}
|
||||
|
||||
|
|
@ -38,6 +40,9 @@ class CMBRiderAssignmentHandler implements RiderAssignmentHandlerInterface
|
|||
// send event
|
||||
$this->mclient->sendEvent($obj, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$this->mclientv2->sendEvent($obj, $payload);
|
||||
|
||||
// check if rider is available
|
||||
if ($rider->isAvailable())
|
||||
{
|
||||
|
|
@ -66,6 +71,9 @@ class CMBRiderAssignmentHandler implements RiderAssignmentHandlerInterface
|
|||
];
|
||||
$this->mclient->sendEvent($obj, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$this->mclientv2->sendEvent($obj, $payload);
|
||||
|
||||
// send fulfill/complete event to rider
|
||||
$this->mclient->sendRiderEvent($obj, $payload);
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||
|
||||
use App\Service\RiderAssignmentHandlerInterface;
|
||||
use App\Service\MQTTClient;
|
||||
use App\Service\MQTTClientApiv2;
|
||||
use App\Service\APNSClient;
|
||||
|
||||
use App\Entity\JobOrder;
|
||||
|
|
@ -20,13 +21,14 @@ class ResqRiderAssignmentHandler implements RiderAssignmentHandlerInterface
|
|||
protected $em;
|
||||
protected $aclient;
|
||||
protected $mclient;
|
||||
protected $mclientv2;
|
||||
protected $translator;
|
||||
|
||||
public function __construct(EntityManagerInterface $em, MQTTClient $mclient,
|
||||
APNSClient $aclient, TranslatorInterface $translator)
|
||||
public function __construct(EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, APNSClient $aclient, TranslatorInterface $translator)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->mclient = $mclient;
|
||||
$this->mclientv2 = $mclientv2;
|
||||
$this->aclient = $aclient;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
|
@ -42,6 +44,9 @@ class ResqRiderAssignmentHandler implements RiderAssignmentHandlerInterface
|
|||
// send event
|
||||
$this->mclient->sendEvent($obj, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$this->mclientv2->sendEvent($obj, $payload);
|
||||
|
||||
// check if rider is available
|
||||
if ($rider->isAvailable())
|
||||
{
|
||||
|
|
@ -72,6 +77,9 @@ class ResqRiderAssignmentHandler implements RiderAssignmentHandlerInterface
|
|||
];
|
||||
$this->mclient->sendEvent($obj, $payload);
|
||||
|
||||
// NOTE: for resq2 app
|
||||
$this->mclientv2->sendEvent($obj, $payload);
|
||||
|
||||
// send fulfill/complete event to rider
|
||||
$this->mclient->sendRiderEvent($obj, $payload);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue