Open necenzurat opened 6 years ago
@necenzurat Can you give me an example? Queuing a command?
nope, when you dispatch a job, the job fires up a dusk instance, just like the command but with queues. Could that be posible?
I think so. I will do a test locally tho.
@necenzurat Sure is possible. You have two options:
You can call your artisan command from your job using Artisan::call($commandName)
;
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');
});
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');
});
}
}
Found it, but:
@necenzurat Hummmmmm. I need to take a deep look into this.
The first option is not good?
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. 🐌
@necenzurat I understand. We should definitely find a way for making things easy while using Laravel Jobs.
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
Would be good to have: Provide an easy way of using this package outside artisan commands.
Hey,
I'm taking a look at it, and maybe something like this helps:
Illuminate\Console\Command
:...
use Illuminate\Console\Command;
class bot extends Command implements ShouldQueue {
...
}
Then you will have a problem of $this->output
being null
on your LaravelConsoleTaskServiceProvider
. For a temporary fix, you can add something like this in the beginning of the task macro function
, line 43, by adding:
...
Command::macro(
'task',
function (string $title, $task = null, $loadingText = 'loading...') {
$this->output = optional($this->output); // Add this line
$this->output->write("$title: <comment>{$loadingText}</comment>");
...
@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.
Any chance for this to be implemented with queues, that would be awesome.