From de9e803ad460f12b8ed8add3c74dec06478d2cb8 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Thu, 5 Mar 2020 08:57:32 +0800 Subject: [PATCH] Update rider status when job order status is changed #362 --- .../JobOrderActiveCacheListener.php | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/EventListener/JobOrderActiveCacheListener.php b/src/EventListener/JobOrderActiveCacheListener.php index b5dbbd83..89eedd01 100644 --- a/src/EventListener/JobOrderActiveCacheListener.php +++ b/src/EventListener/JobOrderActiveCacheListener.php @@ -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 + ); + } } }