Skip to content

[BUG] Logs are not sent in Laravel queues #95

@antoinelame

Description

@antoinelame

Description

Logs from an asynchronous job in a Laravel queue are not sent to CloudWatch until you shutdown the queue process.

This is because php artisan queue:work does not close the process. Queue workers do not "reboot" the framework before processing each job.

How to reproduce

  1. Create a new job:
<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

class TestJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function handle()
    {
        Log::info('The job has been executed');
    }
}
  1. Create a new route:
use App\Jobs\TestJob;

Route::get('dispatch-job', function () {
    TestJob::dispatch();
});
  1. Run the queue:
php artisan queue:work

Note: make sure that in your .env you do not use the sync queue driver.

  1. Call GET /dispatch-job

You will receive the logs in CloudWatch only when you'll interrupt the queue:work command. Not before.

Related GitHub issues

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions