ListTasksCommand::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
1
<?php
2
3
/**
4
 * This file is part of tenside/core-bundle.
5
 *
6
 * (c) Christian Schiffler <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * This project is provided in good faith and hope to be usable by anyone.
12
 *
13
 * @package    tenside/core-bundle
14
 * @author     Christian Schiffler <[email protected]>
15
 * @copyright  2015 Christian Schiffler <[email protected]>
16
 * @license    https://github.com/tenside/core-bundle/blob/master/LICENSE MIT
17
 * @link       https://github.com/tenside/core-bundle
18
 * @filesource
19
 */
20
21
namespace Tenside\CoreBundle\Command;
22
23
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
24
use Symfony\Component\Console\Input\InputInterface;
25
use Symfony\Component\Console\Output\OutputInterface;
26
27
/**
28
 * This class executes a queued task in detached mode.
29
 */
30
class ListTasksCommand extends ContainerAwareCommand
31
{
32
    /**
33
     * {@inheritdoc}
34
     */
35
    protected function configure()
36
    {
37
        $this
38
            ->setName('tenside:listtasks')
39
            ->setDescription('List the queued tasks')
40
            ->setHelp('You most likely do not want to use this from CLI - use the web UI');
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     *
46
     * @throws \InvalidArgumentException When an invalid task id has been passed.
47
     */
48
    protected function execute(InputInterface $input, OutputInterface $output)
49
    {
50
        $container = $this->getContainer();
51
        $taskList  = $container->get('tenside.tasks');
52
53
        foreach ($taskList->getIds() as $taskId) {
54
            $task = $taskList->getTask($taskId);
55
            $output->writeln(sprintf('<info>%s</info> %s (state: %s)', $taskId, $task->getType(), $task->getStatus()));
56
        }
57
    }
58
}
59