| @@ -7,11 +7,18 @@ use Illuminate\Contracts\Queue\ShouldQueue; | |||||
| use Illuminate\Foundation\Bus\Dispatchable; | use Illuminate\Foundation\Bus\Dispatchable; | ||||
| use Illuminate\Queue\InteractsWithQueue; | use Illuminate\Queue\InteractsWithQueue; | ||||
| use Illuminate\Queue\SerializesModels; | use Illuminate\Queue\SerializesModels; | ||||
| use Illuminate\Support\Facades\Log; | |||||
| abstract class BaseJob implements ShouldQueue | abstract class BaseJob implements ShouldQueue | ||||
| { | { | ||||
| use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||||
| public function handle() | |||||
| { | |||||
| $this->logConfig(); | |||||
| $this->handleJob(); | |||||
| } | |||||
| /** | /** | ||||
| * ジョブを再試行する前に待機する秒数を計算 | * ジョブを再試行する前に待機する秒数を計算 | ||||
| */ | */ | ||||
| @@ -19,4 +26,13 @@ abstract class BaseJob implements ShouldQueue | |||||
| { | { | ||||
| return 5; | return 5; | ||||
| } | } | ||||
| abstract protected function handleJob(); | |||||
| private function logConfig() | |||||
| { | |||||
| Log::withContext([ | |||||
| '__job_class__' => staitc::class, | |||||
| ]); | |||||
| } | |||||
| } | } | ||||
| @@ -24,12 +24,7 @@ class SimpleEmail extends BaseJob | |||||
| $this->onQueue(QueueName::EMAIL->value); | $this->onQueue(QueueName::EMAIL->value); | ||||
| } | } | ||||
| /** | |||||
| * Execute the job. | |||||
| * | |||||
| * @return void | |||||
| */ | |||||
| public function handle() | |||||
| protected function handleJob() | |||||
| { | { | ||||
| try { | try { | ||||
| Sender::send($this->emailId); | Sender::send($this->emailId); | ||||
| @@ -27,12 +27,7 @@ class DeleteFile extends BaseJob | |||||
| logger("FILE削除JOB登録:" . $this->storagePath); | logger("FILE削除JOB登録:" . $this->storagePath); | ||||
| } | } | ||||
| /** | |||||
| * Execute the job. | |||||
| * | |||||
| * @return void | |||||
| */ | |||||
| public function handle() | |||||
| protected function handleJob() | |||||
| { | { | ||||
| if (Storage::exists($this->storagePath)) { | if (Storage::exists($this->storagePath)) { | ||||
| Storage::delete($this->storagePath); | Storage::delete($this->storagePath); | ||||
| @@ -4,11 +4,11 @@ namespace App\Providers; | |||||
| use App\Codes\EnvironmentName; | use App\Codes\EnvironmentName; | ||||
| use App\Codes\QueueName; | use App\Codes\QueueName; | ||||
| use App\Codes\SMSProviderName; | |||||
| use Illuminate\Queue\Events\JobProcessing; | use Illuminate\Queue\Events\JobProcessing; | ||||
| use Illuminate\Support\Facades\Log; | use Illuminate\Support\Facades\Log; | ||||
| use Illuminate\Support\Facades\Queue; | use Illuminate\Support\Facades\Queue; | ||||
| use Illuminate\Support\ServiceProvider; | use Illuminate\Support\ServiceProvider; | ||||
| use Illuminate\Support\Str; | |||||
| class AppServiceProvider extends ServiceProvider | class AppServiceProvider extends ServiceProvider | ||||
| { | { | ||||
| @@ -39,6 +39,10 @@ class AppServiceProvider extends ServiceProvider | |||||
| } else if ($queueName === QueueName::JOB->value) { | } else if ($queueName === QueueName::JOB->value) { | ||||
| Log::setDefaultDriver('queue-job'); | Log::setDefaultDriver('queue-job'); | ||||
| } | } | ||||
| Log::withContext([ | |||||
| '__job_uuid__' => strval(Str::uuid()), | |||||
| ]); | |||||
| }); | }); | ||||