dqtiober37522
2017-06-11 08:04
浏览 240
已采纳

Laravel作业在队列中多次执行

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?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doupike2351 2017-06-11 08:33
    已采纳

    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.

    打赏 评论
  • douzhi0107 2018-03-30 20:48

    Delete the job after execution.

    打赏 评论

相关推荐 更多相似问题