This commit is contained in:
Romain Neutron
2013-01-21 23:19:50 +01:00
parent c144041980
commit b4dfcc2f2f
8 changed files with 52 additions and 201 deletions

View File

@@ -11,20 +11,12 @@
namespace Alchemy\Phrasea\Core\Service\TaskManager;
use Alchemy\Phrasea\Core;
use Alchemy\Phrasea\Core\Service;
use Alchemy\Phrasea\Core\Service\ServiceAbstract;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Bridge\Monolog\Logger;
use Monolog\Handler\SyslogHandler;
use Monolog\Handler\NativeMailerHandler;
use Alchemy\Phrasea\Exception\RuntimeException;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class TaskManager extends ServiceAbstract
{
/** `
@@ -48,33 +40,18 @@ class TaskManager extends ServiceAbstract
$options = $this->getOptions();
$registry = $this->app['phraseanet.registry'];
// send log to syslog ?
if (null !== ($syslogLevel = constant($options['syslog_level']))) {
$handler = new SyslogHandler(
"Phraseanet-Task", // string added to each message
"user", // facility (type of program logging)
$syslogLevel, // level
true // bubble
);
if (null !== $syslogLevel = constant($options['syslog_level'])) {
$handler = new SyslogHandler("Phraseanet-Task", "user", $syslogLevel);
$logger->pushHandler($handler);
}
// send log by mail ?
if (null !== ($maillogLevel = constant($options['maillog_level']))) {
if (($adminMail = $registry->get('GV_adminMail')) == '') {
throw(new RuntimeException(sprintf(
"Admininstrator mail must be set to get log by mail."))
);
if (null !== $maillogLevel = constant($options['maillog_level'])) {
if ('' === $adminMail = trim($registry->get('GV_adminMail'))) {
throw new RuntimeException("Admininstrator mail must be set to get log by mail.");
}
$senderMail = $registry->get('GV_defaultmailsenderaddr');
$handler = new NativeMailerHandler(
$adminMail,
"Phraseanet-Task",
$senderMail,
$maillogLevel, // level
true
);
$handler = new NativeMailerHandler($adminMail, "Phraseanet-Task", $senderMail, $maillogLevel);
$logger->pushHandler($handler);
}
@@ -82,7 +59,7 @@ class TaskManager extends ServiceAbstract
}
/**
* Set and return a new \task_manager instance
* Set and return a new task_manager instance
*
* @return \task_manager
*/

View File

@@ -10,13 +10,12 @@
*/
use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Monolog\Handler;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\RotatingFileHandler;
@@ -38,22 +37,23 @@ class module_console_taskrun extends Command
$this->task = NULL;
$this->shedulerPID = NULL;
$this->addArgument('task_id', InputArgument::REQUIRED, 'The task_id to run');
$this->addOption(
'runner'
, 'r'
, InputOption::VALUE_REQUIRED
, 'The name of the runner (manual, scheduler...)'
, task_abstract::RUNNER_MANUAL
);
$this->addOption(
'ttyloglevel'
, 't'
, InputOption::VALUE_REQUIRED
, 'threshold : (DEBUG|INFO|WARNING|ERROR|CRITICAL|ALERT)'
, ''
);
$this->setDescription('Run task');
$this
->addArgument('task_id', InputArgument::REQUIRED, 'The task_id to run')
->addOption(
'runner',
'r',
InputOption::VALUE_REQUIRED,
'The name of the runner (manual, scheduler...)',
task_abstract::RUNNER_MANUAL
)
->addOption(
'ttyloglevel',
't',
InputOption::VALUE_REQUIRED,
'threshold : (DEBUG|INFO|WARNING|ERROR|CRITICAL|ALERT)',
''
)
->setDescription('Run task');
return $this;
}
@@ -97,42 +97,31 @@ class module_console_taskrun extends Command
if ($input->getOption('verbose')) {
$handler = new StreamHandler(fopen('php://stdout', 'a'));
$this->container['monolog']->pushHandler($handler);
$this->container['monolog']->pushHandler(new StreamHandler('php://stdout'));
}
$logfile = __DIR__ . '/../../../../logs/task_' . $task_id . '.log';
$handler = new RotatingFileHandler($logfile, 10);
$this->container['monolog']->pushHandler($handler);
$this->container['monolog']->pushHandler(new RotatingFileHandler($logfile, 10));
$this->task = $task_manager->getTask($task_id, $this->container['monolog']);
$lib2v = array(
'DEBUG' => task_abstract::LOG_DEBUG,
'INFO' => task_abstract::LOG_INFO,
'WARNING' => task_abstract::LOG_WARNING,
'ERROR' => task_abstract::LOG_ERROR,
'CRITICAL' => task_abstract::LOG_CRITICAL,
'ALERT' => task_abstract::LOG_ALERT
'DEBUG' => \task_abstract::LOG_DEBUG,
'INFO' => \task_abstract::LOG_INFO,
'WARNING' => \task_abstract::LOG_WARNING,
'ERROR' => \task_abstract::LOG_ERROR,
'CRITICAL' => \task_abstract::LOG_CRITICAL,
'ALERT' => \task_abstract::LOG_ALERT
);
$tmpTask = $task_manager->getTask($task_id, null);
$taskname = $tmpTask->getName();
unset($tmpTask);
// log to tty ?
if(($ttyloglevel = strtoupper($input->getOption('ttyloglevel'))) != '') {
if (($ttyloglevel = strtoupper($input->getOption('ttyloglevel'))) != '') {
if (!array_key_exists($ttyloglevel, $lib2v)) {
throw(new Alchemy\Phrasea\Exception\RuntimeException(sprintf(
"Bad value '%s' for option loglevel\nuse DEBUG|INFO|WARNING|ERROR|CRITICAL|ALERT", $ttyloglevel))
);
throw new RuntimeException("Bad value '%s' for option loglevel\nuse DEBUG|INFO|WARNING|ERROR|CRITICAL|ALERT", $ttyloglevel);
}
$handler = new Handler\StreamHandler(
"php://stdout",
$lib2v[$ttyloglevel],
true
);
$handler = new StreamHandler("php://stdout", $lib2v[$ttyloglevel]);
$logger->pushHandler($handler);
}
@@ -148,7 +137,6 @@ class module_console_taskrun extends Command
if (function_exists('pcntl_signal')) {
pcntl_signal(SIGTERM, array($this, 'sig_handler'));
pcntl_signal(SIGINT, array($this, 'sig_handler'));
// pcntl_signal(SIGKILL, array($this, 'sig_handler'));
}
try {

View File

@@ -638,7 +638,7 @@ abstract class task_abstract
// if something went wrong, report
if ($exception) {
throw($exception);
throw $exception;
}
}

View File

@@ -88,11 +88,10 @@ abstract class task_databoxAbstract extends task_abstract
// get the records to process
$databox = $this->dependencyContainer['phraseanet.appbox']->get_databox((int) $row['sbas_id']);
} catch (Exception $e) {
$this->log(sprintf(
'can\'t connect to sbas(%s) because "%s"'
, $row['sbas_id']
, $e->getMessage())
, self::LOG_WARNING
$this->log(sprintf('can\'t connect to sbas(%s) because "%s"',
$row['sbas_id'],
$e->getMessage()),
self::LOG_WARNING
);
continue;
}
@@ -100,10 +99,9 @@ abstract class task_databoxAbstract extends task_abstract
try {
$this->loadSettings(simplexml_load_string($row['settings']));
} catch (Exception $e) {
$this->log(sprintf(
'can\'t get get settings of task because "%s"'
, $e->getMessage())
, self::LOG_WARNING
$this->log(sprintf('can\'t get get settings of task because "%s"',
$e->getMessage()),
self::LOG_WARNING
);
continue;
}

View File

@@ -44,10 +44,7 @@ class task_period_RecordMover extends task_appboxAbstract
{
$request = http_request::getInstance();
$parm2 = $request->get_parms(
'period'
, 'logsql'
);
$parm2 = $request->get_parms('period', 'logsql');
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
@@ -164,8 +161,6 @@ class task_period_RecordMover extends task_appboxAbstract
{
period.value = xml2.find("period").text();
logsql.checked = Number(xml2.find("logsql").text()) > 0;
// maxrecs.value = xml.find("maxrecs").text();
// maxmegs.value = xml.find("maxmegs").text();
}
var data = {};

View File

@@ -2065,73 +2065,6 @@ class task_period_archive extends task_abstract
return $ret;
}
/**
* Map a bag of metadatas indexed by **FieldNames** to an array ready for
* \record_adapter metadatas submission
*
* @param \databox_descriptionStructure $metadatasStructure The databox structure related
* @param MetadataBag $metadatas The metadata bag
* @return array
*/
protected function bagToArray(\databox_descriptionStructure $metadatasStructure, MetadataBag $metadatas)
{
$metas = array();
$unicode = new \unicode();
foreach ($metadatasStructure as $databox_field) {
if ($metadatas->containsKey($databox_field->get_tag()->getTagname())) {
if ($databox_field->is_multi()) {
$values = $metadatas->get($databox_field->get_tag()->getTagname())->getValue()->asArray();
$tmp = array();
foreach ($values as $value) {
foreach (\caption_field::get_multi_values($value, $databox_field->get_separator()) as $v) {
$tmp[] = $v;
}
}
$values = array_unique($tmp);
foreach ($values as $value) {
$value = $unicode->substituteCtrlCharacters($value, ' ');
$value = $unicode->toUTF8($value);
if ($databox_field->get_type() == 'date') {
$value = $unicode->parseDate($value);
}
$metas[] = array(
'meta_struct_id' => $databox_field->get_id(),
'value' => $value,
'meta_id' => null
);
}
} else {
$value = $metadatas->get($databox_field->get_tag()->getTagname())->getValue()->asString();
$value = $unicode->substituteCtrlCharacters($value, ' ');
$value = $unicode->toUTF8($value);
if ($databox_field->get_type() == 'date') {
$value = $unicode->parseDate($value);
}
$metas[] = array(
'meta_struct_id' => $databox_field->get_id(),
'value' => $metadatas->get($databox_field->get_tag()->getTagname())->getValue()->asString(),
'meta_id' => null
);
}
}
}
unset($unicode);
return $metas;
}
protected function readXMLForDatabox(\databox_descriptionStructure $metadatasStructure, $pathfile)
{
if (false === $this->dependencyContainer['filesystem']->exists($pathfile)) {
@@ -2207,7 +2140,7 @@ class CListFolder
{
$this->list = array();
if ($hdir = opendir($path)) {
while (false !== ($file = readdir($hdir))) {
while (false !== $file = readdir($hdir)) {
$this->list[] = $file;
}
closedir($hdir);

View File

@@ -45,23 +45,13 @@ class task_period_ftp extends task_appboxAbstract
{
$request = http_request::getInstance();
$parm2 = $request->get_parms(
'proxy'
, 'proxyport'
, 'period'
, 'syslog'
);
$parm2 = $request->get_parms('proxy', 'proxyport', 'period', 'syslog');
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
if ((@$dom->loadXML($oldxml)) != FALSE) {
$xmlchanged = false;
foreach (array(
'str:proxy'
, 'str:proxyport'
, 'str:period'
, 'pop:syslog'
) as $pname) {
foreach (array('str:proxy', 'str:proxyport', 'str:period', 'pop:syslog') as $pname) {
$ptype = substr($pname, 0, 3);
$pname = substr($pname, 4);
$pvalue = $parm2[$pname];
@@ -354,17 +344,6 @@ class task_period_ftp extends task_appboxAbstract
$this->logger->addDebug($line);
if (($ses_id = phrasea_create_session($usr_id)) == null) {
$this->logger->addDebug("Unable to create session");
return;
}
if (!($ph_session = phrasea_open_session($ses_id, $usr_id))) {
$this->logger->addDebug("Unable to open session");
phrasea_close_session($ses_id);
return;
}
try {
$ssl = ($ftp_export['ssl'] == '1');
$ftp_client = $this->dependencyContainer['phraseanet.ftp.client']($ftp_server, 21, 300, $ssl, $this->proxy, $this->proxyport);
@@ -558,7 +537,6 @@ class task_period_ftp extends task_appboxAbstract
unset($ftp_client);
}
$this->finalize($appbox, $id);
// phrasea_close_session($ses_id);
}
protected function postProcessOneContent(appbox $appbox, Array $row)

View File

@@ -8,14 +8,6 @@
* file that was distributed with this source code.
*/
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Monolog\Logger;
class task_period_subdef extends task_databoxAbstract
{
const MINMEGS = 20;
@@ -70,24 +62,14 @@ class task_period_subdef extends task_databoxAbstract
{
$request = http_request::getInstance();
$parm2 = $request->get_parms(
'period'
, 'flush'
, 'maxrecs'
, 'maxmegs'
);
$parm2 = $request->get_parms('period', 'flush', 'maxrecs', 'maxmegs');
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
if (@$dom->loadXML($oldxml)) {
$xmlchanged = false;
foreach (array(
'str:period'
, 'str:flush'
, 'str:maxrecs'
, 'str:maxmegs'
) as $pname) {
foreach (array('str:period', 'str:flush', 'str:maxrecs', 'str:maxmegs') as $pname) {
$ptype = substr($pname, 0, 3);
$pname = substr($pname, 4);
$pvalue = $parm2[$pname];
@@ -327,7 +309,7 @@ class task_period_subdef extends task_databoxAbstract
$stmt = $connbas->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
} catch (Exception $e) {
} catch (\Exception $e) {
$this->log($e->getMessage(), self::LOG_CRITICAL);
}
}