en cours : silexing taskmanager

This commit is contained in:
jygaulier
2012-07-19 17:37:51 +02:00
parent 70f64da8d1
commit be24152468
8 changed files with 263 additions and 0 deletions

View File

@@ -25,6 +25,9 @@ use Alchemy\Phrasea\Controller\Admin\Setup;
use Alchemy\Phrasea\Controller\Admin\Sphinx; use Alchemy\Phrasea\Controller\Admin\Sphinx;
use Alchemy\Phrasea\Controller\Admin\Subdefs; use Alchemy\Phrasea\Controller\Admin\Subdefs;
use Alchemy\Phrasea\Controller\Admin\Users; use Alchemy\Phrasea\Controller\Admin\Users;
use Alchemy\Phrasea\Controller\Admin\Tasks;
use Alchemy\Phrasea\Controller\Admin\Task;
use Alchemy\Phrasea\Controller\Admin\Scheduler;
use Alchemy\Phrasea\Controller\Utils\ConnectionTest; use Alchemy\Phrasea\Controller\Utils\ConnectionTest;
use Alchemy\Phrasea\Controller\Utils\PathFileTest; use Alchemy\Phrasea\Controller\Utils\PathFileTest;
@@ -40,6 +43,10 @@ return call_user_func(
$app->mount('/setup', new Setup()); $app->mount('/setup', new Setup());
$app->mount('/sphinx', new Sphinx()); $app->mount('/sphinx', new Sphinx());
$app->mount('/connected-users', new ConnectedUsers()); $app->mount('/connected-users', new ConnectedUsers());
$app->mount('/tasks', new Tasks());
$app->mount('/task', new Task());
$app->mount('/scheduler', new Scheduler());
$app->mount('/publications', new Publications()); $app->mount('/publications', new Publications());
$app->mount('/users', new Users()); $app->mount('/users', new Users());
$app->mount('/fields', new Fields()); $app->mount('/fields', new Fields());

View File

@@ -0,0 +1,50 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller\Admin;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Scheduler implements ControllerProviderInterface
{
public function connect(Application $app)
{
$appbox = \appbox::get_instance($app['Core']);
$session = $appbox->get_session();
$controllers = $app['controllers_factory'];
/*
* route /admin/tasks/
* tasks status in json
* or
* task manager page in html
*/
$controllers->get('/', function(Application $app, Request $request) use ($app) {
$request = $app['request'];
$task_manager = new \task_manager($appbox);
return "";
});
return $controllers;
}
}

View File

@@ -0,0 +1,85 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller\Admin;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
use Symfony\Component\Finder\Finder;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Task implements ControllerProviderInterface
{
public function connect(Application $app)
{
$appbox = \appbox::get_instance($app['Core']);
$controllers = $app['controllers_factory'];
/*
* route /admin/task/{id}/log
* show logs of a task
*/
$controllers->get('/{id}/log', function(Application $app, Request $request, $id) use ($appbox) {
$registry = $appbox->get_registry();
$logdir = \p4string::addEndSlash($registry->get('GV_RootPath') . 'logs');
$rname = '/task_' . $id . '((\.log)|(-.*\.log))$/';
$finder = new Finder();
$finder
->files()->name($rname)
->in($logdir)
// ->date('> now - 1 days')
->sortByModifiedTime();
$found = false;
foreach ($finder->getIterator() as $file) {
// printf("%s <br/>\n", ($file->getRealPath()));
if ($request->get('clr') == $file->getFilename()) {
file_put_contents($file->getRealPath(), '');
$found = true;
}
}
if ($found) {
return $app->redirect(sprintf("/admin/task/%s/log", urlencode($id)));
}
return $app->stream(
function() use ($finder, $id) {
foreach ($finder->getIterator() as $file) {
printf("<h4>%s\n", $file->getRealPath());
printf("&nbsp;<a href=\"/admin/task/%s/log?clr=%s\">%s</a>"
, $id
, urlencode($file->getFilename())
, _('Clear')
);
print("</h4>\n<pre>\n");
print(htmlentities(file_get_contents($file->getRealPath())));
print("</pre>\n");
ob_flush();
flush();
}
});
});
return $controllers;
}
}

View File

@@ -0,0 +1,79 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller\Admin;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Tasks implements ControllerProviderInterface
{
public function connect(Application $app)
{
$appbox = \appbox::get_instance($app['Core']);
$session = $appbox->get_session();
$controllers = $app['controllers_factory'];
/*
* route /admin/tasks/
* tasks status in json
* or
* task manager page in html
*/
$controllers->get('/', function(Application $app, Request $request) use ($appbox) {
$task_manager = new \task_manager($appbox);
if ($request->getContentType() == 'json') {
return $app->json($task_manager->toArray());
} else {
$template = 'admin/tasks/list.html.twig';
/* @var $twig \Twig_Environment */
$twig = $app['Core']->getTwig();
return $twig->render($template, array(
'task_manager' => $task_manager,
'scheduler_key' => \phrasea::scheduler_key()
));
}
});
/*
$controllers->post('/create/', function() use ($app, $appbox) {
$user = \User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
$request = $app['request'];
$feed = \Feed_Adapter::create($appbox, $user, $request->get('title'), $request->get('subtitle'));
if ($request->get('public') == '1')
$feed->set_public(true);
elseif ($request->get('base_id'))
$feed->set_collection(\collection::get_from_base_id($request->get('base_id')));
return $app->redirect('/admin/publications/list/');
});
*/
return $controllers;
}
}

View File

@@ -33,6 +33,38 @@ class task_manager
return $this; return $this;
} }
/**
* status of scheduler and tasks
* used do refresh the taskmanager page
*
* @return array
*/
public function toArray()
{
$ret = array(
'time' => date("H:i:s"),
'scheduler' => $this->getSchedulerState(),
'tasks' => array()
);
foreach ($this->getTasks(true) as $task) {
if ($task->getState() == self::STATE_TOSTOP && $task->getPID() === NULL) {
// fix
$task->setState(self::STATE_STOPPED);
}
$id = $task->getID();
$ret['tasks'][$id] = array(
'id' => $id,
'pid' => $task->getPID(),
'crashed' => $task->getCrashCounter(),
'completed' => $task->getCompletedPercentage(),
'status' => $task->getState()
);
}
return $ret;
}
public function getTasks($refresh = false, Logger $logger = null) public function getTasks($refresh = false, Logger $logger = null)
{ {
if ($this->tasks && ! $refresh) { if ($this->tasks && ! $refresh) {

View File

@@ -18,6 +18,7 @@
<script type="text/javascript" src="/include/minify/f=include/jslibs/jquery.validate.password.js"></script> <script type="text/javascript" src="/include/minify/f=include/jslibs/jquery.validate.password.js"></script>
<script type="text/javascript" src="/include/jslibs/jquery-ui-1.8.17/js/jquery-ui-1.8.17.custom.min.js"></script> <script type="text/javascript" src="/include/jslibs/jquery-ui-1.8.17/js/jquery-ui-1.8.17.custom.min.js"></script>
<script type="text/javascript" src="/include/vendor/javascript-load-image/load-image.min.js"></script> <script type="text/javascript" src="/include/vendor/javascript-load-image/load-image.min.js"></script>
<script type="text/javascript" src="/include/jslibs/jquery.contextmenu.js"></script>
<script type="text/javascript" src="/include/minify/g=admin"></script> <script type="text/javascript" src="/include/minify/g=admin"></script>
<script type="text/javascript"> <script type="text/javascript">

View File

@@ -69,6 +69,12 @@
<span>{% trans 'admin::utilisateurs: gestionnaire de taches' %}</span> <span>{% trans 'admin::utilisateurs: gestionnaire de taches' %}</span>
</a> </a>
</li> </li>
<li class="{% if feature == 'taskmanager' %}selected{% endif %}">
<a target="right" href="/admin/tasks/" class="ajax">
<img src="/skins/admin/TaskManager.png" />
{% trans 'admin::utilisateurs: gestionnaire de taches 2' %}
</a>
</li>
{% endif %} {% endif %}
<li class="open"> <li class="open">

View File

@@ -23,6 +23,9 @@
RewriteRule ^admin/publications/.*$ /admin/router.php [L] RewriteRule ^admin/publications/.*$ /admin/router.php [L]
RewriteRule ^admin/typeahead/.*$ /admin/router.php [L] RewriteRule ^admin/typeahead/.*$ /admin/router.php [L]
RewriteRule ^admin/subdefs/.*$ /admin/router.php [L] RewriteRule ^admin/subdefs/.*$ /admin/router.php [L]
RewriteRule ^admin/tasks/.*$ /admin/router.php [L]
RewriteRule ^admin/task/.*$ /admin/router.php [L]
RewriteRule ^admin/scheduler/.*$ /admin/router.php [L]
RewriteRule ^prod/records/edit/.*$ /prod/router.php [L] RewriteRule ^prod/records/edit/.*$ /prod/router.php [L]
RewriteRule ^prod/records/movecollection/.*$ /prod/router.php [L] RewriteRule ^prod/records/movecollection/.*$ /prod/router.php [L]