Hirvesh
Hirvesh

Reputation: 7974

Laravel job executing multiple times in queue

Hi I have a laravel job as follows:

namespace App\Jobs;

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

use Timeline\Timeline;

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

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle(Timeline $timeline, $tag)
    {
        $tagData = $timeline->getTagFeed($tag)->getRankedItems();

        if ($tagData) {
            echo "boom";
        }    
    }
}

I'm running it via a route as follows:

Route::get('/queue', function () {
    $timeline= new Timeline();

    $timeline->login("test", "testpwd");
    Queue::later(5, new testQueue($timeline, "Testtag"));
});

Then on the commandline I ran:

php artisan queue:listen database

However, that one job is running 255 times instead of 1 times and exiting successfully.

What am I doing wrong?

Upvotes: 0

Views: 1077

Answers (2)

Amit Sharma
Amit Sharma

Reputation: 2477

Delete the job after execution.

Upvotes: 0

ch271828n
ch271828n

Reputation: 17567

The documentation states:

Binary data, such as raw image contents, should be passed through the base64_encode function before being passed to a queued job. Otherwise, the job may not properly serialize to JSON when being placed on the queue.

So you shouldn't use public function handle(Timeline $timeline, $tag) (or public function handle(Instagram $currentInstagram, $tag) in your conversation, as the Timeline or something is binary data.

Upvotes: 1

Related Questions