Сериализация «Закрытия» не разрешена Laravel Queue

Я очищаю сайт, чтобы получить некоторые данные, и мне нужно время, поэтому я погуглил и обнаружил, что очередь хороша для этого процесса. Я застрял в этой ошибке.

Serialization of 'Closure' is not allowed

Мой код:

class SiteScraper extends Job implements ShouldQueue
{
    use InteractsWithQueue, SerializesModels;

    protected $client;
    protected $crawler;

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

        $this->client = new Client();
        $this->crawler = $this->client->request('GET', 'example.com/login/');
        $form = $this->crawler->selectButton('Log In')->form();
        $this->crawler = $this->client->submit($form, array('email' => 'useremail', 'pass' => 'pass'));
        $this->crawler->filter('.flash-error')->each(function ($node) {
            print $node->text() . "\n";
        });
    }
 public function handle()
{

    $crawler = $this->client->request('GET', $url_to_traverse);
    $status_code = $this->client->getResponse()->getStatus();

        if($status_code == 200){
            $crawler->filter('.friendBrowserNameTitle > a')->each(function ($node) {
                $names = $node->text() . '<br>';
                $profileurl = $node->attr('href') . '<br>';
                echo "Name : " . $names . "  Profile Link : " . $profileurl;

            });
        }
        else{
            echo $status_code;
        }

    }
}

Любая помощь, где я ошибаюсь?


person Aman Kumar    schedule 24.06.2016    source источник


Ответы (1)


Только модели Eloquent будут изящно сериализованы и десериализованы во время обработки задания (Источник)

Итак, я предполагаю, что в вашем случае вам нужно записать текущий код конструкции в метод handle()

class SiteScraper extends Job implements ShouldQueue
{
    use InteractsWithQueue, SerializesModels;

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

    public function handle()
    {

        $client = new Client();
        $crawler = $client->request('GET', 'example.com/login/');
        $form = $crawler->selectButton('Log In')->form();
        $crawler = $client->submit($form, array('email' => 'useremail', 'pass' => 'pass'));
        $crawler->filter('.flash-error')->each(function ($node) {
            print $node->text() . "\n";
        });

        $crawler = $client->request('GET', $url_to_traverse);
        $status_code = $client->getResponse()->getStatus();

        if($status_code == 200){
            $crawler->filter('.friendBrowserNameTitle > a')->each(function ($node) {
                $names = $node->text() . '<br>';
                $profileurl = $node->attr('href') . '<br>';
                echo "Name : " . $names . "  Profile Link : " . $profileurl;

            });
        }
        else{
            echo $status_code;
        }

    }
}
person Andrés Rivas    schedule 28.06.2016