Update rider status when job order status is changed #362
This commit is contained in:
parent
2e3c879fd5
commit
de9e803ad4
1 changed files with 34 additions and 1 deletions
|
|
@ -35,6 +35,7 @@ class JobOrderActiveCacheListener
|
|||
$this->processActiveJO($jo);
|
||||
break;
|
||||
// inactive
|
||||
// NOTE: should never really get here since it's creation
|
||||
case JOStatus::CANCELLED:
|
||||
$this->processInactiveJO($jo, 'cancel');
|
||||
break;
|
||||
|
|
@ -84,10 +85,23 @@ class JobOrderActiveCacheListener
|
|||
$coords = $jo->getCoordinates();
|
||||
|
||||
// TODO: do we put the key in config?
|
||||
// send jo location
|
||||
$this->mqtt->publish(
|
||||
'jo/' . $jo->getID() . '/location',
|
||||
$coords->getLatitude() . ':' . $coords->getLongitude()
|
||||
);
|
||||
|
||||
// TODO: do we still need to send jo status?
|
||||
|
||||
// send rider status
|
||||
$rider = $jo->getRider();
|
||||
if ($rider != null)
|
||||
{
|
||||
$this->mqtt->publish(
|
||||
'rider/' . $rider->getID() . '/status',
|
||||
'jo'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function processInactiveJO($jo, $status = 'cancel')
|
||||
|
|
@ -96,11 +110,30 @@ class JobOrderActiveCacheListener
|
|||
// remove from redis cache
|
||||
$this->jo_cache->removeActiveJobOrder($jo);
|
||||
|
||||
// TODO: publich to mqtt
|
||||
// publish to mqtt
|
||||
// send jo status
|
||||
$this->mqtt->publish(
|
||||
'jo/' . $jo->getID() . '/status',
|
||||
$status
|
||||
);
|
||||
|
||||
// send rider status
|
||||
$rider = $jo->getRider();
|
||||
if ($rider != null)
|
||||
{
|
||||
// check if rider has any queued jobs
|
||||
$open_jos = $rider->getOpenJobOrders();
|
||||
if (count($open_jos) > 0)
|
||||
$rider_status = 'jo';
|
||||
else
|
||||
$rider_status = 'available';
|
||||
|
||||
// send status
|
||||
$this->mqtt->publish(
|
||||
'rider/' . $rider->getID() . '/status',
|
||||
$rider_status
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue