AddBimToConvertQueue.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\BimFile;
  4. use App\Models\Enums\BimFileConvertStatus;
  5. use App\Services\File\BIM\BIMFactory;
  6. use Carbon\Carbon;
  7. use Illuminate\Console\Command;
  8. use Illuminate\Database\Eloquent\Collection;
  9. class AddBimToConvertQueue extends Command
  10. {
  11. /**
  12. * The name and signature of the console command.
  13. *
  14. * @var string
  15. */
  16. protected $signature = 'lpc:add-bim-to-convert-queue';
  17. /**
  18. * The console command description.
  19. *
  20. * @var string
  21. */
  22. protected $description = 'Timed push of bim files to conversion queue';
  23. /**
  24. * Execute the console command.
  25. */
  26. public function handle()
  27. {
  28. BimFile::query()
  29. ->where("created_at", ">=", Carbon::now()->subDay())
  30. ->whereIn("convert_status", [BimFileConvertStatus::NotAdded->value, BimFileConvertStatus::FAILED_TO_ADD_QUEUE->value])
  31. ->chunkById(2000, function (Collection $bimFiles) {
  32. $this->pushToQueue($bimFiles);
  33. });
  34. }
  35. protected function pushToQueue(Collection $bimFiles)
  36. {
  37. foreach ($bimFiles as $bimFile) {
  38. try {
  39. BIMFactory::make($bimFile->bim_driver)->addToConvertQueue($bimFile->bim_data_set_id);
  40. $bimFile->convert_status = BimFileConvertStatus::IN_QUEUE;
  41. } catch (\Exception $exception) {
  42. $bimFile->convert_status = BimFileConvertStatus::FAILED_TO_ADD_QUEUE;
  43. $bimFile->error = $exception->getMessage();
  44. }
  45. $bimFile->save();
  46. }
  47. }
  48. }