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.

47 lines
1.2 KiB

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