Skip to content

Commit a2a3c00

Browse files
fixed naming and dependencies
1 parent d04ca4e commit a2a3c00

File tree

13 files changed

+87
-105
lines changed

13 files changed

+87
-105
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ after_script:
4141

4242
cache:
4343
directories:
44-
- "$HOME/.composer/cache"
44+
- "$HOME/.composer/cache"

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"symfony/expression-language": "^2.6 || ^3.0",
1818
"symfony/config": "^2.6 || ^3.0",
1919
"symfony/console": "^2.6 || ^3.0",
20+
"symfony/process": "^2.6 || ^3.0",
2021
"doctrine/orm": "^2.5"
2122
},
2223
"require-dev": {

src/Command/ExecuteCommand.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
*/
2525
class ExecuteCommand extends Command
2626
{
27-
const START_RESULT = '<?result';
28-
const END_RESULT = '?>';
29-
3027
/**
3128
* @var TaskHandlerFactoryInterface
3229
*/
@@ -76,12 +73,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
7673
} catch (\Exception $e) {
7774
$errOutput->writeln($e->__toString());
7875

76+
// Process exit-code: 0 = OK, >1 = FAIL
7977
return 1;
8078
}
8179

82-
$output->write(self::START_RESULT);
8380
$output->write($result);
84-
$output->write(self::END_RESULT);
81+
82+
return 0;
8583
}
8684

8785
/**

src/DependencyInjection/Configuration.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ public function getConfigTreeBuilder()
8484
->arrayNode('executor')
8585
->addDefaultsIfNotSet()
8686
->children()
87-
->enumNode('type')->values(['inline', 'process'])->defaultValue('inline')->end()
88-
->arrayNode('process')
87+
->enumNode('type')->values(['inside', 'separate'])->defaultValue('inside')->end()
88+
->arrayNode('separate')
8989
->addDefaultsIfNotSet()
9090
->children()
91-
->scalarNode('console')->defaultValue('%kernel.root_dir%/../bin/console')->end()
91+
->scalarNode('console_path')->defaultValue('%kernel.root_dir%/../bin/console')->end()
9292
->end()
9393
->end()
9494
->end()

src/DependencyInjection/TaskExtension.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Task\TaskBundle\DependencyInjection;
1313

14+
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1415
use Symfony\Component\Config\FileLocator;
1516
use Symfony\Component\Config\Loader\LoaderInterface;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -115,6 +116,12 @@ private function loadExecutorComponent(array $config, ContainerBuilder $containe
115116
foreach ($config[$config['type']] as $key => $value) {
116117
$container->setParameter('task.executor.' . $key, $value);
117118
}
119+
120+
if (!file_exists($container->getParameter('task.executor.console_path'))) {
121+
throw new InvalidConfigurationException(
122+
'Console file does not exists! Given in "task.executor.seperate.console".'
123+
);
124+
}
118125
}
119126

120127
/**

src/Executor/ProcessExecutor.php

Lines changed: 0 additions & 87 deletions
This file was deleted.

src/Executor/ProcessException.php renamed to src/Executor/SeparateProcessException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* Exception wrapper which transports the serialized exception from console to the runner.
1616
*/
17-
class ProcessException extends \Exception
17+
class SeparateProcessException extends \Exception
1818
{
1919
/**
2020
* @var string
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
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+
12+
namespace Task\TaskBundle\Executor;
13+
14+
use Symfony\Component\Process\ProcessBuilder;
15+
use Task\Execution\TaskExecutionInterface;
16+
use Task\Runner\ExecutorInterface;
17+
18+
/**
19+
* Uses a separate process to start the executions via console-command.
20+
*/
21+
class SeparateProcessExecutor implements ExecutorInterface
22+
{
23+
/**
24+
* @var string
25+
*/
26+
private $consolePath;
27+
28+
/**
29+
* @var string
30+
*/
31+
private $environment;
32+
33+
/**
34+
* @param string $consolePath
35+
* @param string $environment
36+
*/
37+
public function __construct($consolePath, $environment)
38+
{
39+
$this->consolePath = $consolePath;
40+
$this->environment = $environment;
41+
}
42+
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
public function execute(TaskExecutionInterface $execution)
47+
{
48+
$process = ProcessBuilder::create(
49+
[$this->consolePath, 'task:execute', $execution->getUuid(), '-e ' . $this->environment]
50+
)->getProcess();
51+
52+
$process->run();
53+
54+
if (!$process->isSuccessful()) {
55+
throw new SeparateProcessException($process->getErrorOutput());
56+
}
57+
58+
return $process->getOutput();
59+
}
60+
}

src/Resources/config/executor/inline.xml renamed to src/Resources/config/executor/inside.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
55
<services>
6-
<service id="task.executor.inline" class="Task\Runner\InlineExecutor">
6+
<service id="task.executor.inside" class="Task\Runner\InsideProcessExecutor">
77
<argument type="service" id="task.handler.factory"/>
88
</service>
99
</services>

src/Resources/config/executor/process.xml renamed to src/Resources/config/executor/separate.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
55
<services>
6-
<service id="task.executor.process" class="Task\TaskBundle\Executor\ProcessExecutor">
7-
<argument type="string">%task.executor.console%</argument>
6+
<service id="task.executor.separate" class="Task\TaskBundle\Executor\SeparateProcessExecutor">
7+
<argument type="string">%task.executor.console_path%</argument>
88
<argument type="string">%kernel.environment%%</argument>
99
</service>
1010
</services>

tests/Functional/BootstrapTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@ public function testBootstrap()
3737
case 'array':
3838
$this->assertInstanceOf(ArrayTaskRepository::class, $taskRepository);
3939
$this->assertInstanceOf(ArrayTaskExecutionRepository::class, $taskExecutionRepository);
40+
4041
break;
4142
case 'doctrine':
4243
$this->assertInstanceOf(TaskRepository::class, $taskRepository);
4344
$this->assertInstanceOf(TaskExecutionRepository::class, $taskExecutionRepository);
45+
4446
break;
4547
default:
4648
$this->fail('storage not supported');
49+
4750
break;
4851
}
4952
}

tests/app/config/config.doctrine.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ task:
77
workload: ['test']
88
cron_expression: '* * * * *'
99
executor:
10-
type: process
11-
process:
12-
console: '%kernel.root_dir%/console'
10+
type: separate
11+
separate:
12+
console_path: '%kernel.root_dir%/console'
1313

1414
doctrine:
1515
orm:
16-
auto_generate_proxy_classes: %kernel.debug%
16+
auto_generate_proxy_classes: '%kernel.debug%'
1717
auto_mapping: true
1818
dbal:
1919
driver: pdo_sqlite

tests/app/config/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ task:
55
locking:
66
storages:
77
file:
8-
directory: %kernel.cache_dir%/locks
8+
directory: '%kernel.cache_dir%/locks'

0 commit comments

Comments
 (0)