Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions src/Command/DebugTasksCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Task\TaskBundle\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Task\Storage\StorageInterface;

/**
* Run pending tasks.
*
* @author @wachterjohannes <johannes.wachter@massiveart.com>
*/
class DebugTasksCommand extends Command
{
/**
* @var StorageInterface
*/
private $storage;

public function __construct($name, StorageInterface $storage)
{
parent::__construct($name);

$this->storage = $storage;
}

/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setDescription('Debug tasks')
->addOption('limit', 'l', InputOption::VALUE_REQUIRED, '', null)
->addOption('key', 'k', InputOption::VALUE_REQUIRED, '', null);
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$key = $input->getOption('key');
$limit = $input->getOption('limit');

if (null !== $key) {
$tasks = $this->storage->findByKey($key, $limit);
} else {
$tasks = $this->storage->findAll($limit);
}

$table = new Table($output);
$table->setHeaders(array('uuid', 'key', 'task-name', 'execution-date', 'completed', 'start', 'duration'));

foreach ($tasks as $task) {
$start = null;
$duration = null;
if ($task->getLastExecution()) {
$start = $task->getLastExecution()->getFinishedAtAsDateTime()->format(\DateTime::RFC3339);
$duration = $task->getLastExecution()->getExecutionDuration();
}

$table->addRow(
[
$task->getUuid(),
$task->getKey(),
$task->getTaskName(),
$task->getExecutionDate()->format(\DateTime::RFC3339),
$task->isCompleted(),
$start,
$duration,
]
);
}

$table->render();
}
}
7 changes: 7 additions & 0 deletions src/Resources/config/command.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,12 @@

<tag name="console.command"/>
</service>

<service id="task.command.debug_tasks" class="Task\TaskBundle\Command\DebugTasksCommand">
<argument type="string">debug:tasks</argument>
<argument type="service" id="task.storage"/>

<tag name="console.command"/>
</service>
</services>
</container>
19 changes: 16 additions & 3 deletions src/Storage/DoctrineStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,26 @@ function (TaskEntity $entity) {
/**
* {@inheritdoc}
*/
public function findAll()
public function findAll($limit = null)
{
return array_map(
function (TaskEntity $entity) {
return $entity->getTask();
},
$this->taskRepository->findAll()
$this->taskRepository->findBy([], null, $limit)
);
}

/**
* {@inheritdoc}
*/
public function findByKey($key, $limit = null)
{
return array_map(
function (TaskEntity $entity) {
return $entity->getTask();
},
$this->taskRepository->findBy(['key' => $key], null, $limit)
);
}

Expand All @@ -103,7 +116,7 @@ public function clear()

private function setTask(TaskEntity $entity, TaskInterface $task)
{
$entity->setTask($task);
$entity->setTask(clone $task);
$entity->setUuid($task->getUuid());
$entity->setKey($task->getKey());
$entity->setCompleted($task->isCompleted());
Expand Down