Skip to content

Commit 0653638

Browse files
improved architecture of bundle (#15)
* refactored bundle to fit new structure of php-task * adapted to fit new architecture * finished prototype * fixed refactored * fixed config and console format * fixed exception and intervall * removed unused command removed unused constant * fixed code-style * fixed test-cases and removed old ones * auto-generated changelog * changed dependency
1 parent 2c1a943 commit 0653638

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+762
-951
lines changed

CHANGELOG.md

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,43 @@
1-
# CHANGELOG
1+
# Change Log
22

3-
* 0.2.1 (2016-03-30)
4-
* HOTFIX #18 Fixed command issues (sorting and shortcut)
3+
## [0.2.1](https://github.com/php-task/TaskBundle/tree/0.2.1) (2016-03-30)
4+
[Full Changelog](https://github.com/php-task/TaskBundle/compare/0.2.0...0.2.1)
55

6-
* 0.2.0 (2016-02-27)
7-
* ENHANCEMENT #-- Added debug tasks command and extended storage
8-
* ENHANCEMENT #-- Moved command name to service definition
9-
* FEATURE #13 Added options to command schedule task for cron tasks
6+
**Closed issues:**
107

11-
* 0.1.0 (2016-01-31)
8+
- Debug tasks should be sorted DESC for execution date [\#17](https://github.com/php-task/TaskBundle/issues/17)
9+
- Schedule task command option e \(end-date\) bug [\#16](https://github.com/php-task/TaskBundle/issues/16)
10+
11+
**Merged pull requests:**
12+
13+
- Fixed command issues [\#18](https://github.com/php-task/TaskBundle/pull/18) ([wachterjohannes](https://github.com/wachterjohannes))
14+
15+
## [0.2.0](https://github.com/php-task/TaskBundle/tree/0.2.0) (2016-02-27)
16+
[Full Changelog](https://github.com/php-task/TaskBundle/compare/0.1.0...0.2.0)
17+
18+
**Fixed bugs:**
19+
20+
- If handle return object output failed [\#7](https://github.com/php-task/TaskBundle/issues/7)
21+
- Commands should only output something on error or in verbosity mode [\#6](https://github.com/php-task/TaskBundle/issues/6)
22+
23+
**Closed issues:**
24+
25+
- Move command names to service definition [\#4](https://github.com/php-task/TaskBundle/issues/4)
26+
27+
**Merged pull requests:**
28+
29+
- Added command and extended storage [\#14](https://github.com/php-task/TaskBundle/pull/14) ([wachterjohannes](https://github.com/wachterjohannes))
30+
- Added options to command schedule task for cron tasks [\#13](https://github.com/php-task/TaskBundle/pull/13) ([wachterjohannes](https://github.com/wachterjohannes))
31+
32+
## [0.1.0](https://github.com/php-task/TaskBundle/tree/0.1.0) (2016-01-31)
33+
**Fixed bugs:**
34+
35+
- Next Execution date should be in the future [\#12](https://github.com/php-task/TaskBundle/issues/12)
36+
37+
**Merged pull requests:**
38+
39+
- Add tagged service task compilerpass [\#2](https://github.com/php-task/TaskBundle/pull/2) ([wachterjohannes](https://github.com/wachterjohannes))
40+
41+
42+
43+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"require": {
1313
"php": "~5.5 || ~7.0",
14-
"php-task/php-task": "0.2.*",
14+
"php-task/php-task": "dev-master",
1515
"symfony/http-kernel": "^2.6",
1616
"symfony/dependency-injection": "^2.6",
1717
"symfony/config": "^2.6",

src/Command/DebugTasksCommand.php

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,38 @@
11
<?php
22

3+
/*
4+
* This file is part of php-task library.
5+
*
6+
* (c) php-task
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
312
namespace Task\TaskBundle\Command;
413

514
use Symfony\Component\Console\Command\Command;
615
use Symfony\Component\Console\Helper\Table;
716
use Symfony\Component\Console\Input\InputInterface;
817
use Symfony\Component\Console\Input\InputOption;
918
use Symfony\Component\Console\Output\OutputInterface;
10-
use Task\Storage\StorageInterface;
19+
use Task\Execution\TaskExecutionRepositoryInterface;
1120

1221
/**
1322
* Run pending tasks.
14-
*
15-
* @author @wachterjohannes <johannes.wachter@massiveart.com>
1623
*/
1724
class DebugTasksCommand extends Command
1825
{
1926
/**
20-
* @var StorageInterface
27+
* @var TaskExecutionRepositoryInterface
2128
*/
2229
private $storage;
2330

24-
public function __construct($name, StorageInterface $storage)
31+
/**
32+
* @param string $name
33+
* @param TaskExecutionRepositoryInterface $storage
34+
*/
35+
public function __construct($name, TaskExecutionRepositoryInterface $storage)
2536
{
2637
parent::__construct($name);
2738

@@ -34,44 +45,30 @@ public function __construct($name, StorageInterface $storage)
3445
protected function configure()
3546
{
3647
$this->setDescription('Debug tasks')
37-
->addOption('limit', 'l', InputOption::VALUE_REQUIRED, '', null)
38-
->addOption('key', 'k', InputOption::VALUE_REQUIRED, '', null);
48+
->addOption('limit', 'l', InputOption::VALUE_REQUIRED, '', null);
3949
}
4050

4151
/**
4252
* {@inheritdoc}
4353
*/
4454
protected function execute(InputInterface $input, OutputInterface $output)
4555
{
46-
$key = $input->getOption('key');
4756
$limit = $input->getOption('limit');
4857

49-
if (null !== $key) {
50-
$tasks = $this->storage->findByKey($key, $limit, 'DESC');
51-
} else {
52-
$tasks = $this->storage->findAll($limit, 'DESC');
53-
}
58+
$executions = $this->storage->findAll($limit);
5459

5560
$table = new Table($output);
56-
$table->setHeaders(['uuid', 'key', 'task-name', 'execution-date', 'completed', 'start', 'duration']);
57-
58-
foreach ($tasks as $task) {
59-
$start = null;
60-
$duration = null;
61-
if ($task->getLastExecution()) {
62-
$start = $task->getLastExecution()->getFinishedAtAsDateTime()->format(\DateTime::RFC3339);
63-
$duration = $task->getLastExecution()->getExecutionDuration();
64-
}
61+
$table->setHeaders(['uuid', 'status', 'handler', 'schedule time', 'end time', 'duration']);
6562

63+
foreach ($executions as $execution) {
6664
$table->addRow(
6765
[
68-
$task->getUuid(),
69-
$task->getKey(),
70-
$task->getTaskName(),
71-
$task->getExecutionDate()->format(\DateTime::RFC3339),
72-
$task->isCompleted(),
73-
$start,
74-
$duration,
66+
$execution->getUuid(),
67+
$execution->getStatus(),
68+
$execution->getHandlerClass(),
69+
$execution->getScheduleTime()->format(\DateTime::RFC3339),
70+
!$execution->getEndTime() ? '' : $execution->getEndTime()->format(\DateTime::RFC3339),
71+
(round($execution->getDuration(), 6) * 1000000) . 'ms',
7572
]
7673
);
7774
}

src/Command/RunCommand.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,47 @@
11
<?php
22

3+
/*
4+
* This file is part of php-task library.
5+
*
6+
* (c) php-task
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
312
namespace Task\TaskBundle\Command;
413

514
use Symfony\Component\Console\Command\Command;
615
use Symfony\Component\Console\Input\InputInterface;
716
use Symfony\Component\Console\Output\OutputInterface;
8-
use Task\SchedulerInterface;
17+
use Task\Runner\TaskRunnerInterface;
18+
use Task\Scheduler\SchedulerInterface;
919

1020
/**
1121
* Run pending tasks.
12-
*
13-
* @author @wachterjohannes <johannes.wachter@massiveart.com>
1422
*/
1523
class RunCommand extends Command
1624
{
25+
/**
26+
* @var TaskRunnerInterface
27+
*/
28+
private $runner;
29+
1730
/**
1831
* @var SchedulerInterface
1932
*/
2033
private $scheduler;
2134

22-
public function __construct($name, SchedulerInterface $scheduler)
35+
/**
36+
* @param string $name
37+
* @param TaskRunnerInterface $runner
38+
* @param SchedulerInterface $scheduler
39+
*/
40+
public function __construct($name, TaskRunnerInterface $runner, SchedulerInterface $scheduler)
2341
{
2442
parent::__construct($name);
2543

44+
$this->runner = $runner;
2645
$this->scheduler = $scheduler;
2746
}
2847

@@ -39,6 +58,7 @@ protected function configure()
3958
*/
4059
protected function execute(InputInterface $input, OutputInterface $output)
4160
{
42-
$this->scheduler->run();
61+
$this->runner->runTasks();
62+
$this->scheduler->scheduleTasks();
4363
}
4464
}

src/Command/RunHandlerCommand.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
11
<?php
22

3+
/*
4+
* This file is part of php-task library.
5+
*
6+
* (c) php-task
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
312
namespace Task\TaskBundle\Command;
413

514
use Symfony\Component\Console\Command\Command;
615
use Symfony\Component\Console\Input\InputArgument;
716
use Symfony\Component\Console\Input\InputInterface;
817
use Symfony\Component\Console\Output\OutputInterface;
9-
use Task\Handler\RegistryInterface;
18+
use Task\Handler\TaskHandlerFactoryInterface;
1019

1120
/**
1221
* Run pending tasks.
13-
*
14-
* @author Alexander Schranz <alexander.schranz@massiveart.com>
1522
*/
1623
class RunHandlerCommand extends Command
1724
{
1825
/**
19-
* @var RegistryInterface
26+
* @var TaskHandlerFactoryInterface
2027
*/
21-
private $registry;
28+
private $handlerFactory;
2229

23-
public function __construct($name, RegistryInterface $registry)
30+
/**
31+
* @param string $name
32+
* @param TaskHandlerFactoryInterface $handlerFactory
33+
*/
34+
public function __construct($name, TaskHandlerFactoryInterface $handlerFactory)
2435
{
2536
parent::__construct($name);
2637

27-
$this->registry = $registry;
38+
$this->handlerFactory = $handlerFactory;
2839
}
2940

3041
/**
@@ -33,7 +44,7 @@ public function __construct($name, RegistryInterface $registry)
3344
protected function configure()
3445
{
3546
$this->setDescription('Run pending tasks')
36-
->addArgument('handler', InputArgument::REQUIRED)
47+
->addArgument('handlerClass', InputArgument::REQUIRED)
3748
->addArgument('workload', InputArgument::OPTIONAL);
3849
}
3950

@@ -42,14 +53,14 @@ protected function configure()
4253
*/
4354
protected function execute(InputInterface $input, OutputInterface $output)
4455
{
45-
$handler = $input->getArgument('handler');
56+
$handlerClass = $input->getArgument('handlerClass');
4657
$workload = $input->getArgument('workload');
4758

4859
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
49-
$output->writeln(sprintf('Run command "%s" with workload "%s"', $handler, $workload));
60+
$output->writeln(sprintf('Run command "%s" with workload "%s"', $handlerClass, $workload));
5061
}
5162

52-
$result = $this->registry->run($handler, $workload);
63+
$result = $this->handlerFactory->create($handlerClass)->handle($workload);
5364

5465
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
5566
$output->writeln(sprintf('Result: %s', json_encode($result)));

src/Command/ScheduleTaskCommand.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
<?php
22

3+
/*
4+
* This file is part of php-task library.
5+
*
6+
* (c) php-task
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
312
namespace Task\TaskBundle\Command;
413

514
use Symfony\Component\Console\Command\Command;
615
use Symfony\Component\Console\Input\InputArgument;
716
use Symfony\Component\Console\Input\InputInterface;
817
use Symfony\Component\Console\Input\InputOption;
918
use Symfony\Component\Console\Output\OutputInterface;
10-
use Task\SchedulerInterface;
19+
use Task\Scheduler\SchedulerInterface;
1120

1221
/**
1322
* Schedule task.
14-
*
15-
* @author @wachterjohannes <johannes.wachter@massiveart.com>
1623
*/
1724
class ScheduleTaskCommand extends Command
1825
{
@@ -21,11 +28,15 @@ class ScheduleTaskCommand extends Command
2128
*/
2229
private $scheduler;
2330

24-
public function __construct($name, SchedulerInterface $scheduler)
31+
/**
32+
* @param string $name
33+
* @param SchedulerInterface $runner
34+
*/
35+
public function __construct($name, SchedulerInterface $runner)
2536
{
2637
parent::__construct($name);
2738

28-
$this->scheduler = $scheduler;
39+
$this->scheduler = $runner;
2940
}
3041

3142
/**
@@ -38,8 +49,7 @@ protected function configure()
3849
->addArgument('handler', InputArgument::REQUIRED)
3950
->addArgument('workload', InputArgument::OPTIONAL)
4051
->addOption('cron-expression', 'c', InputOption::VALUE_REQUIRED)
41-
->addOption('end-date', null, InputOption::VALUE_REQUIRED)
42-
->addOption('key', 'k', InputOption::VALUE_REQUIRED);
52+
->addOption('end-date', null, InputOption::VALUE_REQUIRED);
4353
}
4454

4555
/**
@@ -51,7 +61,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
5161
$workload = $input->getArgument('workload');
5262
$cronExpression = $input->getOption('cron-expression');
5363
$endDateString = $input->getOption('end-date');
54-
$key = $input->getOption('key');
5564

5665
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
5766
$output->writeln(sprintf('Schedule task "%s" with workload "%s"', $handler, $workload));
@@ -68,10 +77,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
6877
$taskBuilder->cron($cronExpression, new \DateTime(), $endDate);
6978
}
7079

71-
if ($key !== null) {
72-
$taskBuilder->setKey($key);
73-
}
74-
75-
$taskBuilder->schedule();
80+
$this->scheduler->addTask($taskBuilder->getTask());
7681
}
7782
}

src/DependencyInjection/Configuration.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of php-task library.
5+
*
6+
* (c) php-task
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
312
namespace Task\TaskBundle\DependencyInjection;
413

514
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
@@ -19,7 +28,7 @@ public function getConfigTreeBuilder()
1928

2029
$treeBuilder->root('task')
2130
->children()
22-
->enumNode('storage')->values(['array', 'doctrine'])->defaultValue('array')->end()
31+
->enumNode('storage')->values(['array', 'doctrine'])->defaultValue('doctrine')->end()
2332
->arrayNode('run')
2433
->addDefaultsIfNotSet()
2534
->children()

0 commit comments

Comments
 (0)