-
Notifications
You must be signed in to change notification settings - Fork 20
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
1 parent
153718d
commit 3f7d080
Showing
10 changed files
with
272 additions
and
7 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 |
---|---|---|
@@ -1,6 +1,4 @@ | ||
/vendor | ||
composer.phar | ||
vendor/ | ||
|
||
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file | ||
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file | ||
# composer.lock | ||
composer.lock | ||
.DS_Store |
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,13 @@ | ||
language: php | ||
|
||
php: | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
- hhvm | ||
|
||
before_script: | ||
- travis_retry composer self-update | ||
- travis_retry composer install --prefer-source --no-interaction --dev | ||
|
||
script: 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 |
---|---|---|
@@ -1,2 +1,41 @@ | ||
# laravel-queue-clear | ||
Command for wiping your queues clear | ||
# Laravel Queue Clear Command | ||
|
||
[![Build Status](https://travis-ci.org/morrislaptop/laravel-queue-clear.png?branch=master)](https://travis-ci.org/morrislaptop/laravel-queue-clear) | ||
|
||
Often, when you're issuing `php artisan db:refresh --seed`, you will have queue jobs left over that won't match with | ||
your database records anymore. | ||
|
||
This package simplifies the process of clearing your queues drastically. | ||
|
||
## Installation | ||
|
||
Begin by installing this package through Composer. | ||
|
||
```js | ||
{ | ||
"require": { | ||
"morrislaptop/laravel-queue-clear": "~1.0" | ||
} | ||
} | ||
``` | ||
|
||
And then include the service provider within config/app.php. | ||
|
||
```php | ||
'providers' => [ | ||
'Morrislaptop\LaravelQueueClear\LaravelQueueClearServiceProvider' | ||
]; | ||
``` | ||
|
||
## Usage | ||
|
||
```bash | ||
php artisan queue:clear [connection] [queue] | ||
``` | ||
|
||
Where: | ||
|
||
* `[connection]` is the name of a connection in your config/queue.php | ||
* `[queue]` is the name of the queue / pipe you want to clear | ||
|
||
If you omit either argument, it will use your default driver and the default queue / pipe for that driver. |
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,20 @@ | ||
{ | ||
"name": "morrislaptop/laravel-queue-clear", | ||
"description": "Command for wiping your queues clear", | ||
"authors": [ | ||
{ | ||
"name": "Craig Morris", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.4.0", | ||
"illuminate/support": "5.0.*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Morrislaptop\\LaravelQueueClear\\": "src/" | ||
} | ||
}, | ||
"minimum-stability": "stable" | ||
} |
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,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
> | ||
<testsuites> | ||
<testsuite name="Package Test Suite"> | ||
<directory suffix=".php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</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,38 @@ | ||
<?php namespace Morrislaptop\LaravelQueueClear; | ||
|
||
use Illuminate\Queue\QueueManager; | ||
use Illuminate\Contracts\Queue\Factory as FactoryContract; | ||
use Morrislaptop\LaravelQueueClear\Contracts\Clearer as ClearerContract; | ||
|
||
class Clearer implements ClearerContract | ||
{ | ||
/** | ||
* @var QueueManager | ||
*/ | ||
protected $manager; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
function __construct(FactoryContract $manager) | ||
{ | ||
$this->manager = $manager; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function clear($connection, $queue) | ||
{ | ||
$count = 0; | ||
$connection = $this->manager->connection($connection); | ||
|
||
while ($job = $connection->pop($queue)) { | ||
$job->delete(); | ||
$count++; | ||
} | ||
|
||
return $count; | ||
} | ||
|
||
} |
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,80 @@ | ||
<?php namespace Morrislaptop\LaravelQueueClear\Console; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Contracts\Config\Repository; | ||
use Illuminate\Queue\QueueManager; | ||
use Morrislaptop\LaravelQueueClear\Contracts\Clearer as ClearerContract; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
|
||
class QueueClearCommand extends Command { | ||
|
||
|
||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'queue:clear'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Clear all queued jobs, by deleting all pending jobs.'; | ||
|
||
/** | ||
* @var | ||
*/ | ||
protected $config; | ||
|
||
/** | ||
* @var QueueManager | ||
*/ | ||
protected $queue; | ||
|
||
/** | ||
* @var Clearer | ||
*/ | ||
protected $clearer; | ||
|
||
/** | ||
* @param Repository $config | ||
* @param Clearer $clearer | ||
*/ | ||
function __construct(Repository $config, ClearerContract $clearer) | ||
{ | ||
$this->config = $config; | ||
$this->clearer = $clearer; | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Defines the arguments. | ||
* | ||
* @return array | ||
*/ | ||
public function getArguments() | ||
{ | ||
return array( | ||
array('connection', InputArgument::OPTIONAL, 'The connection of the queue driver to clear.'), | ||
array('queue', InputArgument::OPTIONAL, 'The name of the queue / pipe to clear.'), | ||
); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function fire() | ||
{ | ||
$connection = $this->argument('connection') ?: $this->config->get('queue.default'); | ||
$queue = $this->argument('queue') ?: $this->config->get('queue.connections.' . $connection . '.queue'); | ||
|
||
$this->info(sprintf('Clearing queue "%s" on "%s"', $queue, $connection)); | ||
$cleared = $this->clearer->clear($connection, $queue); | ||
$this->info(sprintf('Cleared %d jobs', $cleared)); | ||
} | ||
|
||
} |
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,21 @@ | ||
<?php namespace Morrislaptop\LaravelQueueClear\Contracts; | ||
|
||
use Illuminate\Contracts\Queue\Factory as FactoryContract; | ||
|
||
interface Clearer | ||
{ | ||
/** | ||
* @param FactoryContract $manager | ||
*/ | ||
function __construct(FactoryContract $manager); | ||
|
||
/** | ||
* Deletes all the jobs in the queue for connection. Returns | ||
* how many jobs were deleted | ||
* | ||
* @param $connection | ||
* @param $queue | ||
* @return int | ||
*/ | ||
public function clear($connection, $queue); | ||
} |
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,38 @@ | ||
<?php namespace Morrislaptop\LaravelQueueClear; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class LaravelQueueClearServiceProvider extends ServiceProvider { | ||
|
||
/** | ||
* Indicates if loading of the provider is deferred. | ||
* | ||
* @var bool | ||
*/ | ||
protected $defer = false; | ||
|
||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->app->bind( | ||
'Morrislaptop\LaravelQueueClear\Contracts\Clearer', | ||
'Morrislaptop\LaravelQueueClear\Clearer' | ||
); | ||
$this->commands('Morrislaptop\LaravelQueueClear\Console\QueueClearCommand'); | ||
} | ||
|
||
/** | ||
* Get the services provided by the provider. | ||
* | ||
* @return array | ||
*/ | ||
public function provides() | ||
{ | ||
return []; | ||
} | ||
|
||
} |
Empty file.