Skip to content

Commit

Permalink
+ Copy files over
Browse files Browse the repository at this point in the history
  • Loading branch information
dusterio committed Apr 11, 2017
1 parent 2286d7b commit 4be854a
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 982 deletions.
104 changes: 104 additions & 0 deletions src/Integrations/LaravelServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

namespace Dusterio\LaravelVerbose\Integrations;

use Illuminate\Support\ServiceProvider;
use Dusterio\LaravelVerbose\Queue\Worker;
use Dusterio\LaravelVerbose\Queue\WorkCommand;
use Dusterio\LaravelVerbose\Queue\Listener;
use Dusterio\LaravelVerbose\Queue\ListenCommand;

/**
* Class CustomQueueServiceProvider
* @package App\Providers
*/
class LaravelServiceProvider extends ServiceProvider
{
/**
* @return void
*/
public function register()
{
$this->registerWorker();
$this->registerListener();
}

/**
* Register the queue worker.
*
* @return void
*/
protected function registerWorker()
{
$this->registerWorkCommand();

$this->app->singleton('queue.worker', function ($app) {
return new Worker(
$app['queue'], $app['events'],
$app['Illuminate\Contracts\Debug\ExceptionHandler']
);
});
}

/**
* Register the queue worker console command.
*
* @return void
*/
protected function registerWorkCommand()
{
$this->app->singleton('command.queue.work', function ($app) {
return new WorkCommand($app['queue.worker']);
});

$this->commands('command.queue.work');
}

/**
* Register the queue listener.
*
* @return void
*/
protected function registerListener()
{
$this->registerListenCommand();

$this->app->singleton('queue.listener', function ($app) {
return new Listener($app->basePath());
});
}

/**
* Register the queue listener console command.
*
* @return void
*/
protected function registerListenCommand()
{
$this->app->singleton('command.queue.listen', function ($app) {
return new ListenCommand($app['queue.listener']);
});

$this->commands('command.queue.listen');
}

/**
* @return void
*/
public function boot()
{
}

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return [
'queue.worker', 'queue.listener',
'command.queue.work', 'command.queue.listen'
];
}
}
93 changes: 2 additions & 91 deletions src/Queue/ListenCommand.php
Original file line number Diff line number Diff line change
@@ -1,89 +1,13 @@
<?php

namespace Illuminate\Queue\Console;
namespace Dusterio\LaravelVerbose\Queue;

use Illuminate\Queue\Listener;
use Illuminate\Console\Command;
use Illuminate\Queue\ListenerOptions;

class ListenCommand extends Command
class ListenCommand extends \Illuminate\Queue\Console\ListenCommand
{
/**
* The console command name.
*
* @var string
*/
protected $signature = 'queue:listen
{connection? : The name of connection}
{--delay=0 : Amount of time to delay failed jobs}
{--force : Force the worker to run even in maintenance mode}
{--memory=128 : The memory limit in megabytes}
{--queue= : The queue to listen on}
{--sleep=3 : Number of seconds to sleep when no job is available}
{--timeout=60 : The number of seconds a child process can run}
{--tries=0 : Number of times to attempt a job before logging it failed}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Listen to a given queue';

/**
* The queue listener instance.
*
* @var \Illuminate\Queue\Listener
*/
protected $listener;

/**
* Create a new queue listen command.
*
* @param \Illuminate\Queue\Listener $listener
* @return void
*/
public function __construct(Listener $listener)
{
parent::__construct();

$this->setOutputHandler($this->listener = $listener);
}

/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
// We need to get the right queue for the connection which is set in the queue
// configuration file for the application. We will pull it based on the set
// connection being run for the queue operation currently being executed.
$queue = $this->getQueue(
$connection = $this->input->getArgument('connection')
);

$this->listener->listen(
$connection, $queue, $this->gatherOptions()
);
}

/**
* Get the name of the queue connection to listen on.
*
* @param string $connection
* @return string
*/
protected function getQueue($connection)
{
$connection = $connection ?: $this->laravel['config']['queue.default'];

return $this->input->getOption('queue') ?: $this->laravel['config']->get(
"queue.connections.{$connection}.queue", 'default'
);
}

/**
* Get the listener options for the command.
*
Expand All @@ -99,19 +23,6 @@ protected function gatherOptions()
);
}

/**
* Set the options on the queue listener.
*
* @param \Illuminate\Queue\Listener $listener
* @return void
*/
protected function setOutputHandler(Listener $listener)
{
$listener->setOutputHandler(function ($type, $line) {
$this->output->write($line);
});
}

/**
* Resolve a Symfony verbosity level back to its CLI parameter.
*
Expand Down
Loading

0 comments on commit 4be854a

Please sign in to comment.