PHRAS-198 #fix add possibility to disable taskmanager per instance

This commit is contained in:
Nicolas Le Goff
2014-07-25 18:40:00 +02:00
parent b4141f92a7
commit 76cb4fad28
8 changed files with 56 additions and 7 deletions

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Controller\Admin; namespace Alchemy\Phrasea\Controller\Admin;
use Alchemy\Phrasea\Exception\RuntimeException;
use Alchemy\Phrasea\Exception\XMLParseErrorException; use Alchemy\Phrasea\Exception\XMLParseErrorException;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
@@ -71,6 +72,11 @@ class TaskManager implements ControllerProviderInterface
* route /admin/scheduler/stop * route /admin/scheduler/stop
*/ */
$controllers->get('/scheduler/stop', function (Application $app, Request $request) use ($app) { $controllers->get('/scheduler/stop', function (Application $app, Request $request) use ($app) {
if ($app['phraseanet.registry"].get("GV_disable_task_manager']) {
throw new RuntimeException('The use of the task manager is disabled on this instance.');
}
try { try {
$app['task-manager']->setSchedulerState(\task_manager::STATE_TOSTOP); $app['task-manager']->setSchedulerState(\task_manager::STATE_TOSTOP);
@@ -341,6 +347,10 @@ class TaskManager implements ControllerProviderInterface
public function startScheduler(Application $app, Request $request) public function startScheduler(Application $app, Request $request)
{ {
if ($app['phraseanet.registry"].get("GV_disable_task_manager']) {
throw new RuntimeException('The use of the task manager is disabled on this instance.');
}
$app['session']->save(); $app['session']->save();
set_time_limit(0); set_time_limit(0);
ignore_user_abort(true); ignore_user_abort(true);

View File

@@ -107,14 +107,18 @@ class API_V1_adapter extends API_V1_Abstract
{ {
$result = new \API_V1_result($app, $app['request'], $this); $result = new \API_V1_result($app, $app['request'], $this);
$taskManager = $app['task-manager']; if ($app['phraseanet.registry"].get("GV_disable_task_manager']) {
$ret = $taskManager->getSchedulerState(); $ret = array('state' => 'disabled');
} else {
$taskManager = $app['task-manager'];
$ret = $taskManager->getSchedulerState();
}
$ret['state'] = $ret['status']; $ret['state'] = $ret['status'];
unset($ret['qdelay'], $ret['status']); unset($ret['qdelay'], $ret['status']);
if (null !== $ret['updated_on']) { if (isset($ret['updated_on']) && null !== $ret['updated_on']) {
$ret['updated_on'] = $ret['updated_on']->format(DATE_ATOM); $ret['updated_on'] = $ret['updated_on']->format(DATE_ATOM);
} }

View File

@@ -17,6 +17,7 @@
*/ */
use Alchemy\Phrasea\Command\Command; use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Exception\RuntimeException;
use Monolog\Handler; use Monolog\Handler;
use Monolog\Logger; use Monolog\Logger;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
@@ -36,6 +37,9 @@ class module_console_schedulerStart extends Command
protected function doExecute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
if ($this->container['phraseanet.registry"].get("GV_disable_task_manager']) {
throw new RuntimeException('The use of the task manager is disabled on this instance.');
}
$logger = $this->container['task-manager.logger']; $logger = $this->container['task-manager.logger'];
$streamHandler = new Handler\StreamHandler('php://stdout', $input->getOption('verbose') ? Logger::DEBUG : Logger::WARNING); $streamHandler = new Handler\StreamHandler('php://stdout', $input->getOption('verbose') ? Logger::DEBUG : Logger::WARNING);

View File

@@ -16,6 +16,7 @@
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
use Alchemy\Phrasea\Command\Command; use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@@ -55,6 +56,10 @@ class module_console_schedulerState extends Command
return self::EXITCODE_SETUP_ERROR; return self::EXITCODE_SETUP_ERROR;
} }
if ($this->container['phraseanet.registry"].get("GV_disable_task_manager']) {
throw new RuntimeException('The use of the task manager is disabled on this instance.');
}
$task_manager = $this->container['task-manager']; $task_manager = $this->container['task-manager'];
$exitCode = 0; $exitCode = 0;

View File

@@ -16,6 +16,7 @@
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
use Alchemy\Phrasea\Command\Command; use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@@ -33,6 +34,10 @@ class module_console_schedulerStop extends Command
protected function doExecute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
if ($this->container['phraseanet.registry"].get("GV_disable_task_manager']) {
throw new RuntimeException('The use of the task manager is disabled on this instance.');
}
try { try {
$task_manager = $this->container['task-manager']; $task_manager = $this->container['task-manager'];
$task_manager->setSchedulerState(task_manager::STATE_TOSTOP); $task_manager->setSchedulerState(task_manager::STATE_TOSTOP);

View File

@@ -73,6 +73,10 @@ class module_console_taskrun extends Command
return self::EXITCODE_SETUP_ERROR; return self::EXITCODE_SETUP_ERROR;
} }
if ($this->container['phraseanet.registry"].get("GV_disable_task_manager']) {
throw new RuntimeException('The use of the task manager is disabled on this instance.');
}
$task_id = (int) $input->getArgument('task_id'); $task_id = (int) $input->getArgument('task_id');
if ($task_id <= 0 || strlen($task_id) !== strlen($input->getArgument('task_id'))) { if ($task_id <= 0 || strlen($task_id) !== strlen($input->getArgument('task_id'))) {
throw new \RuntimeException('Argument must be an Id.'); throw new \RuntimeException('Argument must be an Id.');

View File

@@ -341,6 +341,19 @@ return call_user_func_array(function(Application $app) {
'required' => true 'required' => true
) )
) )
), array(
'section' => _('Task manager'),
'rolled' => true,
'vars' => array(
array(
'type' => \registry::TYPE_BOOLEAN,
'name' => 'GV_disable_task_manager',
'comment' => _('Disable task manager'),
'help' => '',
'default' => false,
'required' => true
)
)
), array( ), array(
'section' => _('Search engine'), 'section' => _('Search engine'),
'rolled' => true, 'rolled' => true,

View File

@@ -33,8 +33,10 @@
<span class="caret"></span> <span class="caret"></span>
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li class="schedMenuItem" id="schedulerStart"><a href="#">start</a></li> {% if not app["phraseanet.registry"].get("GV_disable_task_manager") %}
<li class="schedMenuItem" id="schedulerStop"><a href="#">stop</a></li> <li class="schedMenuItem" id="schedulerStart"><a href="#">start</a></li>
<li class="schedMenuItem" id="schedulerStop"><a href="#">stop</a></li>
{% endif %}
<li class="schedMenuItem" id="schedulerLog"><a href="#">log</a></li> <li class="schedMenuItem" id="schedulerLog"><a href="#">log</a></li>
</ul> </ul>
</div> </div>
@@ -55,8 +57,10 @@
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li class="taskMenuItem" id="taskEdit_{{ task.getID() }}"><a href="#">{% trans 'Edit' %}</a></li> <li class="taskMenuItem" id="taskEdit_{{ task.getID() }}"><a href="#">{% trans 'Edit' %}</a></li>
<li class="taskMenuItem" id="taskStart_{{ task.getID() }}"><a href="#">{% trans 'Start' %}</a></li> {% if not app["phraseanet.registry"].get("GV_disable_task_manager") %}
<li class="taskMenuItem" id="taskStop_{{ task.getID() }}"><a href="#">{% trans 'Stop' %}</a></li> <li class="taskMenuItem" id="taskStart_{{ task.getID() }}"><a href="#">{% trans 'Start' %}</a></li>
<li class="taskMenuItem" id="taskStop_{{ task.getID() }}"><a href="#">{% trans 'Stop' %}</a></li>
{% endif %}
<li class="taskMenuItem" id="taskDelete_{{ task.getID() }}"><a href="#">{% trans 'Delete' %}</a></li> <li class="taskMenuItem" id="taskDelete_{{ task.getID() }}"><a href="#">{% trans 'Delete' %}</a></li>
<li class="taskMenuItem" id="taskLog_{{ task.getID() }}"><a href="#">{% trans 'Logs' %}</a></li> <li class="taskMenuItem" id="taskLog_{{ task.getID() }}"><a href="#">{% trans 'Logs' %}</a></li>
</ul> </ul>