Skip to content

Commit

Permalink
Added possibility to define tasks in extension section in config file
Browse files Browse the repository at this point in the history
  • Loading branch information
stekycz committed Sep 25, 2014
1 parent 78b74b3 commit 422d1c7
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Cronner/DI/CronnerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Nette\Configurator;
use Nette\DI\Compiler;
use Nette\DI\CompilerExtension;
use Nette\DI\Statement;
use Nette\Utils\Json;
use Nette\Utils\Validators;

if (!class_exists('Nette\DI\CompilerExtension')) {
Expand Down Expand Up @@ -33,6 +35,7 @@ class CronnerExtension extends CompilerExtension
'timestampStorage' => NULL,
'maxExecutionTime' => NULL,
'criticalSectionTempDir' => "%tempDir%/critical-section",
'tasks' => array(),
);


Expand Down Expand Up @@ -81,6 +84,22 @@ public function loadConfiguration()
array_key_exists('debugMode', $config) ? !$config['debugMode'] : TRUE,
));

Validators::assert($config['tasks'], 'array');
foreach ($config['tasks'] as $task) {
$def = $container->addDefinition($this->prefix('task.' . md5(Json::encode($task))));
list($def->factory) = Compiler::filterArguments(array(
is_string($task) ? new Statement($task) : $task
));

if (class_exists($def->factory->entity)) {
$def->class = $def->factory->entity;
}

$def->setAutowired(FALSE);
$def->setInject(FALSE);
$def->addTag(self::TASKS_TAG);
}

foreach (array_keys($container->findByTag(self::TASKS_TAG)) as $serviceName) {
$runner->addSetup('addTasks', array('@' . $serviceName));
}
Expand Down

0 comments on commit 422d1c7

Please sign in to comment.