Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SamuelSheppard's avatar

Laravel Queue not running the handle method

I'm facing an issue in my production environment. One specific job is not working as expected when specifically called via the scheduler php artisan schedule:run. As it seems, the queue worker does not run through the code in the handle function of the job. Instead, the job is marked as completed in Horizon with a runtime of under a second. The strange thing is that if I run Laravel Tinker on my production server, and push the job manually to the queue it works as expected.

See below for my setup and code snippets.

Does anyone have an idea what the issue is? No code around this specific job has been touched in months, and the issue just showed up randomly last Friday. The server, docker, and Horizon have been restarted several times without any change in the behavior. And no other job has this issue.

Server Setup

Laravel Version: v8.78.1

Laravel Horizon Version: v5.7.18

Docker PHP Image: php:8.1.0-fpm-alpine3.15

App\Console\Kernel.php

protected function schedule(Schedule $schedule)
{
    $schedule->job(new AdExportFile(
            fileName: 'adwords.csv',
            daysToExport: 10,
            header: [
                'Google Click ID',
                'Conversion Name',
                'Conversion Time',
                'Conversion Value',
                'Conversion Currency'
            ],
            timezone: config('app.timezone'),
            origin: Visit::SOURCE_GOOGLE
        ))->hourly();
}

App\Jobs\AdExportFile.php

class AdExportFile implements ShouldQueue
{
    use Dispatchable;
    use InteractsWithQueue;
    use Queueable;

    public const QUEUE = 'default';

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(
        protected string $fileName,
        protected int $daysToExport,
        protected array $header,
        protected string $timezone,
        protected string $origin,
        protected string $delimiter = ',',
        protected int $minBaseCommission = 5000
    ) {
        $this->onQueue(static::QUEUE);
		\Log::info('AdExportFile: Running __construct');
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
		\Log::info('AdExportFile: Running the handle function');

		Application-specific code...
    }
}

Log output

AdExportFile: Running __construct
0 likes
11 replies
tykus's avatar

Do you have a queue worker running???

EDIT Wait.... is this a queued Job or a scheduled Job?

SamuelSheppard's avatar

@tykus Of course. Otherwise, Horizon would never mark the job as completed, and as stated in the original post, all other jobs work without issue. Including other jobs in the default queue.

SamuelSheppard's avatar

@tykus Correct, the scheduler pushes the job onto the queue, which is then processed but the handle function in the job is not called as we never get the log printed nor the expected outcome.

SamuelSheppard's avatar

@Sinnbeck No, we are not doing something like that. If I push the job to the queue via Tinker it works as expected, the issue only seems to occur when the job is pushed to the queue by the scheduler, which has me very confused.

hadesunseenn's avatar

Faced same issue, On local, it was working fine but on Production, it was just going to the constructor and did not hit handle(). The issue was that I had multiple apps using the same db. So another app was processing the queue.

jctommasi's avatar

I was having the same problem. In the schedule:work console, I could see that the job was running and completing, but it wasn't making any changes in the database. It only worked if I did a push from Tinker. When you execute a job from the scheduler in kernel.php, it pushes it to the 'default' queue. In my queue:work console, it wasn't processing that 'default' queue, which is why I noticed that the scheduler was creating the job, but the code wasn't running because it wasn't listening for new jobs in the 'default' queue. Check if you have any unprocessed jobs in the 'jobs' table. Perhaps you're not processing the queue where the scheduler is sending the new job.

agieswahyudi07's avatar

anyone has solved the problem ? i faced the same problem, the handle function is not working in production, but in local it worked

moghwan's avatar

had the same issue, turns our we were passing to the job a User object with a null id, thus it's not found in the database when querying. we logged if the construct method is accessed and it was, but never the handle method until the object was valid.

how was it detected: go to the pending job (they probably will be failed after restarting horizon) on telescope and check your database queries if they have the correct values in WHERE clause

Please or to participate in this conversation.