-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,311 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
composer.lock | ||
vendor/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "dusterio/laravel-verbose", | ||
"type": "library", | ||
"description": "Package that adds verbosity to Laravel/Lumen built-in console commands", | ||
"keywords": ["php","laravel","verbosity","verbose","console"], | ||
"homepage": "https://github.com/dusterio/laravel-verbose", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Denis Mysenko", | ||
"email": "denis@mysenko.com", | ||
"homepage": "https://www.mysenko.com" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.5.0", | ||
"laravel/framework": "5.4.*" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "3.7.*", | ||
"codeclimate/php-test-reporter": "dev-master" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Dusterio\\LaravelVerbose\\": "src/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
bootstrap="tests/bootstrap.php" | ||
> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory suffix=".php">tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?php | ||
|
||
namespace Illuminate\Queue\Console; | ||
|
||
use Illuminate\Queue\Listener; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Queue\ListenerOptions; | ||
|
||
class ListenCommand extends Command | ||
{ | ||
/** | ||
* 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. | ||
* | ||
* @return \Illuminate\Queue\ListenerOptions | ||
*/ | ||
protected function gatherOptions() | ||
{ | ||
return new ListenerOptions( | ||
$this->option('env'), $this->option('delay'), | ||
$this->option('memory'), $this->option('timeout'), | ||
$this->option('sleep'), $this->option('tries'), | ||
$this->option('force'), $this->resolveVerbosityParameter() | ||
); | ||
} | ||
|
||
/** | ||
* 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. | ||
* | ||
* @return string|null | ||
*/ | ||
private function resolveVerbosityParameter() | ||
{ | ||
$currentVerbosity = $this->output->getVerbosity(); | ||
$parameter = array_search($currentVerbosity, $this->verbosityMap); | ||
|
||
return $parameter ?: null; | ||
} | ||
} |
Oops, something went wrong.