Set rider's availability after JOs are requeued. #630
This commit is contained in:
parent
9b7852d248
commit
f8ebe0d97a
1 changed files with 17 additions and 2 deletions
|
|
@ -50,7 +50,9 @@ 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 FROM job_order WHERE status = :current_status and TIMESTAMPDIFF(MINUTE, date_assign, NOW()) >= :timeout';
|
||||
// need rider id to set rider to available since rider becomes unavailable
|
||||
// the minute JO is assigned to rider
|
||||
$query_sql = 'SELECT id, rider_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,9 +65,12 @@ 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 for the event sending after update of JOs
|
||||
// and the updating of rider's availability
|
||||
$requeued_jos[] = [
|
||||
'jo_id' => $row[0],
|
||||
'rider_id' => $row[1],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -83,11 +88,12 @@ class UpdateUnacceptedJobOrdersCommand extends Command
|
|||
foreach ($requeued_jos as $jo_info)
|
||||
{
|
||||
$jo_id = $jo_info['jo_id'];
|
||||
$rider_id = $jo_info['rider_id'];
|
||||
|
||||
$jo = $em->getRepository(JobOrder::class)->find($jo_id);
|
||||
if ($jo != null)
|
||||
{
|
||||
$output->writeln('Requeuing for rider assignmen ' . $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
|
||||
|
|
@ -105,8 +111,17 @@ class UpdateUnacceptedJobOrdersCommand extends Command
|
|||
];
|
||||
$mclient->sendEvent($jo, $payload);
|
||||
}
|
||||
|
||||
$rider = $em->getRepository(Rider::class)->find($rider_id);
|
||||
if ($rider != null)
|
||||
{
|
||||
// set rider's availability to true
|
||||
$rider->setAvailable(true);
|
||||
}
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue