Add checking if date schedule is more than 24 hours before adding to cache. Add advance orders to cache when refreshing. #535
This commit is contained in:
parent
032489d736
commit
f5f321b506
2 changed files with 20 additions and 5 deletions
|
|
@ -48,8 +48,12 @@ class RefreshLatestActiveJobOrderCacheCommand extends Command
|
||||||
|
|
||||||
fwrite($tmp_cache_log, 'Cleared latest active jo cache...' . "\n");
|
fwrite($tmp_cache_log, 'Cleared latest active jo cache...' . "\n");
|
||||||
|
|
||||||
$date = new DateTime();
|
// get JOs -5 and +22 hours from current datetime
|
||||||
$date->modify('-5 hour');
|
$start_date = new DateTime();
|
||||||
|
$start_date->modify('-5 hour');
|
||||||
|
|
||||||
|
$end_date = new DateTime();
|
||||||
|
$end_date->modify('+22 hour');
|
||||||
|
|
||||||
$status_list = [
|
$status_list = [
|
||||||
JOStatus::PENDING,
|
JOStatus::PENDING,
|
||||||
|
|
@ -63,9 +67,11 @@ class RefreshLatestActiveJobOrderCacheCommand extends Command
|
||||||
->createQueryBuilder('jo');
|
->createQueryBuilder('jo');
|
||||||
$res = $qb->select('jo')
|
$res = $qb->select('jo')
|
||||||
->where('jo.status IN (:statuses)')
|
->where('jo.status IN (:statuses)')
|
||||||
->andWhere('jo.date_schedule >= :date')
|
->andWhere('jo.date_schedule >= :start_date')
|
||||||
|
->andWhere('jo.date_schedule <= :end_date')
|
||||||
->setParameter('statuses', $status_list, Connection::PARAM_STR_ARRAY)
|
->setParameter('statuses', $status_list, Connection::PARAM_STR_ARRAY)
|
||||||
->setParameter('date', $date)
|
->setParameter('start_date', $start_date)
|
||||||
|
->setParameter('end_date', $end_date)
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,9 @@ use App\Service\JobOrderCache;
|
||||||
use App\Ramcar\JOStatus;
|
use App\Ramcar\JOStatus;
|
||||||
use App\Entity\JobOrder;
|
use App\Entity\JobOrder;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
use DateInterval;
|
||||||
|
|
||||||
class JobOrderActiveCacheListener
|
class JobOrderActiveCacheListener
|
||||||
{
|
{
|
||||||
protected $key;
|
protected $key;
|
||||||
|
|
@ -82,7 +85,13 @@ class JobOrderActiveCacheListener
|
||||||
$this->jo_cache->addActiveJobOrder($jo);
|
$this->jo_cache->addActiveJobOrder($jo);
|
||||||
|
|
||||||
// save in latest JO cache
|
// save in latest JO cache
|
||||||
$this->jo_cache->addLatestActiveJoborder($jo);
|
// check if date_schedule is more than 24 hours
|
||||||
|
$date = new DateTime();
|
||||||
|
$interval = new DateInterval('P1D');
|
||||||
|
$date->sub($interval);
|
||||||
|
|
||||||
|
if ($jo->getDateSchedule() >= $date)
|
||||||
|
$this->jo_cache->addLatestActiveJoborder($jo);
|
||||||
|
|
||||||
// publish to mqtt
|
// publish to mqtt
|
||||||
$coords = $jo->getCoordinates();
|
$coords = $jo->getCoordinates();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue