Browse Source

always send last location in callback payload

pull/23/head
Aaron Parecki 6 years ago
parent
commit
09f03ffa95
No known key found for this signature in database GPG Key ID: 276C2817346D6056
2 changed files with 6 additions and 7 deletions
  1. +1
    -1
      compass/app/Http/Controllers/Api.php
  2. +5
    -6
      compass/app/Jobs/NotifyOfNewLocations.php

+ 1
- 1
compass/app/Http/Controllers/Api.php View File

@ -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);
}
}

+ 5
- 6
compass/app/Jobs/NotifyOfNewLocations.php View File

@ -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);
}

Loading…
Cancel
Save