laravel / telescope

An elegant debug assistant for the Laravel framework.
https://laravel.com/docs/telescope
MIT License
4.88k stars 582 forks source link

Some jobs stay in Pending Status. More info given to help re-create #577

Closed jonnywilliamson closed 4 years ago

jonnywilliamson commented 5 years ago

@themsaid

So I have seen the previous issues related to this https://github.com/laravel/telescope/issues/507 https://github.com/laravel/telescope/issues/503 https://github.com/laravel/telescope/issues/411

And I'm suffering the same problem. Some of my jobs are reporting as PENDING even though I know they have completed successfully, and also HORIZON shows the same job as being done correctly.

I've spent a lot of time trying to recreate this using as minimal amount of code as possible, and I hope I've succeeded in providing you with an example that will replicate on your system.

Very quickly as an overall picture.

Here's some code.

// web.php
Route::get('/test', function () {
    dispatch(new \App\Jobs\LongJob());
    return "done";
});
// \App\Jobs\LongJob.php
<?php

namespace App\Jobs;

use App\Events\SendUpdate;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

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

    public $tries = 1;
    public $timeout = 120;

    public function handle()
    {
        sleep(5);
        event(new SendUpdate("The first time is:" . time()));
        sleep(5);
        event(new SendUpdate("The second time is:" . time()));
        sleep(10);
    }
}
// App\Events\SendUpdate.php
<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class SendUpdate implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    private $message;
    public $broadcastQueue = 'broadcast';

    public function __construct($message)
    {
        $this->message = $message;
    }

    public function broadcastOn()
    {
        return new PrivateChannel('App.User.1');
    }
}

I have started horizon, and ensured that it is processing jobs from "default" and "broadcast" queues.

Now when I start the whole process job (hitting "/test" in the browser) I'll get the following:

image

But in horizon it's perfect: image

The next post is some info on my debugging attempts.

nunomaduro commented 1 year ago

@tuktukvlad @rvzug The fix I've made is disabled for Laravel Vapor, as it would dispatch some extra jobs for existing customers. This could represent an extra amount of jobs that customers would not be expecting.

rvzug commented 1 year ago

@nunomaduro Ok, I guess pending in our case is mainly "something went wrong". How can I see what went wrong, as we have no telescope-updates and also no Horizon or worker-cli to see what went wrong? The only way is the Vapor logs in the vapor backend?

ChristopherDosin commented 11 months ago

We have the same issue with Vapor and Laravel 9.

c0ntr-all commented 8 months ago

I also have this problem, but because of the wrong time zone in config.

jonnywilliamson commented 8 months ago

@c0ntr-all Could you expand on that? What do you mean by a wrong timezone in the config. Surely all timezones are valid, no matter which one is used?

tuyennv22ntq commented 3 weeks ago

Still happening, Laravel 11.9, telescope 5.2