nunomaduro / laravel-console-dusk

Laravel Console Dusk allows the usage of Laravel Dusk in Laravel/Laravel Zero artisan commands.
MIT License
151 stars 22 forks source link

[1.1] Usage outside of Artisan commands #4

Open necenzurat opened 6 years ago

necenzurat commented 6 years ago

Any chance for this to be implemented with queues, that would be awesome.

nunomaduro commented 6 years ago

@necenzurat Can you give me an example? Queuing a command?

necenzurat commented 6 years ago

nope, when you dispatch a job, the job fires up a dusk instance, just like the command but with queues. Could that be posible?

nunomaduro commented 6 years ago

I think so. I will do a test locally tho.

nunomaduro commented 6 years ago

@necenzurat Sure is possible. You have two options:

  1. You can call your artisan command from your job using Artisan::call($commandName);

  2. You can place the code as the following example in your job:

resolve(ManagerContract::class)->browse($this, function ($browser) {
    $browser->visit('http://laravel-zero.com')
        ->assertSee('Collision');
});
necenzurat commented 6 years ago

I need to import the ManagerContract, where is that?

<?php

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;

class Q 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()
    {
        resolve(\ManagerContract::class)->browse($this, function ($browser) {
            $browser->visit('https://necesrequests.herokuapp.com/1eyyti51');
        });
    }
}
necenzurat commented 6 years ago

Found it, but: image

nunomaduro commented 6 years ago

@necenzurat Hummmmmm. I need to take a deep look into this.

The first option is not good?

necenzurat commented 6 years ago

Nope, i would like to have the possibility to queue some jobs then the workers would start the chrome browsers in parallel for scraping/other purposes. The command method is slow if you wan't to check many links at the same time. 🐌

nunomaduro commented 6 years ago

@necenzurat I understand. We should definitely find a way for making things easy while using Laravel Jobs.

necenzurat commented 6 years ago

I mean, it would be super cool, but no worries, no one is in a hurry. Let me know if i can help. Ps: would be nice in a separate package like the awesome laravel-console-dusk.

On Tue, 19 Jun 2018 at 23:21, Nuno Maduro notifications@github.com wrote:

@necenzurat https://github.com/necenzurat I understand. We should definitely find a way for making things easy while using Laravel Jobs.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/nunomaduro/laravel-console-dusk/issues/4#issuecomment-398532288, or mute the thread https://github.com/notifications/unsubscribe-auth/AAI4KfQQ7PKhjvbzyu_B-kXc48y2nqWKks5t-V1CgaJpZM4UfTou .

--

-- Costin Moise aka necenzurat

Tel: +4 0726.459.188 | Github https://github.com/necenzurat | Linkedin http://www.linkedin.com/in/necenzurat

nunomaduro commented 6 years ago

Would be good to have: Provide an easy way of using this package outside artisan commands.

manelgavalda commented 4 years ago

Hey,

I'm taking a look at it, and maybe something like this helps:

...
use Illuminate\Console\Command;

class bot extends Command implements ShouldQueue {
    ...
}

@nunomaduro, @owenvoke it would be nice if you can take a look at this, so we can find a solution, as it is the same issue as #17.