Viewing file: AppServiceProvider.php (1.85 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\Providers;
use App\Models\EmailQueue; use App\Models\MessageLog; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Queue; use Illuminate\Support\ServiceProvider; use Illuminate\Queue\Events\JobProcessed; use Illuminate\Queue\Events\JobProcessing;
class AppServiceProvider extends ServiceProvider { /** * Register any application services. * * @return void */ public function register() { // }
/** * Bootstrap any application services. * * @return void */ public function boot() { Queue::after(function (JobProcessed $event) { $payload = $event->job->payload(); $data = unserialize($payload['data']['command']); if (isset($data->data)) { foreach ($data->data as $s) { if (isset($s->email_queue_id)) { $emailQueue = EmailQueue::where('id', $s->email_queue_id)->first(); if (!$event->job->hasFailed()) { EmailQueue::where('id', $emailQueue->id)->update(['delivered_at' => now()]); if ($emailQueue->random_ref_key) { MessageLog::where('random_ref_key', $emailQueue->random_ref_key)->update(['queue_id' => $emailQueue->id, 'status' => 'succeed']); } } else { EmailQueue::where('id', $emailQueue->id)->update(['status' => 'failed']); if ($emailQueue->random_ref_key) { MessageLog::where('random_ref_key', $emailQueue->random_ref_key)->update(['queue_id' => $emailQueue->id, 'status' => 'failed']); } }
} } }
}); } }
|