diff --git a/config/services.yaml b/config/services.yaml index 4249102e..e7cec9ea 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -86,7 +86,6 @@ services: $host: "%env(REDIS_CLIENT_HOST)%" $port: "%env(REDIS_CLIENT_PORT)%" $password: "%env(REDIS_CLIENT_PASSWORD)%" - $env_flag: "dev" App\Service\GeofenceTracker: arguments: @@ -204,3 +203,18 @@ services: App\Service\GISManagerInterface: "@App\\Service\\GISManager\\OpenStreet" #App\Service\GISManagerInterface: "@App\\Service\\GISManager\\Google" + App\EventListener\JobOrderActiveCache: + arguments: + $redis: "@App\\Service\\RedisClientProvider" + $key: "%env(JO_ACTIVE_CACHE_KEY)%" + $mqtt: "@App\\Service\\MQTTClient" + tags: + - name: 'doctrine.orm.entity_listener' + event: 'postUpdate' + entity: 'App\Entity\JobOrder' + - name: 'doctrine.orm.entity_listener' + event: 'postRemove' + entity: 'App\Entity\JobOrder' + - name: 'doctrine.orm.entity_listener' + event: 'postPersist' + entity: 'App\Entity\JobOrder' diff --git a/src/EventListener/JobOrderActiveCache.php b/src/EventListener/JobOrderActiveCache.php new file mode 100644 index 00000000..fb82b22c --- /dev/null +++ b/src/EventListener/JobOrderActiveCache.php @@ -0,0 +1,77 @@ +redis = $redis->getRedisClient(); + $this->key = $key; + $this->mqtt = $mqtt; + } + + // when a new job order comes in + public function postPersist(JobOrder $jo, LifecycleEventArgs $args) + { + $status = $jo->getStatus(); + + switch ($status) + { + // active + case JOStatus::PENDING: + case JOStatus::RIDER_ASSIGN: + case JOStatus::ASSIGNED: + case JOStatus::IN_TRANSIT: + case JOStatus::IN_PROGRESS: + $this->processActiveJO($jo); + break; + // inactive + case JOStatus::CANCELLED: + case JOStatus::FULFILLED: + $this->processInactiveJO($jo); + break; + } + } + + // when a job order is updated + public function postUpdate(JobOrder $jo, LifecycleEventArgs $args) + { + } + + // when a job order is deleted + public function postRemove(JobOrder $jo, LifecycleEventArgs $args) + { + } + + protected function processActiveJO($jo) + { + $coords = $jo->getCoordinates(); + + // put in redis cache + error_log('add ' . $this->key . ' - (' . $coords->getLongitude() . ', ' . $coords->getLatitude() . ') - ' . $jo->getID()); + $this->redis->geoadd($this->key, $coords->getLongitude(), $coords->getLatitude(), $jo->getID()); + + // TODO: publish to mqtt + } + + protected function processInactiveJO($jo) + { + // TODO: remove from redis cache + + // TODO: publich to mqtt + } +} + diff --git a/translations/messages.en.yaml b/translations/messages.en.yaml index 04ebdc42..992f8de9 100644 --- a/translations/messages.en.yaml +++ b/translations/messages.en.yaml @@ -26,4 +26,4 @@ default_lat: 14.6091 default_long: 121.0223 #default_lat: 3.084216 #default_long: 101.6129996 -default_region: my +default_region: ph