ClearBeanstalkdQueue   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getArguments() 0 6 1
A fire() 0 18 3
1
<?php
2
3
namespace App\Console\Commands;
4
5
use Queue;
6
use Illuminate\Console\Command;
7
use Symfony\Component\Console\Input\InputArgument;
8
9
class ClearBeanstalkdQueue extends Command
10
{
11
    /**
12
     * The console command name.
13
     *
14
     * @var string
15
     */
16
    protected $name = 'queue:beanstalkd:clear';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Clear a Beanstalkd queue, by deleting all pending jobs.';
24
25
    /**
26
     * Defines the arguments.
27
     *
28
     * @return array
29
     */
30
    public function getArguments()
31
    {
32
        return [
33
            ['queue', InputArgument::OPTIONAL, 'The name of the queue to clear.'],
34
        ];
35
    }
36
37
    /**
38
     * Execute the console command.
39
     */
40
    public function fire()
41
    {
42
        $queue = ($this->argument('queue')) ?
43
            $this->argument('queue') :
44
            config('queue.connections.beanstalkd.queue');
45
46
        $this->info(sprintf('Clearing queue: %s', $queue));
47
48
        $pheanstalk = Queue::getPheanstalk();
49
        $pheanstalk->useTube($queue);
50
        $pheanstalk->watch($queue);
51
52
        while ($job = $pheanstalk->reserve(0)) {
53
            $pheanstalk->delete($job);
54
        }
55
56
        $this->info('...cleared.');
57
    }
58
}
59