| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace App\Jobs\Import;
- use App\Events\SendWebSocketMessageEvent;
- use App\Models\Import;
- use App\Services\ImportMafsService;
- use App\Services\ImportOrdersService;
- use App\Services\ImportReclamationsService;
- use Exception;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Queue\Queueable;
- use Illuminate\Support\Facades\Log;
- class ImportJob implements ShouldQueue
- {
- use Queueable;
- /**
- * Create a new job instance.
- */
- public function __construct(
- private readonly Import $import,
- private readonly int $userId,
- )
- {}
- /**
- * Execute the job.
- */
- public function handle(): void
- {
- try {
- switch($this->import->type) {
- case 'orders':
- (new ImportOrdersService($this->import))->handle();
- break;
- case 'mafs':
- (new ImportMafsService($this->import))->handle();
- break;
- case 'reclamations':
- (new ImportReclamationsService($this->import))->handle();
- break;
- }
- Log::info('Import ' . $this->import->type. ' job done!');
- event(new SendWebSocketMessageEvent('Импорт завершён!', $this->userId, ['path' => $this->import->filename, 'type' => $this->import->type]));
- } catch (Exception $e) {
- Log::info('Import ' . $this->import->type. ' job failed! ERROR: ' . $e->getMessage());
- event(new SendWebSocketMessageEvent('Ошибка импорта! ' . $e->getMessage(), $this->userId, ['error' => $e->getMessage()]));
- }
- }
- }
|