Add sending of mqtt events. #630

This commit is contained in:
Korina Cordero 2021-10-20 05:34:43 +00:00
parent c2066b86c9
commit d366106381
2 changed files with 19 additions and 11 deletions

View file

@ -50,7 +50,7 @@ class UpdateUnacceptedJobOrdersCommand extends Command
// since we need the actual job orders for mqtt events, we need to get the ids of the job orders
// that will be updated
$query_sql = 'SELECT id, rider_id FROM job_order WHERE status = :current_status and TIMESTAMPDIFF(MINUTE, date_assign, NOW()) >= :timeout';
$query_sql = 'SELECT id FROM job_order WHERE status = :current_status and TIMESTAMPDIFF(MINUTE, date_assign, NOW()) >= :timeout';
$query_stmt = $db->prepare($query_sql);
$query_stmt->execute([
@ -63,11 +63,9 @@ class UpdateUnacceptedJobOrdersCommand extends Command
while ($row = $query_stmt->fetch(PDO::FETCH_NUM))
{
// $row[0] is the jo id
// $row[1] is the rider id
// store the ids for now, until the jos have been updated
// store the ids for now for the event sending after update of JOs
$requeued_jos[] = [
'jo_id' => $row[0],
'rider_id' => $row[1],
];
}
@ -90,15 +88,23 @@ class UpdateUnacceptedJobOrdersCommand extends Command
$jo = $em->getRepository(JobOrder::class)->find($jo_id);
if ($jo != null)
{
$output->writeln($jo->getID());
$output->writeln('Requeuing for rider assignmen ' . $jo->getID());
$id = $jo->getID();
// send notifications to rider app, telling rider that jo has been requeued
$rider_payload = [
'event' => 'cancelled',
'reason' => 'Reassigned',
'jo_id' => $id,
];
$mclient->sendRiderEvent($jo, $rider_payload);
// send notification to mobile app for customer, telling customer that jo has been requeued
//$mobile_payload = [
//];
//$mclient->sendEvent();
// send outlet assign since order should go back to hub and await reassignment to another rider
$payload = [
'event' => 'outlet_assign',
'jo_id' => $id,
];
$mclient->sendEvent($jo, $payload);
}
}

View file

@ -50,6 +50,8 @@ class ResqRiderAssignmentHandler implements RiderAssignmentHandlerInterface
// send push notification
$this->aclient->sendPush($obj, "A RESQ rider is on his way to you.");
$this->em->flush();
}
}