You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.3 KiB

  1. <?php
  2. namespace App\Jobs;
  3. use DB, Log;
  4. use App\Jobs\Job;
  5. use Illuminate\Contracts\Bus\SelfHandling;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use DateTime, DateTimeZone;
  8. class NotifyOfNewLocations extends Job implements SelfHandling, ShouldQueue
  9. {
  10. private $_dbid;
  11. private $_last_location;
  12. public function __construct($dbid, $last_location) {
  13. $this->_dbid = $dbid;
  14. $this->_last_location = $last_location;
  15. }
  16. public function handle() {
  17. $db = DB::table('databases')->where('id','=',$this->_dbid)->first();
  18. $urls = preg_split('/\s+/', $db->ping_urls);
  19. foreach($urls as $url) {
  20. if(trim($url)) {
  21. $ch = curl_init($url);
  22. curl_setopt($ch, CURLOPT_POST, true);
  23. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  24. 'Content-Type: application/json',
  25. 'Authorization: Bearer '.$db->read_token,
  26. 'Compass-Url: '.env('BASE_URL').'api/last?token='.$db->read_token.'&geocode=1'
  27. ]);
  28. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($this->_last_location));
  29. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  30. curl_exec($ch);
  31. $timestamp = '';
  32. if($this->_last_location) {
  33. $timestamp = $this->_last_location['properties']['timestamp'];
  34. }
  35. Log::info("Notifying ".$url." with current location: ".$timestamp);
  36. }
  37. }
  38. }
  39. }