Fix the command to update unaccepted job orders. Add more checking before updating rider's availability. #630

This commit is contained in:
Korina Cordero 2021-11-08 05:36:59 +00:00
parent 9f5493c125
commit f9de11ccb5
2 changed files with 23 additions and 16 deletions

View file

@ -75,25 +75,21 @@ class UpdateUnacceptedJobOrdersCommand extends Command
$requeued_jos[] = [
'jo' => $requeued_jo,
];
$update_sql = 'UPDATE job_order SET status = :new_status, rider_id = null WHERE id = :jo_id';
$update_stmt = $db->prepare($update_sql);
$update_stmt->execute([
'new_status' => $new_status,
'jo_id' => $jo_id,
]);
}
// update the assigned job orders and have been unaccepted for at least 3 minutes
// change the jo status from assigned to rider_assign and rider id to null
$update_sql = 'UPDATE job_order SET status = :new_status, rider_id = null WHERE status = :current_status and TIMESTAMPDIFF(MINUTE, date_assign, NOW()) >= :timeout';
$update_stmt = $db->prepare($update_sql);
$update_stmt->execute([
'new_status' => $new_status,
'current_status' => $current_status,
'timeout' => $timeout,
]);
foreach ($requeued_jos as $jo_info)
{
$jo = $jo_info['jo'];
if ($jo != null)
{
// $output->writeln('Requeuing for rider assignment ' . $jo->getID());
$output->writeln('Requeuing for rider assignment ' . $jo->getID());
$id = $jo->getID();
// send notifications to rider app, telling rider that jo has been requeued
@ -104,6 +100,7 @@ class UpdateUnacceptedJobOrdersCommand extends Command
];
$mclient->sendRiderEvent($jo, $rider_payload);
// send outlet assign since order should go back to hub and await reassignment to another rider
$payload = [
'event' => 'outlet_assign',
@ -115,11 +112,19 @@ class UpdateUnacceptedJobOrdersCommand extends Command
$rider = $jo->getRider();
if ($rider != null)
{
// set rider's availability to true
$rider->setAvailable(true);
// check rider's current job order before changing rider's availability
// since rider's current job order is set when JO is assigned to rider
if ($rider->getCurrentJobOrder() != null)
{
if ($rider->getCurrentJobOrder()->getID() == $jo->getID())
{
// reset rider's availability to true
$rider->setAvailable(true);
// set rider's current job order to null
$rider->setCurrentJobOrder();
// set rider's current job order to null
$rider->setCurrentJobOrder();
}
}
}
}

View file

@ -565,6 +565,8 @@ class RiderController extends Controller
public function riderActiveJO(EntityManagerInterface $em, MQTTClient $mclient, Rider $rider, $jo_id)
{
$jo = $em->getRepository(JobOrder::class)->find($jo_id);
// TODO: change this to setCurrentJobOrder since this is what is being used to set rider's
// job order. It is no longer using setActiveJobOrder.
$rider->setActiveJobOrder($jo);
$em->flush();