Add logging of hub if hub has no available rider. #543

This commit is contained in:
Korina Cordero 2021-03-22 07:16:30 +00:00
parent 4966e7e0c6
commit a5aef93ccb

View file

@ -38,6 +38,7 @@ use App\Service\InventoryManager;
use App\Service\RiderAssignmentHandlerInterface; use App\Service\RiderAssignmentHandlerInterface;
use App\Service\HubSelector; use App\Service\HubSelector;
use App\Service\HubDistributor; use App\Service\HubDistributor;
use App\Service\HubFilterLogger;
use App\Entity\MobileSession; use App\Entity\MobileSession;
use App\Entity\Customer; use App\Entity\Customer;
@ -2334,7 +2335,7 @@ class APIController extends Controller implements LoggedController
public function newRequestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo, public function newRequestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
MapTools $map_tools, InventoryManager $im, MQTTClient $mclient, MapTools $map_tools, InventoryManager $im, MQTTClient $mclient,
RiderAssignmentHandlerInterface $rah, HubSelector $hub_select, RiderAssignmentHandlerInterface $rah, HubSelector $hub_select,
HubDistributor $hub_dist) HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger)
{ {
// check required parameters and api key // check required parameters and api key
$required_params = [ $required_params = [
@ -2548,13 +2549,20 @@ class APIController extends Controller implements LoggedController
// TODO: this might need changes after the new hub selector // TODO: this might need changes after the new hub selector
if (!empty($nearest_hubs)) if (!empty($nearest_hubs))
{ {
// go through the hub list, find the nearest hub
// with an available rider
//error_log('found nearest hub ' . $nearest_hub->getID()); //error_log('found nearest hub ' . $nearest_hub->getID());
// assign rider foreach ($nearest_hubs as $nearest_hub)
$available_riders = $nearest_hubs[0]['hub']->getAvailableRiders(); {
if (count($available_riders) > 0) $available_riders = $nearest_hub['hub']->getAvailableRiders();
if (count($available_riders) >= 1)
{ {
$assigned_rider = null; $assigned_rider = null;
if (count($available_riders) > 1) if (count($available_riders) == 1)
{
$assigned_rider = $available_riders[0];
}
else
{ {
// TODO: the setting of riders into an array // TODO: the setting of riders into an array
// will no longer be necessary when the contents // will no longer be necessary when the contents
@ -2567,11 +2575,8 @@ class APIController extends Controller implements LoggedController
$assigned_rider = $this->randomizeRider($riders); $assigned_rider = $this->randomizeRider($riders);
} }
else
$assigned_rider = $available_riders[0];
//error_log('found rider ' . $assigned_rider->getID()); $jo->setHub($nearest_hub['hub']);
$jo->setHub($nearest_hubs[0]['hub']);
$jo->setRider($assigned_rider); $jo->setRider($assigned_rider);
$jo->setStatus(JOStatus::ASSIGNED); $jo->setStatus(JOStatus::ASSIGNED);
$jo->setStatusAutoAssign(AutoAssignStatus::HUB_AND_RIDER_ASSIGNED); $jo->setStatusAutoAssign(AutoAssignStatus::HUB_AND_RIDER_ASSIGNED);
@ -2579,7 +2584,17 @@ class APIController extends Controller implements LoggedController
$assigned_rider->setAvailable(false); $assigned_rider->setAvailable(false);
// update redis hub_jo_count for hub // update redis hub_jo_count for hub
$hub_dist->incrementJoCountForHub($nearest_hubs[0]['hub']); $hub_dist->incrementJoCountForHub($nearest_hub['hub']);
// break out of loop
break;
}
else
{
// log hub into hub_filter_log
$hub_filter_logger->logFilteredHub($nearest_hub['hub'], 'no_available_rider');
// continue to go through list to find hub with an available rider
}
} }
} }
} }