|
@ -10,16 +10,15 @@ use DateTime, DateTimeZone; |
|
|
class NotifyOfNewLocations extends Job implements SelfHandling, ShouldQueue |
|
|
class NotifyOfNewLocations extends Job implements SelfHandling, ShouldQueue |
|
|
{ |
|
|
{ |
|
|
private $_dbid; |
|
|
private $_dbid; |
|
|
private $_last_location; |
|
|
|
|
|
|
|
|
|
|
|
public function __construct($dbid, $last_location) { |
|
|
|
|
|
|
|
|
public function __construct($dbid) { |
|
|
$this->_dbid = $dbid; |
|
|
$this->_dbid = $dbid; |
|
|
$this->_last_location = $last_location; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function handle() { |
|
|
public function handle() { |
|
|
$db = DB::table('databases')->where('id','=',$this->_dbid)->first(); |
|
|
$db = DB::table('databases')->where('id','=',$this->_dbid)->first(); |
|
|
$urls = preg_split('/\s+/', $db->ping_urls); |
|
|
$urls = preg_split('/\s+/', $db->ping_urls); |
|
|
|
|
|
|
|
|
foreach($urls as $url) { |
|
|
foreach($urls as $url) { |
|
|
if(trim($url)) { |
|
|
if(trim($url)) { |
|
|
$ch = curl_init($url); |
|
|
$ch = curl_init($url); |
|
@ -29,12 +28,12 @@ class NotifyOfNewLocations extends Job implements SelfHandling, ShouldQueue |
|
|
'Authorization: Bearer '.$db->read_token, |
|
|
'Authorization: Bearer '.$db->read_token, |
|
|
'Compass-Url: '.env('BASE_URL').'api/last?token='.$db->read_token.'&geocode=1' |
|
|
'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_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
|
curl_exec($ch); |
|
|
curl_exec($ch); |
|
|
$timestamp = ''; |
|
|
$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); |
|
|
Log::info("Notifying ".$url." with current location: ".$timestamp); |
|
|
} |
|
|
} |
|
|