Merge pull request #1322 from bburnichon/feature/task-manager-start

task manager start
This commit is contained in:
Benoît Burnichon
2015-03-26 09:52:10 +01:00
16 changed files with 558 additions and 1202 deletions

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\Command\Task;
use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Exception\RuntimeException;
use Alchemy\Phrasea\TaskManager\TaskManagerStatus;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\Command\Task;
use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Exception\RuntimeException;
use Alchemy\Phrasea\TaskManager\TaskManagerStatus;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

View File

@@ -11,11 +11,10 @@
namespace Alchemy\Phrasea\Command\Task;
use Alchemy\TaskManager\TaskManager;
use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Exception\RuntimeException;
use Alchemy\TaskManager\Event\TaskManagerSubscriber\LockFileSubscriber;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

View File

@@ -12,10 +12,11 @@
namespace Alchemy\Phrasea\Command\Task;
use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Exception\RuntimeException;
use Alchemy\Phrasea\Model\Entities\Task;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class SchedulerState extends Command
{

View File

@@ -12,13 +12,16 @@
namespace Alchemy\Phrasea\Controller\Admin;
use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Exception\RuntimeException;
use Alchemy\Phrasea\Form\TaskForm;
use Alchemy\Phrasea\Model\Entities\Task;
use Alchemy\Phrasea\Exception\RuntimeException;
use Alchemy\Phrasea\Exception\XMLParseErrorException;
use Alchemy\Phrasea\TaskManager\LiveInformation;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Process\Process;
class TaskManager implements ControllerProviderInterface
{
@@ -126,6 +129,25 @@ class TaskManager implements ControllerProviderInterface
{
$app['task-manager.status']->start();
$cmdLine = sprintf(
'%s %s %s',
$app['conf']->get(['main', 'binaries', 'php_binary']),
realpath(__DIR__ . '/../../../../../bin/console'),
'task-manager:scheduler:run'
);
/** @var EventDispatcherInterface $dispatcher */
$dispatcher = $app['dispatcher'];
$dispatcher->addListener(KernelEvents::TERMINATE, function () use ($cmdLine) {
$process = new Process($cmdLine);
$process->setTimeout(0);
$process->disableOutput();
set_time_limit(0);
ignore_user_abort(true);
$process->run();
}, -1000);
return $app->redirectPath('admin_tasks_list');
}
@@ -133,6 +155,17 @@ class TaskManager implements ControllerProviderInterface
{
$app['task-manager.status']->stop();
/** @var LiveInformation $info */
$info = $app['task-manager.live-information'];
$data = $info->getManager();
if (null !== $pid = $data['process-id']) {
if (substr(php_uname(), 0, 7) == "Windows"){
exec(sprintf('TaskKill /PID %d', $pid));
} else {
exec(sprintf('kill %d', $pid));
}
}
return $app->redirectPath('admin_tasks_list');
}

View File

@@ -14,6 +14,9 @@ namespace Alchemy\Phrasea\Core\Provider;
use Alchemy\Phrasea\Core\Configuration\SessionHandlerFactory;
use Silex\Application;
use Silex\ServiceProviderInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;
class SessionHandlerServiceProvider implements ServiceProviderInterface
{
@@ -27,10 +30,24 @@ class SessionHandlerServiceProvider implements ServiceProviderInterface
});
}
public function onKernelResponse(FilterResponseEvent $event)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
return;
}
$session = $event->getRequest()->getSession();
if ($session && $session->isStarted()) {
$session->save();
}
}
/**
* {@inheritdoc}
*/
public function boot(Application $app)
{
// Priority should be lower than test session mock listener
$app['dispatcher']->addListener(KernelEvents::RESPONSE, array($this, 'onKernelResponse'), -129);
}
}

View File

@@ -25,7 +25,7 @@ class NginxMode extends AbstractServerMode implements ModeInterface
$xAccelMapping = [];
foreach ($this->mapping as $entry) {
$xAccelMapping[] = sprintf('%s=%s', $entry['mount-point'], $entry['directory']);
$xAccelMapping[] = sprintf('%s=%s', $entry['directory'], $entry['mount-point']);
}
if (count($xAccelMapping) > 0 ) {