Merge branch '478-cmb-move-adding-removing-rider-to-and-from-cache' into '472-cmb-release'
Add checking if rider is available. #478 See merge request jankstudio/resq!557
This commit is contained in:
commit
24a75378c3
1 changed files with 27 additions and 5 deletions
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace App\Service;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use App\Service\RedisClientProvider;
|
||||
use App\Entity\Rider;
|
||||
|
||||
|
|
@ -10,12 +12,14 @@ class RiderCache
|
|||
protected $redis;
|
||||
protected $loc_key;
|
||||
protected $status_key;
|
||||
protected $em;
|
||||
|
||||
public function __construct(RedisClientProvider $redis_prov, $loc_key, $status_key)
|
||||
public function __construct(EntityManagerInterface $em, RedisClientProvider $redis_prov, $loc_key, $status_key)
|
||||
{
|
||||
$this->redis = $redis_prov->getRedisClient();
|
||||
$this->loc_key = $loc_key;
|
||||
$this->status_key = $status_key;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function addActiveRider($id, $lat, $lng)
|
||||
|
|
@ -46,10 +50,15 @@ class RiderCache
|
|||
$lng = $data[1][0];
|
||||
$lat = $data[1][1];
|
||||
|
||||
$locs[$id] = [
|
||||
'longitude' => $lng,
|
||||
'latitude' => $lat,
|
||||
];
|
||||
// get rider details so we can check for availability
|
||||
$rider = $this->getRiderDetails($id);
|
||||
if ($rider != null)
|
||||
{
|
||||
$locs[$id] = [
|
||||
'longitude' => $lng,
|
||||
'latitude' => $lat,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// error_log(print_r($all_riders, true));
|
||||
|
|
@ -73,4 +82,17 @@ class RiderCache
|
|||
{
|
||||
$this->redis->hincrby($this->status_key, $id, -1);
|
||||
}
|
||||
|
||||
protected function getRiderDetails($id)
|
||||
{
|
||||
$rider = $this->em->getRepository(Rider::class)->find($id);
|
||||
if ($rider == null)
|
||||
return null;
|
||||
|
||||
// return only if available
|
||||
if ($rider->isAvailable())
|
||||
return $rider;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue