Remove platform detection

This commit is contained in:
Romain Neutron
2012-05-24 14:52:20 +02:00
parent a3c87fdf10
commit 2b7c196d13
13 changed files with 106 additions and 185 deletions

View File

@@ -9,21 +9,20 @@
* file that was distributed with this source code.
*/
use Monolog\Logger;
use Symfony\Component\Console\Output\OutputInterface;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class task_Scheduler
{
const TASKDELAYTOQUIT = 60;
// how to schedule tasks (choose in 'run' method)
const METHOD_FORK = 'METHOD_FORK';
const METHOD_PROC_OPEN = 'METHOD_PROC_OPEN';
const ERR_ALREADY_RUNNING = 114; // aka EALREADY (Operation already in progress)
/**
@@ -32,8 +31,11 @@ class task_Scheduler
*/
private $logger;
private $method;
private $input;
protected $output;
public function __construct(Logger $logger)
{
$this->logger = $logger;
}
protected function log($message)
{
@@ -47,30 +49,25 @@ class task_Scheduler
return appbox::get_instance(\bootstrap::getCore())->get_connection();
}
/*
/**
* @throws Exception if scheduler is already running
* @todo doc all possible exception
*/
public function run(\Monolog\Logger $logger)
public function run()
{
$this->logger = $logger;
$appbox = appbox::get_instance(\bootstrap::getCore());
$registry = $appbox->get_registry();
$nullfile = '';
$system = system_server::get_platform();
switch ($system) {
case "WINDOWS":
$nullfile = 'NUL';
$this->method = self::METHOD_PROC_OPEN;
break;
default:
case "DARWIN":
case "LINUX":
$nullfile = '/dev/null';
$this->method = self::METHOD_FORK;
break;
$this->method = self::METHOD_PROC_OPEN;
$nullfile = '/dev/null';
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$nullfile = 'NUL';
}
if (function_exists('pcntl_fork')) {
$this->method = self::METHOD_FORK;
}
$lockdir = $registry->get('GV_RootPath') . 'tmp/locks/';
@@ -320,10 +317,11 @@ class task_Scheduler
if ($this->method == self::METHOD_PROC_OPEN) {
if ( ! $taskPoll[$tkey]["process"]) {
$tmpFile = tempnam(sys_get_temp_dir(), 'task');
$descriptors[1] = array('file', $tmpFile, 'a+');
$descriptors[2] = array('file', $tmpFile, 'a+');
$nullfile = defined('PHP_WINDOWS_VERSION_BUILD') ? 'NUL' : '/dev/null';
$descriptors[1] = array('file', $nullfile, 'a+');
$descriptors[2] = array('file', $nullfile, 'a+');
$taskPoll[$tkey]["process"] = proc_open(
$taskPoll[$tkey]["cmd"] . ' ' . implode(' ', $taskPoll[$tkey]["args"])

View File

@@ -283,26 +283,15 @@ abstract class task_abstract
abstract public function help();
public function __construct($taskid)
public function __construct($taskid, Logger $logger)
{
$this->logger = $logger;
$this->taskid = $taskid;
phrasea::use_i18n(Session_Handler::get_locale());
$this->system = system_server::get_platform();
$this->launched_by = array_key_exists("REQUEST_URI", $_SERVER) ? self::LAUCHED_BY_BROWSER : self::LAUCHED_BY_COMMANDLINE;
if ($this->system != "DARWIN" && $this->system != "WINDOWS" && $this->system != "LINUX") {
if ($this->launched_by == self::LAUCHED_BY_COMMANDLINE) {
// printf("Desole, ce programme ne fonctionne pas sous '" . $this->system . "'.\n");
flush();
}
exit(-1);
} else {
if ($this->launched_by == self::LAUCHED_BY_COMMANDLINE) {
flush();
}
}
try {
$conn = connection::getPDOConnection();
@@ -496,10 +485,8 @@ abstract class task_abstract
return $lockFD;
}
final public function run($runner, $logger)
final public function run($runner)
{
$this->logger = $logger;
$lockFD = $this->lockTask();
$this->setRunner($runner);
@@ -680,7 +667,9 @@ abstract class task_abstract
public function log($message)
{
$this->logger->addInfo($message);
if ($this->logger) {
$this->logger->addInfo($message);
}
return $this;
}

View File

@@ -16,10 +16,6 @@
*/
abstract class task_databoxAbstract extends task_abstract
{
// abstract public function help();
//
// abstract public function getName();
protected $mono_sbas_id;
abstract protected function retrieveSbasContent(databox $databox);

View File

@@ -37,6 +37,8 @@ class task_manager
return $this->tasks;
}
$core = \bootstrap::getCore();
$sql = "SELECT task2.* FROM task2 ORDER BY task_id ASC";
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute();
@@ -45,9 +47,6 @@ class task_manager
$tasks = array();
$appbox = \appbox::get_instance(\bootstrap::getCore());
$lockdir = $appbox->get_registry()->get('GV_RootPath') . 'tmp/locks/';
foreach ($rs as $row) {
$row['pid'] = NULL;
@@ -56,21 +55,7 @@ class task_manager
continue;
}
try {
// if( ($lock = fopen( $lockdir . 'task.'.$row['task_id'].'.lock', 'a+')) )
// {
// if (flock($lock, LOCK_SH | LOCK_NB) === FALSE)
// {
// // already locked : running !
// $row['pid'] = fgets($lock, 512);
// }
// else
// {
// // can lock : not running
// flock($lock, LOCK_UN);
// }
// fclose($lock);
// }
$tasks[$row['task_id']] = new $classname($row['task_id']);
$tasks[$row['task_id']] = new $classname($row['task_id'], $core['monolog']);
} catch (Exception $e) {
}

View File

@@ -202,7 +202,7 @@ class task_period_cindexer extends task_abstract
public function printInterfaceJS()
{
$appname = 'phraseanet_indexer';
if ($this->system == 'WINDOWS') {
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$appname .= '.exe';
}
?>
@@ -277,17 +277,17 @@ class task_period_cindexer extends task_abstract
public function printInterfaceHTML()
{
$appname = 'phraseanet_indexer';
if ($this->system == 'WINDOWS') {
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$appname .= '.exe';
}
ob_start();
?>
<form name="graphicForm" onsubmit="return(false);" method="post">
<br/>
<?php echo _('task::cindexer:executable') ?>&nbsp;:&nbsp;
<?php echo _('task::cindexer:executable') ?>&nbsp;:&nbsp;
<input type="text" name="binpath" style="width:300px;" onchange="chgxmltxt(this, 'binpath');" value="">&nbsp;/&nbsp;<?php echo $appname ?>
<br/>
<?php echo _('task::cindexer:host') ?>&nbsp;:&nbsp;<input type="text" name="host" style="width:100px;" onchange="chgxmltxt(this, 'host');" value="">
<?php echo _('task::cindexer:host') ?>&nbsp;:&nbsp;<input type="text" name="host" style="width:100px;" onchange="chgxmltxt(this, 'host');" value="">
<br/>
<?php echo _('task::cindexer:port') ?>&nbsp;:&nbsp;<input type="text" name="port" style="width:100px;" onchange="chgxmltxt(this, 'port');" value="">
<br/>
@@ -299,7 +299,7 @@ class task_period_cindexer extends task_abstract
<br/>
<br/>
<?php echo _('task::cindexer:control socket') ?>&nbsp;:&nbsp;<input type="text" name="socket" style="width:50px;" onchange="chgxmltxt(this, 'socket');" value="">
<?php echo _('task::cindexer:control socket') ?>&nbsp;:&nbsp;<input type="text" name="socket" style="width:50px;" onchange="chgxmltxt(this, 'socket');" value="">
<br/>
<?php echo _('task::cindexer:Debug mask') ?>&nbsp;:&nbsp;<input type="text" name="debugmask" style="width:50px;" onchange="chgxmltxt(this, 'debugmask');" value="">
<br/>
@@ -310,20 +310,20 @@ class task_period_cindexer extends task_abstract
<br/>
</div>
<?php echo _('task::cindexer:MySQL charset') ?>&nbsp;:&nbsp;<input type="text" name="charset" style="width:100px;" onchange="chgxmltxt(this, 'charset');" value="">
<?php echo _('task::cindexer:MySQL charset') ?>&nbsp;:&nbsp;<input type="text" name="charset" style="width:100px;" onchange="chgxmltxt(this, 'charset');" value="">
<br/>
<input type="checkbox" name="nolog" onclick="chgxmlck(this, 'nolog');">&nbsp;<?php echo _('task::cindexer:do not (sys)log, but out to console)') ?>
<br/>
<?php echo _('task::cindexer:default language for new candidates') ?>&nbsp;:&nbsp;<input type="text" name="clng" style="width:50px;" onchange="chgxmltxt(this, 'clng');" value="">
<?php echo _('task::cindexer:default language for new candidates') ?>&nbsp;:&nbsp;<input type="text" name="clng" style="width:50px;" onchange="chgxmltxt(this, 'clng');" value="">
<br/>
<br/>
<hr/>
<br/>
<?php echo _('task::cindexer:windows specific') ?>&nbsp;:<br/>
<?php echo _('task::cindexer:windows specific') ?>&nbsp;:<br/>
<input type="checkbox" name="winsvc_run" onclick="chgxmlck(this, 'run');">&nbsp;<?php echo _('task::cindexer:run as application, not as service') ?>
<br/>
@@ -369,20 +369,12 @@ class task_period_cindexer extends task_abstract
{
$cmd = $this->binpath . 'phraseanet_indexer';
switch ($this->system) {
case "WINDOWS":
$cmd .= '.exe';
$nullfile = 'NUL';
$this->method = self::METHOD_PROC_OPEN;
break;
default:
case "DARWIN":
case "LINUX":
$nullfile = '/dev/null';
// $this->method = self::METHOD_FORK;
// $this->method = self::METHOD_EXEC;
$this->method = self::METHOD_PROC_OPEN;
break;
$nullfile = '/dev/null';
$this->method = self::METHOD_PROC_OPEN;
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$nullfile = '/dev/null';
$cmd .= '.exe';
}
if ( ! file_exists($cmd) || ! is_executable($cmd)) {
@@ -470,7 +462,7 @@ class task_period_cindexer extends task_abstract
private function run_with_proc_open($cmd, $args, $args_nopwd)
{
$nullfile = $this->system == 'WINDOWS' ? 'NUL' : '/dev/null';
$nullfile = defined('PHP_WINDOWS_VERSION_BUILD') ? 'NUL' : '/dev/null';
$descriptors = array();
$descriptors[1] = array("file", $nullfile, "a+");