Merge branch '362-cmb-fix-dashboard-status-change' into '270-final-cmb-fixes'

Update rider status when job order status is changed #362

See merge request jankstudio/resq!406
This commit is contained in:
Kendrick Chan 2020-03-05 00:58:36 +00:00
commit d2a4b95805

View file

@ -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
);
}
}
}