From 09f03ffa95b8e046f4b3237e7c69db4060683dd2 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sun, 28 Jan 2018 16:03:12 -0800 Subject: [PATCH] always send last location in callback payload --- compass/app/Http/Controllers/Api.php | 2 +- compass/app/Jobs/NotifyOfNewLocations.php | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/compass/app/Http/Controllers/Api.php b/compass/app/Http/Controllers/Api.php index 90bddd8..c6d5f16 100644 --- a/compass/app/Http/Controllers/Api.php +++ b/compass/app/Http/Controllers/Api.php @@ -341,7 +341,7 @@ class Api extends BaseController // Notify subscribers that new data is available if($db->ping_urls) { - $job = (new NotifyOfNewLocations($db->id, $last_location))->onQueue('compass'); + $job = (new NotifyOfNewLocations($db->id))->onQueue('compass'); $this->dispatch($job); } } diff --git a/compass/app/Jobs/NotifyOfNewLocations.php b/compass/app/Jobs/NotifyOfNewLocations.php index ff58fab..5f71ad1 100644 --- a/compass/app/Jobs/NotifyOfNewLocations.php +++ b/compass/app/Jobs/NotifyOfNewLocations.php @@ -10,16 +10,15 @@ use DateTime, DateTimeZone; class NotifyOfNewLocations extends Job implements SelfHandling, ShouldQueue { private $_dbid; - private $_last_location; - public function __construct($dbid, $last_location) { + public function __construct($dbid) { $this->_dbid = $dbid; - $this->_last_location = $last_location; } public function handle() { $db = DB::table('databases')->where('id','=',$this->_dbid)->first(); $urls = preg_split('/\s+/', $db->ping_urls); + foreach($urls as $url) { if(trim($url)) { $ch = curl_init($url); @@ -29,12 +28,12 @@ class NotifyOfNewLocations extends Job implements SelfHandling, ShouldQueue 'Authorization: Bearer '.$db->read_token, 'Compass-Url: '.env('BASE_URL').'api/last?token='.$db->read_token.'&geocode=1' ]); - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($this->_last_location)); + curl_setopt($ch, CURLOPT_POSTFIELDS, $db->last_location); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_exec($ch); $timestamp = ''; - if($this->_last_location) { - $timestamp = $this->_last_location['properties']['timestamp']; + if($db->last_location) { + $timestamp = json_decode($db->last_location)->properties->timestamp; } Log::info("Notifying ".$url." with current location: ".$timestamp); }