mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-13 13:03:20 +00:00
-
This commit is contained in:
@@ -29,6 +29,20 @@ class module_console_schedulerStart extends Command
|
|||||||
parent::__construct($name);
|
parent::__construct($name);
|
||||||
|
|
||||||
$this->setDescription('Start the scheduler');
|
$this->setDescription('Start the scheduler');
|
||||||
|
$this->addOption(
|
||||||
|
'nolog'
|
||||||
|
, NULL
|
||||||
|
, 1 | InputOption::VALUE_NONE
|
||||||
|
, 'do not log (scheduler) to logfile'
|
||||||
|
, NULL
|
||||||
|
);
|
||||||
|
$this->addOption(
|
||||||
|
'notasklog'
|
||||||
|
, NULL
|
||||||
|
, 1 | InputOption::VALUE_NONE
|
||||||
|
, 'do not log (tasks) to logfiles'
|
||||||
|
, NULL
|
||||||
|
);
|
||||||
$this->setHelp(
|
$this->setHelp(
|
||||||
"You should use launch the command and finish it with `&`"
|
"You should use launch the command and finish it with `&`"
|
||||||
. " to return to the console\n\n"
|
. " to return to the console\n\n"
|
||||||
@@ -38,7 +52,7 @@ class module_console_schedulerStart extends Command
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(InputInterface $input, OutputInterface $output)
|
public function execute(InputInterface $zinput, OutputInterface $output)
|
||||||
{
|
{
|
||||||
if(!setup::is_installed())
|
if(!setup::is_installed())
|
||||||
{
|
{
|
||||||
@@ -48,7 +62,7 @@ class module_console_schedulerStart extends Command
|
|||||||
require_once dirname(__FILE__) . '/../../../../lib/bootstrap.php';
|
require_once dirname(__FILE__) . '/../../../../lib/bootstrap.php';
|
||||||
|
|
||||||
$scheduler = new task_Scheduler();
|
$scheduler = new task_Scheduler();
|
||||||
$scheduler->run($output, true);
|
$scheduler->run($zinput, $output); //, !$input->getOption('nolog'), !$input->getOption('notasklog'));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -43,11 +43,28 @@ class module_console_taskrun extends Command
|
|||||||
, 'The name of the runner (manual, scheduler...)'
|
, 'The name of the runner (manual, scheduler...)'
|
||||||
, task_abstract::RUNNER_MANUAL
|
, task_abstract::RUNNER_MANUAL
|
||||||
);
|
);
|
||||||
|
$this->addOption(
|
||||||
|
'nolog'
|
||||||
|
, NULL
|
||||||
|
, 1 | InputOption::VALUE_NONE
|
||||||
|
, 'do not log to logfile'
|
||||||
|
, NULL
|
||||||
|
);
|
||||||
$this->setDescription('Run task');
|
$this->setDescription('Run task');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sig_handler($signo)
|
||||||
|
{
|
||||||
|
if($this->task)
|
||||||
|
{
|
||||||
|
$this->task->log(sprintf("signal %s received", $signo));
|
||||||
|
if($signo == SIGTERM)
|
||||||
|
$this->task->set_running(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function execute(InputInterface $input, OutputInterface $output)
|
public function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
if(!setup::is_installed())
|
if(!setup::is_installed())
|
||||||
@@ -81,9 +98,12 @@ class module_console_taskrun extends Command
|
|||||||
|
|
||||||
register_tick_function(array($this, 'tick_handler'), true);
|
register_tick_function(array($this, 'tick_handler'), true);
|
||||||
declare(ticks=1);
|
declare(ticks=1);
|
||||||
|
pcntl_signal(SIGTERM, array($this, 'sig_handler'));
|
||||||
|
|
||||||
|
$this->task->run($runner, $input, $output);
|
||||||
|
|
||||||
|
$this->task->log(sprintf("%s [%d] taskrun : returned from 'run()', get_status()=%s \n", __FILE__, __LINE__, $this->task->get_status()));
|
||||||
|
|
||||||
$this->task->run($runner);
|
|
||||||
printf("TASK QUIT\n");
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,6 +26,7 @@ class task_Scheduler
|
|||||||
const METHOD_PROC_OPEN = 'METHOD_PROC_OPEN';
|
const METHOD_PROC_OPEN = 'METHOD_PROC_OPEN';
|
||||||
|
|
||||||
private $method;
|
private $method;
|
||||||
|
private $input;
|
||||||
protected $output;
|
protected $output;
|
||||||
|
|
||||||
protected function log($message)
|
protected function log($message)
|
||||||
@@ -33,18 +34,21 @@ class task_Scheduler
|
|||||||
$registry = registry::get_instance();
|
$registry = registry::get_instance();
|
||||||
$logdir = $registry->get('GV_RootPath') . 'logs/';
|
$logdir = $registry->get('GV_RootPath') . 'logs/';
|
||||||
|
|
||||||
logs::rotate($logdir . "scheduler.log");
|
logs::rotate($logdir . "scheduler_l.log");
|
||||||
|
logs::rotate($logdir . "scheduler_o.log");
|
||||||
|
logs::rotate($logdir . "scheduler_e.log");
|
||||||
|
|
||||||
$date_obj = new DateTime();
|
$date_obj = new DateTime();
|
||||||
$message = sprintf("%s\t%s", $date_obj->format(DATE_ATOM), $message);
|
$message = sprintf("%s\t%s", $date_obj->format(DATE_ATOM), $message);
|
||||||
|
|
||||||
if($this->output instanceof OutputInterface)
|
if($this->output instanceof OutputInterface)
|
||||||
{
|
{
|
||||||
$this->output->writeln($message);
|
// $this->output->writeln($message);
|
||||||
}
|
}
|
||||||
// else
|
// $this->output->writeln($this->input->getOption('nolog'));
|
||||||
|
if($this->input && !($this->input->getOption('nolog')))
|
||||||
{
|
{
|
||||||
file_put_contents($logdir . "scheduler.log", $message."\n", FILE_APPEND);
|
file_put_contents($logdir . "scheduler_l.log", $message . "\n", FILE_APPEND);
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -52,20 +56,32 @@ class task_Scheduler
|
|||||||
protected static function get_connection()
|
protected static function get_connection()
|
||||||
{
|
{
|
||||||
require dirname(__FILE__) . '/../../../config/connexion.inc';
|
require dirname(__FILE__) . '/../../../config/connexion.inc';
|
||||||
|
return(appbox::get_instance()->get_connection());
|
||||||
return new connection_pdo('appbox', $hostname, $port, $user, $password, $dbname);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run(OutputInterface $output = null, $log_tasks = true)
|
public function run($input=null, OutputInterface $output = null) //, $log = true, $log_tasks = true)
|
||||||
{
|
{
|
||||||
$this->method = self::METHOD_FORK;
|
$this->method = self::METHOD_FORK;
|
||||||
|
|
||||||
require_once dirname(__FILE__) . '/../../bootstrap.php';
|
require_once dirname(__FILE__) . '/../../bootstrap.php';
|
||||||
|
$this->input = $input;
|
||||||
$this->output = $output;
|
$this->output = $output;
|
||||||
$appbox = appbox::get_instance();
|
$appbox = appbox::get_instance();
|
||||||
$registry = $appbox->get_registry();
|
$registry = $appbox->get_registry();
|
||||||
|
|
||||||
|
$nullfile = '';
|
||||||
$system = system_server::get_platform();
|
$system = system_server::get_platform();
|
||||||
|
switch($system)
|
||||||
|
{
|
||||||
|
case "WINDOWS":
|
||||||
|
$nullfile = 'NUL';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
case "DARWIN":
|
||||||
|
case "LINUX":
|
||||||
|
$nullfile = '/dev/null';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
$lockdir = $registry->get('GV_RootPath') . 'tmp/locks/';
|
$lockdir = $registry->get('GV_RootPath') . 'tmp/locks/';
|
||||||
|
|
||||||
@@ -101,13 +117,12 @@ class task_Scheduler
|
|||||||
|
|
||||||
$this->log(sprintf("running scheduler with method %s", $this->method));
|
$this->log(sprintf("running scheduler with method %s", $this->method));
|
||||||
|
|
||||||
|
|
||||||
if($this->method == self::METHOD_FORK)
|
if($this->method == self::METHOD_FORK)
|
||||||
pcntl_signal(SIGCHLD, SIG_IGN);
|
pcntl_signal(SIGCHLD, SIG_IGN);
|
||||||
|
|
||||||
$logdir = $registry->get('GV_RootPath') . 'logs/';
|
$logdir = $registry->get('GV_RootPath') . 'logs/';
|
||||||
|
|
||||||
$conn = self::get_connection();
|
$conn = appbox::get_instance()->get_connection();
|
||||||
|
|
||||||
$taskPoll = array(); // the poll of tasks
|
$taskPoll = array(); // the poll of tasks
|
||||||
|
|
||||||
@@ -146,15 +161,36 @@ class task_Scheduler
|
|||||||
|
|
||||||
while($schedstatus == 'started' || $runningtask > 0)
|
while($schedstatus == 'started' || $runningtask > 0)
|
||||||
{
|
{
|
||||||
while(!$conn->ping())
|
while(1)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
assert(is_object($conn));
|
||||||
|
$ping = @$conn->ping();
|
||||||
|
}
|
||||||
|
catch(ErrorException $e)
|
||||||
|
{
|
||||||
|
$ping = false;
|
||||||
|
}
|
||||||
|
if($ping)
|
||||||
|
break;
|
||||||
|
|
||||||
unset($conn);
|
unset($conn);
|
||||||
if(!$connwaslost)
|
if(!$connwaslost)
|
||||||
{
|
{
|
||||||
$this->log(sprintf("Warning : abox connection lost, restarting in 10 min."));
|
$this->log(sprintf("Warning : abox connection lost, restarting in 10 min."));
|
||||||
}
|
}
|
||||||
sleep(60 * 10);
|
for($i = 0; $i < 60 * 10; $i++)
|
||||||
$conn = self::get_connection();
|
sleep(1);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$conn = appbox::get_instance()->get_connection();
|
||||||
|
}
|
||||||
|
catch(ErrorException $e)
|
||||||
|
{
|
||||||
|
$ping = false;
|
||||||
|
}
|
||||||
|
|
||||||
$connwaslost = true;
|
$connwaslost = true;
|
||||||
}
|
}
|
||||||
if($connwaslost)
|
if($connwaslost)
|
||||||
@@ -168,13 +204,21 @@ class task_Scheduler
|
|||||||
|
|
||||||
$connwaslost = false;
|
$connwaslost = false;
|
||||||
}
|
}
|
||||||
|
// printf("%d \n", __LINE__);
|
||||||
$schedstatus = '';
|
$schedstatus = '';
|
||||||
|
$row = NULL;
|
||||||
|
try
|
||||||
|
{
|
||||||
$sql = "SELECT schedstatus FROM sitepreff";
|
$sql = "SELECT schedstatus FROM sitepreff";
|
||||||
$stmt = $conn->prepare($sql);
|
$stmt = $conn->prepare($sql);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
}
|
||||||
|
catch(ErrorException $e)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if($row)
|
if($row)
|
||||||
{
|
{
|
||||||
@@ -193,14 +237,14 @@ class task_Scheduler
|
|||||||
$stmt = $conn->prepare($sql);
|
$stmt = $conn->prepare($sql);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
|
||||||
$this->log("schedstatus == 'stopping', waiting tasks to end");
|
$this->log("schedstatus == 'stopping', waiting tasks to end");
|
||||||
}
|
}
|
||||||
|
|
||||||
logs::rotate($logdir . "scheduler.log");
|
logs::rotate($logdir . "scheduler_t.log");
|
||||||
logs::rotate($logdir . "scheduler.error.log");
|
logs::rotate($logdir . "scheduler_o.log");
|
||||||
|
logs::rotate($logdir . "scheduler_e.log");
|
||||||
|
|
||||||
|
// printf("%d \n", __LINE__);
|
||||||
// initialy, all tasks are supposed to be removed from the poll
|
// initialy, all tasks are supposed to be removed from the poll
|
||||||
foreach($taskPoll as $tkey => $task)
|
foreach($taskPoll as $tkey => $task)
|
||||||
$taskPoll[$tkey]["todel"] = true;
|
$taskPoll[$tkey]["todel"] = true;
|
||||||
@@ -208,32 +252,41 @@ class task_Scheduler
|
|||||||
foreach($task_manager->get_tasks(true) as $task)
|
foreach($task_manager->get_tasks(true) as $task)
|
||||||
{
|
{
|
||||||
$tkey = "t_" . $task->get_task_id();
|
$tkey = "t_" . $task->get_task_id();
|
||||||
|
$status = $task->get_status();
|
||||||
|
|
||||||
logs::rotate($logdir . "task_$tkey.log");
|
logs::rotate($logdir . "task_t_" . $task->get_task_id() . ".log");
|
||||||
logs::rotate($logdir . "task_$tkey.error.log");
|
logs::rotate($logdir . "task_o_" . $task->get_task_id() . ".log");
|
||||||
|
logs::rotate($logdir . "task_e_" . $task->get_task_id() . ".log");
|
||||||
|
|
||||||
if(!isset($taskPoll[$tkey]))
|
if(!isset($taskPoll[$tkey]))
|
||||||
{
|
{
|
||||||
// the task is not in the poll, add it
|
// the task is not in the poll, add it
|
||||||
$phpcli = $registry->get('GV_cli');
|
$phpcli = $registry->get('GV_cli');
|
||||||
|
|
||||||
switch($system)
|
switch($system)
|
||||||
{
|
{
|
||||||
|
case "WINDOWS":
|
||||||
|
$cmd = $phpcli;
|
||||||
|
$args = array('-f', $registry->get('GV_RootPath') . 'bin/console', '--', '-q', 'task:run', $task->get_task_id(), '--runner=scheduler');
|
||||||
|
if($this->input && ($this->input->getOption('notasklog')))
|
||||||
|
$args[] = 'notasklog';
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
case "DARWIN":
|
case "DARWIN":
|
||||||
case "WINDOWS":
|
|
||||||
case "LINUX":
|
case "LINUX":
|
||||||
$cmd = $phpcli;
|
$cmd = $phpcli;
|
||||||
$args = array('-f', $registry->get('GV_RootPath') . 'bin/console', 'task:run', $task->get_task_id(), '--runner=scheduler');
|
$args = array('-f', $registry->get('GV_RootPath') . 'bin/console', '--', '-q', 'task:run', $task->get_task_id(), '--runner=scheduler');
|
||||||
|
if($this->input && ($this->input->getOption('notasklog')))
|
||||||
|
$args[] = 'notasklog';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$taskPoll[$tkey] = array(
|
$taskPoll[$tkey] = array(
|
||||||
"task" => $task,
|
"task" => $task,
|
||||||
"current_status" => $task->get_status(),
|
"current_status" => $status,
|
||||||
"cmd" => $cmd,
|
"cmd" => $cmd,
|
||||||
"args" => $args,
|
"args" => $args,
|
||||||
"killat" => null
|
"killat" => null,
|
||||||
|
"sigterm_sent" => false
|
||||||
);
|
);
|
||||||
if($this->method == self::METHOD_PROC_OPEN)
|
if($this->method == self::METHOD_PROC_OPEN)
|
||||||
{
|
{
|
||||||
@@ -245,24 +298,24 @@ class task_Scheduler
|
|||||||
sprintf(
|
sprintf(
|
||||||
"new Task %s, status=%s"
|
"new Task %s, status=%s"
|
||||||
, $taskPoll[$tkey]["task"]->get_task_id()
|
, $taskPoll[$tkey]["task"]->get_task_id()
|
||||||
, $task->get_status()
|
, $status
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// the task is already in the poll, update its status
|
// the task is already in the poll, update its status
|
||||||
if($taskPoll[$tkey]["current_status"] != $task->get_status())
|
if($taskPoll[$tkey]["current_status"] != $status)
|
||||||
{
|
{
|
||||||
$this->log(
|
$this->log(
|
||||||
sprintf(
|
sprintf(
|
||||||
"Task %s, oldstatus=%s, newstatus=%s"
|
"Task %s, oldstatus=%s, newstatus=%s"
|
||||||
, $taskPoll[$tkey]["task"]->get_task_id()
|
, $taskPoll[$tkey]["task"]->get_task_id()
|
||||||
, $taskPoll[$tkey]["current_status"]
|
, $taskPoll[$tkey]["current_status"]
|
||||||
, $task->get_status()
|
, $status
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$taskPoll[$tkey]["current_status"] = $task->get_status();
|
$taskPoll[$tkey]["current_status"] = $status;
|
||||||
}
|
}
|
||||||
// update the whole task object
|
// update the whole task object
|
||||||
unset($taskPoll[$tkey]["task"]);
|
unset($taskPoll[$tkey]["task"]);
|
||||||
@@ -284,18 +337,16 @@ class task_Scheduler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Launch task that are not yet launched
|
||||||
/**
|
|
||||||
* Launch task that are not yet launched
|
|
||||||
*/
|
|
||||||
$runningtask = 0;
|
$runningtask = 0;
|
||||||
|
|
||||||
foreach($taskPoll as $tkey => $tv)
|
foreach($taskPoll as $tkey => $tv)
|
||||||
{
|
{
|
||||||
switch($tv['task']->get_status())
|
$status = $tv['task']->get_status();
|
||||||
|
switch($status)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
$this->log(sprintf('Unknow status `%s`', $tv['task']->get_status()));
|
$this->log(sprintf('Unknow status `%s`', $status));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case task_abstract::RETURNSTATUS_TORESTART:
|
case task_abstract::RETURNSTATUS_TORESTART:
|
||||||
@@ -332,24 +383,8 @@ class task_Scheduler
|
|||||||
{
|
{
|
||||||
if(!$taskPoll[$tkey]["process"])
|
if(!$taskPoll[$tkey]["process"])
|
||||||
{
|
{
|
||||||
$descriptors = array(
|
$descriptors[1] = array('file', $logdir . "task_o_" . $task->get_task_id() . ".log", 'a+');
|
||||||
1 => array("pipe", "w"),
|
$descriptors[2] = array('file', $logdir . "task_e_" . $task->get_task_id() . ".log", 'a+');
|
||||||
2 => array("pipe", "w")
|
|
||||||
);
|
|
||||||
|
|
||||||
if($log_tasks === true)
|
|
||||||
{
|
|
||||||
$descriptors[1] = array(
|
|
||||||
"file"
|
|
||||||
, $logdir . "task_$tkey.log"
|
|
||||||
, "a+"
|
|
||||||
);
|
|
||||||
$descriptors[2] = array(
|
|
||||||
"file"
|
|
||||||
, $logdir . "task_$tkey.error.log"
|
|
||||||
, "a+"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$taskPoll[$tkey]["process"] = proc_open(
|
$taskPoll[$tkey]["process"] = proc_open(
|
||||||
$taskPoll[$tkey]["cmd"] . ' ' . implode(' ', $taskPoll[$tkey]["args"])
|
$taskPoll[$tkey]["cmd"] . ' ' . implode(' ', $taskPoll[$tkey]["args"])
|
||||||
@@ -415,27 +450,25 @@ class task_Scheduler
|
|||||||
// child
|
// child
|
||||||
// printf("hello i am child pid=%d\n", getmypid());
|
// printf("hello i am child pid=%d\n", getmypid());
|
||||||
// printf("%s %s \n", $taskPoll[$tkey]["cmd"], implode(' ', $taskPoll[$tkey]["args"]));
|
// printf("%s %s \n", $taskPoll[$tkey]["cmd"], implode(' ', $taskPoll[$tkey]["args"]));
|
||||||
// ;
|
|
||||||
umask(0);
|
umask(0);
|
||||||
openlog('MyLog', LOG_PID | LOG_PERROR, LOG_LOCAL0);
|
|
||||||
if(posix_setsid() < 0)
|
if(posix_setsid() < 0)
|
||||||
die("Forked process could not detach from terminal\n");
|
die("Forked process could not detach from terminal\n");
|
||||||
//chdir(dirname(__FILE__));
|
|
||||||
fclose(STDIN);
|
fclose(STDIN);
|
||||||
fclose(STDOUT);
|
fclose(STDOUT);
|
||||||
fclose(STDERR);
|
fclose(STDERR);
|
||||||
$fdIN = fopen('/dev/null', 'r');
|
$fdIN = fopen($nullfile, 'r');
|
||||||
$fdOUT = fopen($logdir . "task_$tkey.log", 'a+');
|
$fdOUT = fopen($logdir . "task_o_" . $taskPoll[$tkey]["task"]->get_task_id() . ".log", 'a+');
|
||||||
$fdERR = fopen($logdir . "task_$tkey.error.log", 'a+');
|
$fdERR = fopen($logdir . "task_e_" . $taskPoll[$tkey]["task"]->get_task_id() . ".log", 'a+');
|
||||||
|
|
||||||
|
$this->log(sprintf("exec('%s %s')", $taskPoll[$tkey]["cmd"], implode(' ', $taskPoll[$tkey]["args"])));
|
||||||
pcntl_exec($taskPoll[$tkey]["cmd"], $taskPoll[$tkey]["args"]);
|
pcntl_exec($taskPoll[$tkey]["cmd"], $taskPoll[$tkey]["args"]);
|
||||||
|
|
||||||
sleep(2);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// parent
|
// parent
|
||||||
// printf("hello i am parent pid=%d\n", getmypid());
|
// sleep(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -506,33 +539,30 @@ class task_Scheduler
|
|||||||
if($taskPoll[$tkey]["killat"] === NULL)
|
if($taskPoll[$tkey]["killat"] === NULL)
|
||||||
$taskPoll[$tkey]["killat"] = time() + self::TASKDELAYTOQUIT;
|
$taskPoll[$tkey]["killat"] = time() + self::TASKDELAYTOQUIT;
|
||||||
|
|
||||||
$tpid = $taskPoll[$tkey]['task']->get_pid();
|
$pid = $taskPoll[$tkey]['task']->get_pid();
|
||||||
if($tpid)
|
if($pid)
|
||||||
{
|
{
|
||||||
|
if(!$taskPoll[$tkey]['sigterm_sent'])
|
||||||
|
{
|
||||||
|
posix_kill($pid, SIGTERM);
|
||||||
|
$this->log(
|
||||||
|
sprintf(
|
||||||
|
"SIGTERM sent to task %s (pid=%s)"
|
||||||
|
, $taskPoll[$tkey]["task"]->get_task_id()
|
||||||
|
, $pid
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if(($dt = $taskPoll[$tkey]["killat"] - time()) < 0)
|
if(($dt = $taskPoll[$tkey]["killat"] - time()) < 0)
|
||||||
{
|
{
|
||||||
if($this->method == self::METHOD_PROC_OPEN)
|
|
||||||
{
|
|
||||||
$pids = preg_split('/\s+/', `ps -o pid --no-heading --ppid $tpid`);
|
|
||||||
foreach($pids as $pid)
|
|
||||||
{
|
|
||||||
if(is_numeric($pid))
|
|
||||||
{
|
|
||||||
$this->log("Killing pid %d", $pid);
|
|
||||||
posix_kill($pid, 9);
|
posix_kill($pid, 9);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
elseif($this->method == self::METHOD_FORK)
|
|
||||||
{
|
|
||||||
posix_kill($tpid, 9);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->log(
|
$this->log(
|
||||||
sprintf(
|
sprintf(
|
||||||
"SIGKILL sent to task %s (pid=%s)"
|
"SIGKILL sent to task %s (pid=%s)"
|
||||||
, $taskPoll[$tkey]["task"]->get_task_id()
|
, $taskPoll[$tkey]["task"]->get_task_id()
|
||||||
, $tpid
|
, $pid
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -569,6 +599,7 @@ class task_Scheduler
|
|||||||
, $taskPoll[$tkey]["task"]->get_task_id()
|
, $taskPoll[$tkey]["task"]->get_task_id()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
$taskPoll[$tkey]["task"]->set_status(task_abstract::RETURNSTATUS_STOPPED);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -590,290 +621,8 @@ class task_Scheduler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for($i=0; $i<$sleeptime; $i++)
|
||||||
/*
|
sleep(1);
|
||||||
|
|
||||||
|
|
||||||
$common_status = array(
|
|
||||||
task_abstract::STATUS_STARTED
|
|
||||||
, task_abstract::RETURNSTATUS_STOPPED
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
foreach($taskPoll as $tkey => $tv)
|
|
||||||
{
|
|
||||||
// if (!in_array($taskPoll[$tkey]["task"]->get_status(), $common_status))
|
|
||||||
// {
|
|
||||||
// $this->log(
|
|
||||||
// sprintf(
|
|
||||||
// 'task %s has status %s'
|
|
||||||
// , $taskPoll[$tkey]["task"]->get_task_id()
|
|
||||||
// , $taskPoll[$tkey]["task"]->get_status()
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
switch($tv['task']->get_status())
|
|
||||||
{
|
|
||||||
default:
|
|
||||||
$this->log(sprintf('Unknow status `%s`', $tv['task']->get_status()));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case task_abstract::RETURNSTATUS_TORESTART:
|
|
||||||
if(!$taskPoll[$tkey]['task']->get_pid())
|
|
||||||
{
|
|
||||||
@fclose($taskPoll[$tkey]["pipes"][1]);
|
|
||||||
@fclose($taskPoll[$tkey]["pipes"][2]);
|
|
||||||
@proc_close($taskPoll[$tkey]["process"]);
|
|
||||||
|
|
||||||
$taskPoll[$tkey]["process"] = null;
|
|
||||||
if($schedstatus == 'started')
|
|
||||||
{
|
|
||||||
$taskPoll[$tkey]["task"]->set_status(task_abstract::STATUS_TOSTART);
|
|
||||||
}
|
|
||||||
// trick to start the task immediatly : DON'T break if ending with 'tostart'
|
|
||||||
// so it will continue with 'tostart' case !
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case task_abstract::STATUS_TOSTART:
|
|
||||||
// if scheduler is 'tostop', don't launch a new task !
|
|
||||||
if($schedstatus != 'started')
|
|
||||||
break;
|
|
||||||
|
|
||||||
$taskPoll[$tkey]["killat"] = NULL;
|
|
||||||
if(!$taskPoll[$tkey]["process"])
|
|
||||||
{
|
|
||||||
$descriptors = array(
|
|
||||||
1 => array("pipe", "w"),
|
|
||||||
2 => array("pipe", "w")
|
|
||||||
);
|
|
||||||
|
|
||||||
if($log_tasks === true)
|
|
||||||
{
|
|
||||||
$descriptors[1] = array(
|
|
||||||
"file"
|
|
||||||
, $logdir . "task_$tkey.log"
|
|
||||||
, "a+"
|
|
||||||
);
|
|
||||||
$descriptors[2] = array(
|
|
||||||
"file"
|
|
||||||
, $logdir . "task_$tkey.error.log"
|
|
||||||
, "a+"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$taskPoll[$tkey]["process"] = proc_open(
|
|
||||||
$taskPoll[$tkey]["cmd"].' '.implode(' ', $taskPoll[$tkey]["args"])
|
|
||||||
, $descriptors
|
|
||||||
, $taskPoll[$tkey]["pipes"]
|
|
||||||
, $registry->get('GV_RootPath') . "bin/"
|
|
||||||
, null
|
|
||||||
, array('bypass_shell' => true)
|
|
||||||
);
|
|
||||||
|
|
||||||
if(is_resource($taskPoll[$tkey]["process"]))
|
|
||||||
{
|
|
||||||
sleep(2); // let the process lock and write it's pid
|
|
||||||
}
|
|
||||||
|
|
||||||
if(is_resource($taskPoll[$tkey]["process"]) && $taskPoll[$tkey]['task']->get_pid() !== null)
|
|
||||||
{
|
|
||||||
|
|
||||||
// ************************************************
|
|
||||||
// file_put_contents("/tmp/scheduler2.log", sprintf("%s [%d] : RUNNING ? : pid=%s \n", __FILE__, __LINE__, $taskPoll[$tkey]['task']->get_pid()), FILE_APPEND);
|
|
||||||
|
|
||||||
$this->log(
|
|
||||||
sprintf(
|
|
||||||
"Task %s '%s' started (pid=%s)"
|
|
||||||
, $taskPoll[$tkey]['task']->get_task_id()
|
|
||||||
, $taskPoll[$tkey]["cmd"]
|
|
||||||
, $taskPoll[$tkey]['task']->get_pid()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$runningtask++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// ************************************************
|
|
||||||
// file_put_contents("/tmp/scheduler2.log", sprintf("%s [%d] : NOT RUNNING ? : pid=%s \n", __FILE__, __LINE__, $taskPoll[$tkey]['task']->get_pid()), FILE_APPEND);
|
|
||||||
$taskPoll[$tkey]["task"]->increment_crash_counter();
|
|
||||||
|
|
||||||
@fclose($taskPoll[$tkey]["pipes"][1]);
|
|
||||||
@fclose($taskPoll[$tkey]["pipes"][2]);
|
|
||||||
@proc_close($taskPoll[$tkey]["process"]);
|
|
||||||
$taskPoll[$tkey]["process"] = null;
|
|
||||||
|
|
||||||
$this->log(
|
|
||||||
sprintf(
|
|
||||||
"Task %s '%s' failed to start %d times"
|
|
||||||
, $taskPoll[$tkey]["task"]->get_task_id()
|
|
||||||
, $taskPoll[$tkey]["cmd"]
|
|
||||||
, $taskPoll[$tkey]["task"]->get_crash_counter()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if($taskPoll[$tkey]["task"]->get_crash_counter() > 5)
|
|
||||||
{
|
|
||||||
$taskPoll[$tkey]["task"]->set_status(task_abstract::RETURNSTATUS_STOPPED);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$taskPoll[$tkey]["task"]->set_status(task_abstract::STATUS_TOSTART);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case task_abstract::STATUS_STARTED:
|
|
||||||
$crashed = false;
|
|
||||||
// If no process, the task is probably manually ran
|
|
||||||
if($taskPoll[$tkey]["process"])
|
|
||||||
{
|
|
||||||
$taskPoll[$tkey]["killat"] = NULL;
|
|
||||||
|
|
||||||
// if(is_resource($taskPoll[$tkey]["process"]))
|
|
||||||
// {
|
|
||||||
// $proc_status = proc_get_status($taskPoll[$tkey]["process"]);
|
|
||||||
// if($proc_status['running'])
|
|
||||||
// $runningtask++;
|
|
||||||
// else
|
|
||||||
// $crashed = true;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// $crashed = true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
if($taskPoll[$tkey]['task']->get_pid())
|
|
||||||
$runningtask++;
|
|
||||||
else
|
|
||||||
$crashed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($crashed === true && $taskPoll[$tkey]["task"]->get_status() === task_abstract::RETURNSTATUS_TORESTART)
|
|
||||||
{
|
|
||||||
$crashed = false;
|
|
||||||
}
|
|
||||||
if($crashed)
|
|
||||||
{
|
|
||||||
$taskPoll[$tkey]["task"]->increment_crash_counter();
|
|
||||||
|
|
||||||
@fclose($taskPoll[$tkey]["pipes"][1]);
|
|
||||||
@fclose($taskPoll[$tkey]["pipes"][2]);
|
|
||||||
@proc_close($taskPoll[$tkey]["process"]);
|
|
||||||
$taskPoll[$tkey]["process"] = null;
|
|
||||||
|
|
||||||
$this->log(
|
|
||||||
sprintf(
|
|
||||||
"Task %s crashed %d times"
|
|
||||||
, $taskPoll[$tkey]["task"]->get_task_id()
|
|
||||||
, $taskPoll[$tkey]["task"]->get_crash_counter()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
if($taskPoll[$tkey]["task"]->get_crash_counter() > 5)
|
|
||||||
{
|
|
||||||
$taskPoll[$tkey]["task"]->set_status(task_abstract::RETURNSTATUS_STOPPED);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$taskPoll[$tkey]["task"]->set_status(task_abstract::STATUS_TOSTART);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case task_abstract::STATUS_TOSTOP:
|
|
||||||
if($taskPoll[$tkey]["process"])
|
|
||||||
{
|
|
||||||
if($taskPoll[$tkey]["killat"] === NULL)
|
|
||||||
$taskPoll[$tkey]["killat"] = time() + self::TASKDELAYTOQUIT;
|
|
||||||
|
|
||||||
if(($dt = $taskPoll[$tkey]["killat"] - time()) < 0)
|
|
||||||
{
|
|
||||||
$ppid = $taskPoll[$tkey]['task']->get_pid();
|
|
||||||
$pids = preg_split('/\s+/', `ps -o pid --no-heading --ppid $ppid`);
|
|
||||||
foreach($pids as $pid)
|
|
||||||
{
|
|
||||||
if(is_numeric($pid))
|
|
||||||
{
|
|
||||||
$this->log("Killing pid %d", $pid);
|
|
||||||
posix_kill($pid, 9);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->log(
|
|
||||||
sprintf(
|
|
||||||
"SIGKILL sent to task %s (pid=%s)"
|
|
||||||
, $taskPoll[$tkey]["task"]->get_task_id()
|
|
||||||
, $taskPoll[$tkey]["task"]->get_pid()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
proc_terminate($taskPoll[$tkey]["process"], 9);
|
|
||||||
@fclose($taskPoll[$tkey]["pipes"][1]);
|
|
||||||
@fclose($taskPoll[$tkey]["pipes"][2]);
|
|
||||||
proc_close($taskPoll[$tkey]["process"]);
|
|
||||||
unlink($lockdir . 'task_' . $taskPoll[$tkey]['task']->get_task_id() . '.lock');
|
|
||||||
|
|
||||||
$taskPoll[$tkey]["task"]->increment_crash_counter();
|
|
||||||
// $taskPoll[$tkey]["task"]->set_pid(null);
|
|
||||||
$taskPoll[$tkey]["task"]->set_status(task_abstract::RETURNSTATUS_STOPPED);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->log(
|
|
||||||
sprintf(
|
|
||||||
"waiting task %s to quit (kill in %d seconds)"
|
|
||||||
, $taskPoll[$tkey]["task"]->get_task_id()
|
|
||||||
, $dt
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$runningtask++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case task_abstract::RETURNSTATUS_STOPPED:
|
|
||||||
case task_abstract::RETURNSTATUS_TODELETE:
|
|
||||||
if($taskPoll[$tkey]["process"])
|
|
||||||
{
|
|
||||||
@fclose($taskPoll[$tkey]["pipes"][1]);
|
|
||||||
@fclose($taskPoll[$tkey]["pipes"][2]);
|
|
||||||
@proc_close($taskPoll[$tkey]["process"]);
|
|
||||||
|
|
||||||
$taskPoll[$tkey]["process"] = null;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$to_reopen = false;
|
|
||||||
if($conn->ping())
|
|
||||||
{
|
|
||||||
$conn->close();
|
|
||||||
unset($conn);
|
|
||||||
$to_reopen = true;
|
|
||||||
}
|
|
||||||
sleep($sleeptime);
|
|
||||||
if($to_reopen)
|
|
||||||
{
|
|
||||||
$conn = self::get_connection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "UPDATE sitepreff SET schedstatus='stopped', schedpid='0'";
|
$sql = "UPDATE sitepreff SET schedstatus='stopped', schedpid='0'";
|
||||||
|
@@ -90,6 +90,9 @@ abstract class task_abstract
|
|||||||
protected $return_value;
|
protected $return_value;
|
||||||
protected $runner;
|
protected $runner;
|
||||||
|
|
||||||
|
private $input;
|
||||||
|
private $output;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* delay between two loops
|
* delay between two loops
|
||||||
*
|
*
|
||||||
@@ -104,7 +107,15 @@ abstract class task_abstract
|
|||||||
|
|
||||||
public function get_status()
|
public function get_status()
|
||||||
{
|
{
|
||||||
return $this->task_status;
|
$conn = connection::getPDOConnection();
|
||||||
|
$sql = 'SELECT status FROM task2 WHERE task_id = :taskid';
|
||||||
|
$stmt = $conn->prepare($sql);
|
||||||
|
$stmt->execute(array(':taskid' => $this->taskid));
|
||||||
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
$stmt->closeCursor();
|
||||||
|
if(!$row)
|
||||||
|
throw new Exception('Unknown task id');
|
||||||
|
return $row['status'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function printInterfaceHEAD()
|
public function printInterfaceHEAD()
|
||||||
@@ -141,7 +152,7 @@ abstract class task_abstract
|
|||||||
$stmt = $conn->prepare($sql);
|
$stmt = $conn->prepare($sql);
|
||||||
$stmt->execute(array(':status' => $status, ':taskid' => $this->get_task_id()));
|
$stmt->execute(array(':status' => $status, ':taskid' => $this->get_task_id()));
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
$this->log(sprintf("task %d <- %s", $this->get_task_id(), $status));
|
||||||
$this->task_status = $status;
|
$this->task_status = $status;
|
||||||
|
|
||||||
return $this->task_status;
|
return $this->task_status;
|
||||||
@@ -265,6 +276,7 @@ abstract class task_abstract
|
|||||||
function __construct($taskid)
|
function __construct($taskid)
|
||||||
{
|
{
|
||||||
$this->taskid = $taskid;
|
$this->taskid = $taskid;
|
||||||
|
|
||||||
phrasea::use_i18n(Session_Handler::get_locale());
|
phrasea::use_i18n(Session_Handler::get_locale());
|
||||||
|
|
||||||
$this->system = system_server::get_platform();
|
$this->system = system_server::get_platform();
|
||||||
@@ -296,7 +308,7 @@ abstract class task_abstract
|
|||||||
$this->log($e->getMessage());
|
$this->log($e->getMessage());
|
||||||
$this->log(("Warning : abox connection lost, restarting in 10 min."));
|
$this->log(("Warning : abox connection lost, restarting in 10 min."));
|
||||||
|
|
||||||
for($t = 60 * 10; $t > 0; $t--) // DON'T do sleep(600) because it prevents ticks !
|
for($t = 60 * 10; $this->running && $t > 0; $t--) // DON'T do sleep(600) because it prevents ticks !
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|
||||||
$this->running = false;
|
$this->running = false;
|
||||||
@@ -353,6 +365,8 @@ abstract class task_abstract
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function delete()
|
public function delete()
|
||||||
|
{
|
||||||
|
if(!$this->get_pid()) // do not delete a running task
|
||||||
{
|
{
|
||||||
$conn = connection::getPDOConnection();
|
$conn = connection::getPDOConnection();
|
||||||
$registry = registry::get_instance();
|
$registry = registry::get_instance();
|
||||||
@@ -362,10 +376,8 @@ abstract class task_abstract
|
|||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
|
||||||
$lock_file = $registry->get('GV_RootPath') . 'tmp/locks/task_' . $this->get_task_id() . '.lock';
|
$lock_file = $registry->get('GV_RootPath') . 'tmp/locks/task_' . $this->get_task_id() . '.lock';
|
||||||
if(is_writable($lock_file))
|
@unlink($lock_file);
|
||||||
unlink($lock_file);
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function check_memory_usage()
|
protected function check_memory_usage()
|
||||||
@@ -521,6 +533,11 @@ abstract class task_abstract
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function set_running($stat)
|
||||||
|
{
|
||||||
|
$this->running = $stat;
|
||||||
|
}
|
||||||
|
|
||||||
protected function pause($when_started=0)
|
protected function pause($when_started=0)
|
||||||
{
|
{
|
||||||
$this->log($this->records_done . ' records done');
|
$this->log($this->records_done . ' records done');
|
||||||
@@ -532,15 +549,16 @@ abstract class task_abstract
|
|||||||
$conn = connection::getPDOConnection();
|
$conn = connection::getPDOConnection();
|
||||||
$conn->close();
|
$conn->close();
|
||||||
unset($conn);
|
unset($conn);
|
||||||
// sleep($this->period - $when_started);
|
for($t = $this->period - $when_started; $this->running && $t > 0; $t--) // DON'T do sleep($this->period - $when_started) because it prevents ticks !
|
||||||
for($t = $this->period - $when_started; $t > 0; $t--) // DON'T do sleep($this->period - $when_started) because it prevents ticks !
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final public function run($runner)
|
final public function run($runner, $input=null, $output = null)
|
||||||
{
|
{
|
||||||
|
$this->input = $input;
|
||||||
|
$this->output = $output;
|
||||||
|
|
||||||
// ************************************************
|
// ************************************************
|
||||||
// file_put_contents("/tmp/scheduler2.log", sprintf("%s [%d] : LAUNCHING : tid=%s \n", __FILE__, __LINE__, $this->get_task_id()), FILE_APPEND);
|
// file_put_contents("/tmp/scheduler2.log", sprintf("%s [%d] : LAUNCHING : tid=%s \n", __FILE__, __LINE__, $this->get_task_id()), FILE_APPEND);
|
||||||
@@ -555,7 +573,7 @@ abstract class task_abstract
|
|||||||
{
|
{
|
||||||
// ************************************************
|
// ************************************************
|
||||||
// file_put_contents("/tmp/scheduler2.log", sprintf("%s [%d] : LAUNCH OPENED AND CANT LOCK : pid=%s \n", __FILE__, __LINE__, getmypid()), FILE_APPEND);
|
// file_put_contents("/tmp/scheduler2.log", sprintf("%s [%d] : LAUNCH OPENED AND CANT LOCK : pid=%s \n", __FILE__, __LINE__, getmypid()), FILE_APPEND);
|
||||||
printf(("runtask::ERROR : task already running.\n"), $taskid);
|
$this->log("runtask::ERROR : task already running.");
|
||||||
fclose($tasklock);
|
fclose($tasklock);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -574,8 +592,8 @@ abstract class task_abstract
|
|||||||
$this->set_status(self::STATUS_STARTED);
|
$this->set_status(self::STATUS_STARTED);
|
||||||
|
|
||||||
$this->running = true;
|
$this->running = true;
|
||||||
|
|
||||||
$this->run2();
|
$this->run2();
|
||||||
// $this->set_pid(0);
|
|
||||||
|
|
||||||
flock($tasklock, LOCK_UN | LOCK_NB);
|
flock($tasklock, LOCK_UN | LOCK_NB);
|
||||||
ftruncate($tasklock, 0);
|
ftruncate($tasklock, 0);
|
||||||
@@ -586,7 +604,6 @@ abstract class task_abstract
|
|||||||
$this->delete();
|
$this->delete();
|
||||||
else
|
else
|
||||||
$this->set_status($this->return_value);
|
$this->set_status($this->return_value);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -651,12 +668,30 @@ abstract class task_abstract
|
|||||||
// print($s);
|
// print($s);
|
||||||
}
|
}
|
||||||
|
|
||||||
function log($msg = '')
|
public function log($message)
|
||||||
{
|
{
|
||||||
// $d = debug_backtrace(false);
|
$registry = registry::get_instance();
|
||||||
// printf("%s\t[%s]\t%s\r\n", date('r'), $d[0]['line'], $msg);
|
$logdir = $registry->get('GV_RootPath') . 'logs/';
|
||||||
printf("%s\t%s\r\n", date('r'), $msg);
|
|
||||||
|
logs::rotate($logdir . 'task_l_'.$this->taskid.'.log');
|
||||||
|
logs::rotate($logdir . 'task_o_'.$this->taskid.'.log');
|
||||||
|
logs::rotate($logdir . 'task_e_'.$this->taskid.'.log');
|
||||||
|
|
||||||
|
$date_obj = new DateTime();
|
||||||
|
$message = sprintf("%s\t%s", $date_obj->format(DATE_ATOM), $message);
|
||||||
|
|
||||||
|
if($this->output)
|
||||||
|
{
|
||||||
|
$this->output->writeln($message);
|
||||||
}
|
}
|
||||||
|
if( $this->input && !($this->input->getOption('nolog')) )
|
||||||
|
{
|
||||||
|
file_put_contents($logdir . 'task_l_'.$this->taskid.'.log', $message."\n", FILE_APPEND);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function interfaceAvailable()
|
public static function interfaceAvailable()
|
||||||
{
|
{
|
||||||
|
@@ -33,27 +33,32 @@ abstract class task_databoxAbstract extends task_abstract
|
|||||||
|
|
||||||
protected function run2()
|
protected function run2()
|
||||||
{
|
{
|
||||||
|
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
|
||||||
while($this->running)
|
while($this->running)
|
||||||
{
|
{
|
||||||
|
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$conn = connection::getPDOConnection();
|
$conn = connection::getPDOConnection();
|
||||||
}
|
}
|
||||||
catch(Exception $e)
|
catch(Exception $e)
|
||||||
{
|
{
|
||||||
|
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
|
||||||
$this->log($e->getMessage());
|
$this->log($e->getMessage());
|
||||||
$this->log(("Warning : abox connection lost, restarting in 10 min."));
|
$this->log(("Warning : abox connection lost, restarting in 10 min."));
|
||||||
|
|
||||||
for($t = 60 * 10; $t; $t--) // DON'T do sleep(600) because it prevents ticks !
|
for($t = 60 * 10; $this->running && $t; $t--) // DON'T do sleep(600) because it prevents ticks !
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|
||||||
$this->running = false;
|
$this->running = false;
|
||||||
$this->return_value = self::RETURNSTATUS_TORESTART;
|
$this->return_value = self::RETURNSTATUS_TORESTART;
|
||||||
|
|
||||||
|
$this->log(sprintf("%s [%d] returning from 'run2()' rv=%s \n", __FILE__, __LINE__, $this->return_value));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->set_last_exec_time();
|
$this->set_last_exec_time();
|
||||||
|
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -67,12 +72,14 @@ abstract class task_databoxAbstract extends task_abstract
|
|||||||
}
|
}
|
||||||
catch(Exception $e)
|
catch(Exception $e)
|
||||||
{
|
{
|
||||||
|
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
|
||||||
$this->task_status = self::STATUS_TOSTOP;
|
$this->task_status = self::STATUS_TOSTOP;
|
||||||
$this->return_value = self::RETURNSTATUS_STOPPED;
|
$this->return_value = self::RETURNSTATUS_STOPPED;
|
||||||
$rs = array();
|
$rs = array();
|
||||||
}
|
}
|
||||||
foreach($rs as $row)
|
foreach($rs as $row)
|
||||||
{
|
{
|
||||||
|
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
|
||||||
if(!$this->running)
|
if(!$this->running)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -89,6 +96,7 @@ abstract class task_databoxAbstract extends task_abstract
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
|
||||||
$this->load_settings(simplexml_load_string($row['settings']));
|
$this->load_settings(simplexml_load_string($row['settings']));
|
||||||
}
|
}
|
||||||
catch(Exception $e)
|
catch(Exception $e)
|
||||||
@@ -98,14 +106,26 @@ abstract class task_databoxAbstract extends task_abstract
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->current_state = self::STATE_OK;
|
$this->current_state = self::STATE_OK;
|
||||||
$this->process_sbas()
|
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
|
||||||
->check_current_state()
|
$this->process_sbas()->check_current_state();
|
||||||
->flush_records_sbas();
|
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
|
||||||
|
$this->process_sbas()->flush_records_sbas();
|
||||||
|
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
|
||||||
}
|
}
|
||||||
|
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
|
||||||
|
|
||||||
$this->increment_loops();
|
$this->increment_loops();
|
||||||
|
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
|
||||||
$this->pause($duration);
|
$this->pause($duration);
|
||||||
}
|
}
|
||||||
|
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
|
||||||
|
$this->process_sbas()->check_current_state();
|
||||||
|
$this->log(sprintf("%s [%d] rv=%s \n", __FILE__, __LINE__, $this->return_value));
|
||||||
|
$this->process_sbas()->flush_records_sbas();
|
||||||
|
|
||||||
|
$this->set_status($this->return_value);
|
||||||
|
|
||||||
|
$this->log(sprintf("%s [%d] returning from 'run2()' rv=%s \n", __FILE__, __LINE__, $this->return_value));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -167,13 +167,7 @@ class task_manager
|
|||||||
|
|
||||||
public function get_scheduler_state2()
|
public function get_scheduler_state2()
|
||||||
{
|
{
|
||||||
$sql = "SELECT UNIX_TIMESTAMP()-UNIX_TIMESTAMP(schedqtime) AS qdelay, schedstatus AS status FROM sitepreff";
|
$pid = NULL;
|
||||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
|
||||||
$stmt->execute();
|
|
||||||
$ret = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
||||||
$stmt->closeCursor();
|
|
||||||
$ret['pid'] = NULL;
|
|
||||||
|
|
||||||
$appbox = appbox::get_instance();
|
$appbox = appbox::get_instance();
|
||||||
$lockdir = $appbox->get_registry()->get('GV_RootPath') . 'tmp/locks/';
|
$lockdir = $appbox->get_registry()->get('GV_RootPath') . 'tmp/locks/';
|
||||||
if( ($schedlock = fopen( $lockdir . 'scheduler.lock', 'a+')) )
|
if( ($schedlock = fopen( $lockdir . 'scheduler.lock', 'a+')) )
|
||||||
@@ -181,7 +175,7 @@ class task_manager
|
|||||||
if (flock($schedlock, LOCK_SH | LOCK_NB) === FALSE)
|
if (flock($schedlock, LOCK_SH | LOCK_NB) === FALSE)
|
||||||
{
|
{
|
||||||
// already locked : running !
|
// already locked : running !
|
||||||
$ret['pid'] = fgets($schedlock, 512);
|
$pid = trim(fgets($schedlock, 512));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -190,6 +184,20 @@ class task_manager
|
|||||||
}
|
}
|
||||||
fclose($schedlock);
|
fclose($schedlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$sql = "SELECT UNIX_TIMESTAMP()-UNIX_TIMESTAMP(schedqtime) AS qdelay, schedstatus AS status FROM sitepreff";
|
||||||
|
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||||
|
$stmt->execute();
|
||||||
|
$ret = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
$stmt->closeCursor();
|
||||||
|
|
||||||
|
if($pid === NULL && $ret['status'] !== 'stopped')
|
||||||
|
{
|
||||||
|
// auto fix
|
||||||
|
$this->appbox->get_connection()->exec('UPDATE sitepreff SET schedstatus=\'stopped\'');
|
||||||
|
$ret['status'] = 'stopped';
|
||||||
|
}
|
||||||
|
$ret['pid'] = $pid;
|
||||||
return($ret);
|
return($ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -16,6 +16,11 @@
|
|||||||
*/
|
*/
|
||||||
class task_period_cindexer extends task_abstract
|
class task_period_cindexer extends task_abstract
|
||||||
{
|
{
|
||||||
|
// how to execute indexer (choose in 'run2' method)
|
||||||
|
private $method;
|
||||||
|
const METHOD_FORK = 'METHOD_FORK';
|
||||||
|
const METHOD_EXEC = 'METHOD_EXEC';
|
||||||
|
const METHOD_PROC_OPEN = 'METHOD_PROC_OPEN';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -115,18 +120,18 @@ class task_period_cindexer extends task_abstract
|
|||||||
);
|
);
|
||||||
$dom = new DOMDocument();
|
$dom = new DOMDocument();
|
||||||
$dom->formatOutput = true;
|
$dom->formatOutput = true;
|
||||||
if ($dom->loadXML($oldxml))
|
if($dom->loadXML($oldxml))
|
||||||
{
|
{
|
||||||
$xmlchanged = false;
|
$xmlchanged = false;
|
||||||
foreach (array("str:binpath", "str:host", "str:port", "str:base", "str:user", "str:password", "str:socket", "boo:use_sbas", "boo:nolog", "str:clng", "boo:winsvc_run", "str:charset") as $pname)
|
foreach(array("str:binpath", "str:host", "str:port", "str:base", "str:user", "str:password", "str:socket", "boo:use_sbas", "boo:nolog", "str:clng", "boo:winsvc_run", "str:charset") as $pname)
|
||||||
{
|
{
|
||||||
$ptype = substr($pname, 0, 3);
|
$ptype = substr($pname, 0, 3);
|
||||||
$pname = substr($pname, 4);
|
$pname = substr($pname, 4);
|
||||||
$pvalue = $parm2[$pname];
|
$pvalue = $parm2[$pname];
|
||||||
if ($ns = $dom->getElementsByTagName($pname)->item(0))
|
if($ns = $dom->getElementsByTagName($pname)->item(0))
|
||||||
{
|
{
|
||||||
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
|
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
|
||||||
while (($n = $ns->firstChild))
|
while(($n = $ns->firstChild))
|
||||||
$ns->removeChild($n);
|
$ns->removeChild($n);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -135,7 +140,7 @@ class task_period_cindexer extends task_abstract
|
|||||||
$ns = $dom->documentElement->appendChild($dom->createElement($pname));
|
$ns = $dom->documentElement->appendChild($dom->createElement($pname));
|
||||||
}
|
}
|
||||||
// on fixe sa valeur
|
// on fixe sa valeur
|
||||||
switch ($ptype)
|
switch($ptype)
|
||||||
{
|
{
|
||||||
case "str":
|
case "str":
|
||||||
$ns->appendChild($dom->createTextNode($pvalue));
|
$ns->appendChild($dom->createTextNode($pvalue));
|
||||||
@@ -159,7 +164,7 @@ class task_period_cindexer extends task_abstract
|
|||||||
*/
|
*/
|
||||||
public function xml2graphic($xml, $form)
|
public function xml2graphic($xml, $form)
|
||||||
{
|
{
|
||||||
if (($sxml = simplexml_load_string($xml))) // in fact XML IS always valid here...
|
if(($sxml = simplexml_load_string($xml))) // in fact XML IS always valid here...
|
||||||
{
|
{
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@@ -178,7 +183,6 @@ class task_period_cindexer extends task_abstract
|
|||||||
parent.calccmd();
|
parent.calccmd();
|
||||||
</script>
|
</script>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return("");
|
return("");
|
||||||
}
|
}
|
||||||
else // ... so we NEVER come here
|
else // ... so we NEVER come here
|
||||||
@@ -195,7 +199,7 @@ class task_period_cindexer extends task_abstract
|
|||||||
public function printInterfaceJS()
|
public function printInterfaceJS()
|
||||||
{
|
{
|
||||||
$appname = 'phraseanet_indexer';
|
$appname = 'phraseanet_indexer';
|
||||||
if ($this->system == 'WINDOWS')
|
if($this->system == 'WINDOWS')
|
||||||
$appname .= '.exe';
|
$appname .= '.exe';
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@@ -247,7 +251,6 @@ class task_period_cindexer extends task_abstract
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,7 +270,7 @@ class task_period_cindexer extends task_abstract
|
|||||||
public function printInterfaceHTML()
|
public function printInterfaceHTML()
|
||||||
{
|
{
|
||||||
$appname = 'phraseanet_indexer';
|
$appname = 'phraseanet_indexer';
|
||||||
if ($this->system == 'WINDOWS')
|
if($this->system == 'WINDOWS')
|
||||||
$appname .= '.exe';
|
$appname .= '.exe';
|
||||||
ob_start();
|
ob_start();
|
||||||
?>
|
?>
|
||||||
@@ -356,50 +359,83 @@ class task_period_cindexer extends task_abstract
|
|||||||
*/
|
*/
|
||||||
protected function run2()
|
protected function run2()
|
||||||
{
|
{
|
||||||
$cmd = $this->binpath . 'phraseanet_indexer';
|
$this->method = self::METHOD_PROC_OPEN;
|
||||||
$nulfile = '/dev/null';
|
$this->method = self::METHOD_FORK;
|
||||||
|
$this->method = self::METHOD_EXEC;
|
||||||
|
|
||||||
if ($this->system == 'WINDOWS')
|
$cmd = $this->binpath . 'phraseanet_indexer';
|
||||||
|
$nullfile = '/dev/null';
|
||||||
|
|
||||||
|
if($this->system == 'WINDOWS')
|
||||||
{
|
{
|
||||||
$cmd .= '.exe';
|
$cmd .= '.exe';
|
||||||
$nulfile = 'nul';
|
$nullfile = 'NULL';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file_exists($cmd) || !is_executable($cmd))
|
if(!file_exists($cmd) || !is_executable($cmd))
|
||||||
{
|
{
|
||||||
$this->log(sprintf(_('task::cindexer:file \'%s\' does not exists'), $cmd));
|
$this->log(sprintf(_('task::cindexer:file \'%s\' does not exists'), $cmd));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cmd .= $this->host ? " -h=" . $this->host : '';
|
// $cmd .= $this->host ? " -h=" . $this->host : '';
|
||||||
$cmd .= $this->port ? " -P=" . $this->port : '';
|
// $cmd .= $this->port ? " -P=" . $this->port : '';
|
||||||
$cmd .= $this->base ? " -b=" . $this->base : '';
|
// $cmd .= $this->base ? " -b=" . $this->base : '';
|
||||||
$cmd .= $this->user ? " -u=" . $this->user : '';
|
// $cmd .= $this->user ? " -u=" . $this->user : '';
|
||||||
$cmd .= $this->password ? " -p=" . $this->password : '';
|
// $cmd .= $this->password ? " -p=" . $this->password : '';
|
||||||
$cmd .= $this->socket ? " --socket=" . $this->socket : '';
|
// $cmd .= $this->socket ? " --socket=" . $this->socket : '';
|
||||||
$cmd .= $this->use_sbas ? " -o" : '';
|
// $cmd .= $this->use_sbas ? " -o" : '';
|
||||||
$cmd .= $this->charset ? " --default-character-set=" . $this->charset : '';
|
// $cmd .= $this->charset ? " --default-character-set=" . $this->charset : '';
|
||||||
$cmd .= $this->nolog ? " -n" : '';
|
// $cmd .= $this->nolog ? " -n" : '';
|
||||||
$cmd .= $this->winsvc_run ? " --run" : '';
|
// $cmd .= $this->winsvc_run ? " --run" : '';
|
||||||
|
|
||||||
|
$args = array();
|
||||||
|
if($this->host)
|
||||||
|
$args[] = '-h=' . $this->host;
|
||||||
|
if($this->port)
|
||||||
|
;
|
||||||
|
$args[] = '-P=' . $this->port;
|
||||||
|
if($this->base)
|
||||||
|
$args[] = '-b=' . $this->base;
|
||||||
|
if($this->user)
|
||||||
|
$args[] = '-u=' . $this->user;
|
||||||
|
if($this->password)
|
||||||
|
$args[] = '-p=' . $this->password;
|
||||||
|
if($this->socket)
|
||||||
|
$args[] = '--socket=' . $this->socket;
|
||||||
|
if($this->use_sbas)
|
||||||
|
$args[] = '-o';
|
||||||
|
if($this->charset)
|
||||||
|
$args[] = '--default-character-set=' . $this->charset;
|
||||||
|
if($this->nolog)
|
||||||
|
$args[] = '-n';
|
||||||
|
if($this->winsvc_run)
|
||||||
|
$args[] = '--run';
|
||||||
|
|
||||||
$registry = registry::get_instance();
|
$registry = registry::get_instance();
|
||||||
$logdir = p4string::addEndSlash($registry->get('GV_RootPath') . 'logs');
|
$logdir = p4string::addEndSlash($registry->get('GV_RootPath') . 'logs');
|
||||||
|
|
||||||
|
$this->return_value = self::RETURNSTATUS_STOPPED; // will be normal ending
|
||||||
|
|
||||||
|
if($this->method == self::METHOD_PROC_OPEN)
|
||||||
|
{
|
||||||
$descriptors = array();
|
$descriptors = array();
|
||||||
$descriptors[1] = array("file", $logdir . "/phraseanet_indexer_" . $this->get_task_id() . ".log", "a+");
|
// $descriptors[1] = array("file", $logdir . "/phraseanet_indexer_" . $this->get_task_id() . ".log", "a+");
|
||||||
$descriptors[2] = array("file", $logdir . "/phraseanet_indexer_" . $this->get_task_id() . ".error.log", "a+");
|
// $descriptors[2] = array("file", $logdir . "/phraseanet_indexer_" . $this->get_task_id() . ".error.log", "a+");
|
||||||
|
$descriptors[1] = array("file", $nullfile, "a+");
|
||||||
|
$descriptors[2] = array("file", $nullfile, "a+");
|
||||||
|
|
||||||
$pipes = array();
|
$pipes = array();
|
||||||
|
|
||||||
$this->log(sprintf('cmd=\'%s\'', $cmd));
|
$this->log(sprintf('cmd=\'%s %s\'', $cmd, implode(' ', $args)));
|
||||||
$process = proc_open($cmd, $descriptors, $pipes, $this->binpath, null, array('bypass_shell' => true));
|
$process = proc_open($cmd . ' ' . implode(' ', $args), $descriptors, $pipes, $this->binpath, null, array('bypass_shell' => true));
|
||||||
|
|
||||||
$pid = NULL;
|
$pid = NULL;
|
||||||
if (is_resource($process))
|
if(is_resource($process))
|
||||||
{
|
{
|
||||||
$proc_status = proc_get_status($process);
|
$proc_status = proc_get_status($process);
|
||||||
if ($proc_status['running'])
|
if($proc_status['running'])
|
||||||
$pid = $proc_status['pid'];
|
$pid = $proc_status['pid'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,16 +445,16 @@ class task_period_cindexer extends task_abstract
|
|||||||
|
|
||||||
$this->running = true;
|
$this->running = true;
|
||||||
|
|
||||||
while ($this->running)
|
while($this->running)
|
||||||
{
|
{
|
||||||
$this->check_task_status();
|
$this->check_task_status();
|
||||||
|
|
||||||
if ($this->task_status == self::STATUS_TOSTOP && $this->socket > 0)
|
if($this->task_status == self::STATUS_TOSTOP && $this->socket > 0)
|
||||||
{
|
{
|
||||||
// must quit task, so send 'Q' to port 127.0.0.1:XXXX to cindexer
|
// must quit task, so send 'Q' to port 127.0.0.1:XXXX to cindexer
|
||||||
if (!$qsent && (($sock = socket_create(AF_INET, SOCK_STREAM, 0)) !== false))
|
if(!$qsent && (($sock = socket_create(AF_INET, SOCK_STREAM, 0)) !== false))
|
||||||
{
|
{
|
||||||
if (socket_connect($sock, '127.0.0.1', $this->socket) === true)
|
if(socket_connect($sock, '127.0.0.1', $this->socket) === true)
|
||||||
{
|
{
|
||||||
socket_write($sock, 'Q', 1);
|
socket_write($sock, 'Q', 1);
|
||||||
socket_write($sock, "\r\n", strlen("\r\n"));
|
socket_write($sock, "\r\n", strlen("\r\n"));
|
||||||
@@ -435,22 +471,29 @@ class task_period_cindexer extends task_abstract
|
|||||||
}
|
}
|
||||||
|
|
||||||
$proc_status = proc_get_status($process);
|
$proc_status = proc_get_status($process);
|
||||||
if (!$proc_status['running'])
|
if(!$proc_status['running'])
|
||||||
{
|
{
|
||||||
// the cindexer died
|
// the cindexer died
|
||||||
if ($qsent == 'Q')
|
if($qsent == 'Q')
|
||||||
|
{
|
||||||
$this->log(_('task::cindexer:the cindexer clean-quit'));
|
$this->log(_('task::cindexer:the cindexer clean-quit'));
|
||||||
elseif ($qsent == 'K')
|
}
|
||||||
|
elseif($qsent == 'K')
|
||||||
|
{
|
||||||
$this->log(_('task::cindexer:the cindexer has been killed'));
|
$this->log(_('task::cindexer:the cindexer has been killed'));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
$this->log(_('task::cindexer:the cindexer crashed'));
|
$this->log(_('task::cindexer:the cindexer crashed'));
|
||||||
|
$this->return_value = NULL; // NOT normal ending will enforce restart from scheduler
|
||||||
|
}
|
||||||
$this->running = false;
|
$this->running = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ($qsent == 'Q')
|
if($qsent == 'Q')
|
||||||
{
|
{
|
||||||
if (time() > $timetokill)
|
if(time() > $timetokill)
|
||||||
{
|
{
|
||||||
// must kill cindexer
|
// must kill cindexer
|
||||||
$this->log(_('task::cindexer:killing the cindexer'));
|
$this->log(_('task::cindexer:killing the cindexer'));
|
||||||
@@ -462,22 +505,135 @@ class task_period_cindexer extends task_abstract
|
|||||||
sleep(5);
|
sleep(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($sock)
|
if($sock)
|
||||||
{
|
{
|
||||||
socket_close($sock);
|
socket_close($sock);
|
||||||
$sock = NULL;
|
$sock = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (array_keys($pipes) as $offset)
|
foreach(array_keys($pipes) as $offset)
|
||||||
{
|
{
|
||||||
if (is_resource($pipes[$offset]))
|
if(is_resource($pipes[$offset]))
|
||||||
fclose($pipes[$offset]);
|
fclose($pipes[$offset]);
|
||||||
}
|
}
|
||||||
|
|
||||||
proc_terminate($process); // sigint
|
proc_terminate($process); // sigint
|
||||||
proc_close($process);
|
proc_close($process);
|
||||||
|
}
|
||||||
|
elseif($this->method == self::METHOD_FORK)
|
||||||
|
{
|
||||||
|
$pid = pcntl_fork();
|
||||||
|
if($pid == -1)
|
||||||
|
{
|
||||||
|
die("failed to fork");
|
||||||
|
}
|
||||||
|
elseif($pid == 0)
|
||||||
|
{
|
||||||
|
// child
|
||||||
|
umask(0);
|
||||||
|
// openlog('MyLog', LOG_PID | LOG_PERROR, LOG_LOCAL0);
|
||||||
|
if(posix_setsid() < 0)
|
||||||
|
die("Forked process could not detach from terminal\n");
|
||||||
|
//chdir(dirname(__FILE__));
|
||||||
|
fclose(STDIN);
|
||||||
|
fclose(STDOUT);
|
||||||
|
fclose(STDERR);
|
||||||
|
$fdIN = fopen($nullfile, 'r');
|
||||||
|
// $fdOUT = fopen($nullfile, 'a+');
|
||||||
|
// $fdERR = fopen($nullfile, 'a+');
|
||||||
|
$fdOUT = fopen($logdir . "/task_o_" . $this->get_task_id() . ".log", "a+");
|
||||||
|
$fdERR = fopen($logdir . "/task_e_" . $this->get_task_id() . ".log", "a+");
|
||||||
|
|
||||||
return self::RETURNSTATUS_STOPPED;
|
pcntl_exec($cmd, $args);
|
||||||
|
|
||||||
|
sleep(2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// parent
|
||||||
|
$this->running = true;
|
||||||
|
|
||||||
|
$sigsent = NULL;
|
||||||
|
while($this->running)
|
||||||
|
{
|
||||||
|
// is the cindexer alive ?
|
||||||
|
if(!posix_kill($pid, 0))
|
||||||
|
{
|
||||||
|
printf("%d \n", __LINE__);
|
||||||
|
// dead...
|
||||||
|
if($sigsent === NULL)
|
||||||
|
{
|
||||||
|
printf("%d \n", __LINE__);
|
||||||
|
// but it's not my fault
|
||||||
|
$this->log(_('task::cindexer:the cindexer crashed'));
|
||||||
|
$this->running = false;
|
||||||
|
// return self::RETURNSTATUS_STOPPED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%d \n", __LINE__);
|
||||||
|
$this->check_task_status();
|
||||||
|
|
||||||
|
if($this->task_status == self::STATUS_TOSTOP)
|
||||||
|
{
|
||||||
|
printf("%d \n", __LINE__);
|
||||||
|
posix_kill($pid, ($sigsent=SIGINT));
|
||||||
|
sleep(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
$status = NULL;
|
||||||
|
if(pcntl_wait($status, WNOHANG) == $pid)
|
||||||
|
{
|
||||||
|
printf("%d \n", __LINE__);
|
||||||
|
// child (indexer) has exited
|
||||||
|
if($sigsent == SIGINT)
|
||||||
|
{
|
||||||
|
$this->log(_('task::cindexer:the cindexer clean-quit'));
|
||||||
|
}
|
||||||
|
elseif($sigsent == SIGKILL)
|
||||||
|
{
|
||||||
|
$this->log(_('task::cindexer:the cindexer has been killed'));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->log(_('task::cindexer:the cindexer crashed'));
|
||||||
|
$this->return_value = NULL; // NOT normal ending will enforce restart from scheduler
|
||||||
|
}
|
||||||
|
$this->running = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("%d \n", __LINE__);
|
||||||
|
if($sigsent == SIGINT && time() > $timetokill)
|
||||||
|
{
|
||||||
|
printf("%d \n", __LINE__);
|
||||||
|
// must kill cindexer
|
||||||
|
$this->log(_('task::cindexer:killing the cindexer'));
|
||||||
|
$qsent = 'K';
|
||||||
|
posix_kill($pid, ($sigsent=SIGKILL));
|
||||||
|
}
|
||||||
|
sleep(2);
|
||||||
|
}
|
||||||
|
} // while running (method fork)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif($this->method == self::METHOD_EXEC)
|
||||||
|
{
|
||||||
|
umask(0);
|
||||||
|
fclose(STDIN);
|
||||||
|
fclose(STDOUT);
|
||||||
|
fclose(STDERR);
|
||||||
|
$fdIN = fopen($nullfile, 'r');
|
||||||
|
$fdOUT = fopen($logdir . "/task_o_" . $this->get_task_id() . ".log", "a+");
|
||||||
|
$fdERR = fopen($logdir . "/task_e_" . $this->get_task_id() . ".log", "a+");
|
||||||
|
|
||||||
|
pcntl_exec($cmd, $args);
|
||||||
|
|
||||||
|
sleep(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return($this->return_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -551,7 +551,8 @@ class task_period_outofdate extends task_abstract
|
|||||||
if(!$conn->ping())
|
if(!$conn->ping())
|
||||||
{
|
{
|
||||||
$this->log(("Warning : abox connection lost, restarting in 10 min."));
|
$this->log(("Warning : abox connection lost, restarting in 10 min."));
|
||||||
sleep(60 * 10);
|
for($i=0; $i<60 * 10; $i++)
|
||||||
|
sleep(1);
|
||||||
$this->running = false;
|
$this->running = false;
|
||||||
|
|
||||||
return(self::RETURNSTATUS_TORESTART);
|
return(self::RETURNSTATUS_TORESTART);
|
||||||
@@ -566,13 +567,13 @@ class task_period_outofdate extends task_abstract
|
|||||||
catch(Exception $e)
|
catch(Exception $e)
|
||||||
{
|
{
|
||||||
$this->log(("dbox connection lost, restarting in 10 min."));
|
$this->log(("dbox connection lost, restarting in 10 min."));
|
||||||
sleep(60 * 10);
|
for($i=0; $i<60 * 10; $i++)
|
||||||
|
sleep(1);
|
||||||
$this->running = false;
|
$this->running = false;
|
||||||
|
|
||||||
return(self::RETURNSTATUS_TORESTART);
|
return(self::RETURNSTATUS_TORESTART);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$this->set_last_exec_time();
|
$this->set_last_exec_time();
|
||||||
|
|
||||||
$databox = databox::get_instance($this->sbas_id);
|
$databox = databox::get_instance($this->sbas_id);
|
||||||
@@ -670,15 +671,28 @@ class task_period_outofdate extends task_abstract
|
|||||||
|
|
||||||
$nchanged = 0;
|
$nchanged = 0;
|
||||||
foreach($tsql as $xsql)
|
foreach($tsql as $xsql)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
$stmt = $this->connbas->prepare($xsql['sql']);
|
$stmt = $this->connbas->prepare($xsql['sql']);
|
||||||
$stmt->execute($xsql['params']);
|
if($stmt->execute($xsql['params']))
|
||||||
|
{
|
||||||
$n = $stmt->rowCount();
|
$n = $stmt->rowCount();
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
|
||||||
$nchanged += $n;
|
$nchanged += $n;
|
||||||
if($n > 0)
|
if($n > 0)
|
||||||
$this->log(sprintf(("SQL=%s\n - %s changes"), $xsql['sql'], $n));
|
$this->log(sprintf("SQL='%s' ; parms=%s - %s changes", $xsql['sql'], var_export($xsql['params']), $n));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->log(sprintf("ERROR SQL='%s' ; parms=%s", $xsql['sql'], var_export($xsql['params'], true)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (ErrorException $e)
|
||||||
|
{
|
||||||
|
$this->log(sprintf("ERROR SQL='%s' ; parms=%s", $xsql['sql'], var_export($xsql['params'], true)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret = ($nchanged > 0 ? $nchanged : 'NORECSTODO');
|
$ret = ($nchanged > 0 ? $nchanged : 'NORECSTODO');
|
||||||
@@ -686,228 +700,6 @@ class task_period_outofdate extends task_abstract
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
function doRecords()
|
|
||||||
{
|
|
||||||
$ndone = 0;
|
|
||||||
$ret = 'NORECSTODO';
|
|
||||||
|
|
||||||
$date1 = $date2 = NULL;
|
|
||||||
$field1 = $field2 = '';
|
|
||||||
|
|
||||||
// test : DATE 1
|
|
||||||
if(($field1 = trim($this->sxTaskSettings->field1)) != '')
|
|
||||||
{
|
|
||||||
$date1 = time();
|
|
||||||
if(($delta = (int) ($this->sxTaskSettings->fieldDv1)) > 0)
|
|
||||||
{
|
|
||||||
if($this->sxTaskSettings->fieldDs1 == '-')
|
|
||||||
$date1 += 86400 * $delta;
|
|
||||||
else
|
|
||||||
$date1 -= 86400 * $delta;
|
|
||||||
}
|
|
||||||
$date1 = date("YmdHis", $date1);
|
|
||||||
}
|
|
||||||
// test : DATE 2
|
|
||||||
if(($field2 = trim($this->sxTaskSettings->field2)) != '')
|
|
||||||
{
|
|
||||||
$date2 = time();
|
|
||||||
if(($delta = (int) ($this->sxTaskSettings->fieldDv2)) > 0)
|
|
||||||
{
|
|
||||||
if($this->sxTaskSettings->fieldDs2 == '-')
|
|
||||||
$date2 += 86400 * $delta;
|
|
||||||
else
|
|
||||||
$date2 -= 86400 * $delta;
|
|
||||||
}
|
|
||||||
$date2 = date("YmdHis", $date2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$sqlset = $params = $tmp_params = array();
|
|
||||||
for($i = 0; $i <= 2; $i++)
|
|
||||||
{
|
|
||||||
$sqlwhere[$i] = '';
|
|
||||||
$sqlset[$i] = '';
|
|
||||||
$x = 'status' . $i;
|
|
||||||
@list($tostat, $statval) = explode('_', (string) ($this->sxTaskSettings->{$x}));
|
|
||||||
if($tostat >= 4 && $tostat <= 63)
|
|
||||||
{
|
|
||||||
if($statval == '0')
|
|
||||||
{
|
|
||||||
$sqlset[$i] = 'status=status & ~(1<<' . $tostat . ')';
|
|
||||||
$sqlwhere[$i] .= '(status & (1<<' . $tostat . ') = 0)';
|
|
||||||
}
|
|
||||||
elseif($statval == '1')
|
|
||||||
{
|
|
||||||
$sqlset[$i] = 'status=status|(1<<' . $tostat . ')';
|
|
||||||
$sqlwhere[$i] .= '(status & (1<<' . $tostat . ') != 0)';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$x = 'coll' . $i;
|
|
||||||
if(($tocoll = (string) ($this->sxTaskSettings->{$x})) != '')
|
|
||||||
{
|
|
||||||
$sqlset[$i] .= ( $sqlset[$i] ? ', ' : '') . ('coll_id = :coll_id_set' . $i);
|
|
||||||
$sqlwhere[$i] .= ( $sqlwhere[$i] ? ' AND ' : '') . '(coll_id = :coll_id_where' . $i . ')';
|
|
||||||
$tmp_params[':coll_id_set' . $i] = $tocoll;
|
|
||||||
$tmp_params[':coll_id_where' . $i] = $tocoll;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for($i = 0; $i <= 2; $i++)
|
|
||||||
{
|
|
||||||
// if(!$sqlwhere[$i])
|
|
||||||
// $sqlwhere[$i] = '1';
|
|
||||||
}
|
|
||||||
|
|
||||||
$nchanged = 0;
|
|
||||||
// $sqlupd = 'UPDATE record INNER JOIN prop ON prop.record_id=record.record_id';
|
|
||||||
|
|
||||||
if($date1)
|
|
||||||
{
|
|
||||||
$params = array();
|
|
||||||
$params[':name1'] = $field1;
|
|
||||||
$params[':date1'] = $date1;
|
|
||||||
$params[':coll_id_set0'] = $tmp_params[':coll_id_set0'];
|
|
||||||
|
|
||||||
$w = 'p1.name = :name1 AND :date1 <= p1.value';
|
|
||||||
if($sqlwhere[1] && $sqlwhere[2])
|
|
||||||
{
|
|
||||||
$w .= ' AND ((' . $sqlwhere[1] . ') OR (' . $sqlwhere[2] . '))';
|
|
||||||
$params[':coll_id_where1'] = $tmp_params[':coll_id_where1'];
|
|
||||||
$params[':coll_id_where2'] = $tmp_params[':coll_id_where2'];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if($sqlwhere[1])
|
|
||||||
{
|
|
||||||
$w .= ' AND ' . $sqlwhere[1];
|
|
||||||
$params[':coll_id_where1'] = $tmp_params[':coll_id_where1'];
|
|
||||||
}
|
|
||||||
elseif($sqlwhere[2])
|
|
||||||
{
|
|
||||||
$w .= ' AND ' . $sqlwhere[2];
|
|
||||||
$params[':coll_id_where2'] = $tmp_params[':coll_id_where2'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql = "UPDATE prop AS p1 INNER JOIN record USING(record_id)
|
|
||||||
SET " . $sqlset[0] .
|
|
||||||
" WHERE " . $w;
|
|
||||||
printf("%d : %s \n%s", __LINE__, $sql, var_export($params, true));
|
|
||||||
|
|
||||||
$stmt = $this->connbas->prepare($sql);
|
|
||||||
$stmt->execute($params);
|
|
||||||
$n = $stmt->rowCount();
|
|
||||||
$stmt->closeCursor();
|
|
||||||
|
|
||||||
$nchanged += $n;
|
|
||||||
if($n > 0)
|
|
||||||
$this->log(sprintf(("SQL=%s\n - %s changes"), $sql, $n));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if($date2 && $date1)
|
|
||||||
{
|
|
||||||
$params = array();
|
|
||||||
$params[':name1'] = $field1;
|
|
||||||
$params[':name2'] = $field2;
|
|
||||||
$params[':date1'] = $date1;
|
|
||||||
$params[':date2'] = $date2;
|
|
||||||
$params[':coll_id_set1'] = $tmp_params[':coll_id_set1'];
|
|
||||||
|
|
||||||
$w = 'p1.name = :name1 AND p2.name = :name2 AND :date1 > p1.value AND :date2 <= p2.value';
|
|
||||||
if($sqlwhere[0] && $sqlwhere[2])
|
|
||||||
{
|
|
||||||
$w .= ' AND ((' . $sqlwhere[0] . ') OR (' . $sqlwhere[2] . '))';
|
|
||||||
$params[':coll_id_where0'] = $tmp_params[':coll_id_where0'];
|
|
||||||
$params[':coll_id_where2'] = $tmp_params[':coll_id_where2'];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if($sqlwhere[0])
|
|
||||||
{
|
|
||||||
$w .= ' AND ' . $sqlwhere[0];
|
|
||||||
$params[':coll_id_where0'] = $tmp_params[':coll_id_where0'];
|
|
||||||
}
|
|
||||||
elseif($sqlwhere[2])
|
|
||||||
{
|
|
||||||
$w .= ' AND ' . $sqlwhere[2];
|
|
||||||
$params[':coll_id_where2'] = $tmp_params[':coll_id_where2'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql = "UPDATE (prop AS p1 INNER JOIN prop AS p2 USING(record_id))
|
|
||||||
INNER JOIN record USING(record_id)
|
|
||||||
SET " . $sqlset[1] .
|
|
||||||
" WHERE " . $w;
|
|
||||||
printf("%d : %s \n%s", __LINE__, $sql, var_export($params, true));
|
|
||||||
|
|
||||||
$stmt = $this->connbas->prepare($sql);
|
|
||||||
$stmt->execute($params);
|
|
||||||
$n = $stmt->rowCount();
|
|
||||||
$stmt->closeCursor();
|
|
||||||
|
|
||||||
$nchanged += $n;
|
|
||||||
if($n > 0)
|
|
||||||
$this->log(sprintf(("SQL=%s\n - %s changes"), $sql, $n));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if($date2)
|
|
||||||
{
|
|
||||||
$params = array();
|
|
||||||
$params[':name2'] = $field2;
|
|
||||||
$params[':date2'] = $date2;
|
|
||||||
$params[':coll_id_set2'] = $tmp_params[':coll_id_set2'];
|
|
||||||
|
|
||||||
$w = 'p2.name = :name2 AND :date2 > p2.value';
|
|
||||||
if($sqlwhere[0] && $sqlwhere[1])
|
|
||||||
{
|
|
||||||
$w .= ' AND ((' . $sqlwhere[0] . ') OR (' . $sqlwhere[2] . '))';
|
|
||||||
$params[':coll_id_where0'] = $tmp_params[':coll_id_where0'];
|
|
||||||
$params[':coll_id_where1'] = $tmp_params[':coll_id_where1'];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if($sqlwhere[0])
|
|
||||||
{
|
|
||||||
$w .= ' AND ' . $sqlwhere[0];
|
|
||||||
$params[':coll_id_where0'] = $tmp_params[':coll_id_where0'];
|
|
||||||
}
|
|
||||||
elseif($sqlwhere[1])
|
|
||||||
{
|
|
||||||
$w .= ' AND ' . $sqlwhere[1];
|
|
||||||
$params[':coll_id_where1'] = $tmp_params[':coll_id_where1'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql = "UPDATE prop AS p2 INNER JOIN record USING(record_id)
|
|
||||||
SET " . $sqlset[2] .
|
|
||||||
" WHERE " . $w;
|
|
||||||
|
|
||||||
printf("%d : %s \n%s", __LINE__, $sql, var_export($params, true));
|
|
||||||
|
|
||||||
$stmt = $this->connbas->prepare($sql);
|
|
||||||
$stmt->execute($params);
|
|
||||||
$n = $stmt->rowCount();
|
|
||||||
$stmt->closeCursor();
|
|
||||||
|
|
||||||
$nchanged += $n;
|
|
||||||
if($n > 0)
|
|
||||||
$this->log(sprintf(("SQL=%s\n - %s changes"), $sql, $n));
|
|
||||||
}
|
|
||||||
|
|
||||||
$ret = ($nchanged > 0 ? $nchanged : 'NORECSTODO');
|
|
||||||
|
|
||||||
return($ret);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
private function calcSQL($sxTaskSettings)
|
private function calcSQL($sxTaskSettings)
|
||||||
{
|
{
|
||||||
$ret = array();
|
$ret = array();
|
||||||
@@ -1006,24 +798,11 @@ class task_period_outofdate extends task_abstract
|
|||||||
$sql = "UPDATE prop AS p1 INNER JOIN record USING(record_id)
|
$sql = "UPDATE prop AS p1 INNER JOIN record USING(record_id)
|
||||||
SET " . $sqlset[0] .
|
SET " . $sqlset[0] .
|
||||||
" WHERE " . $w;
|
" WHERE " . $w;
|
||||||
// printf("%d : %s \n%s", __LINE__, $sql, var_export($params, true));
|
|
||||||
|
|
||||||
$ret[] = array('sql'=>$sql, 'params'=>$params);
|
$ret[] = array('sql'=>$sql, 'params'=>$params);
|
||||||
|
|
||||||
// $stmt = $this->connbas->prepare($sql);
|
|
||||||
// $stmt->execute($params);
|
|
||||||
// $n = $stmt->rowCount();
|
|
||||||
// $stmt->closeCursor();
|
|
||||||
//
|
|
||||||
// $nchanged += $n;
|
|
||||||
// if($n > 0)
|
|
||||||
// $this->log(sprintf(("SQL=%s\n - %s changes"), $sql, $n));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if($date1 && $date2)
|
if($date1 && $date2)
|
||||||
{
|
{
|
||||||
$params = array();
|
$params = array();
|
||||||
@@ -1058,22 +837,11 @@ class task_period_outofdate extends task_abstract
|
|||||||
INNER JOIN record USING(record_id)
|
INNER JOIN record USING(record_id)
|
||||||
SET " . $sqlset[1] .
|
SET " . $sqlset[1] .
|
||||||
" WHERE " . $w;
|
" WHERE " . $w;
|
||||||
// printf("%d : %s \n%s", __LINE__, $sql, var_export($params, true));
|
|
||||||
|
|
||||||
$ret[] = array('sql'=>$sql, 'params'=>$params);
|
$ret[] = array('sql'=>$sql, 'params'=>$params);
|
||||||
|
|
||||||
// $stmt = $this->connbas->prepare($sql);
|
|
||||||
// $stmt->execute($params);
|
|
||||||
// $n = $stmt->rowCount();
|
|
||||||
// $stmt->closeCursor();
|
|
||||||
//
|
|
||||||
// $nchanged += $n;
|
|
||||||
// if($n > 0)
|
|
||||||
// $this->log(sprintf(("SQL=%s\n - %s changes"), $sql, $n));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if($date2 && $sqlset[2])
|
if($date2 && $sqlset[2])
|
||||||
{
|
{
|
||||||
$params = array();
|
$params = array();
|
||||||
@@ -1084,7 +852,7 @@ class task_period_outofdate extends task_abstract
|
|||||||
$w = 'p2.name = :name2 AND :date2 > p2.value';
|
$w = 'p2.name = :name2 AND :date2 > p2.value';
|
||||||
if($sqlwhere[0] && $sqlwhere[1])
|
if($sqlwhere[0] && $sqlwhere[1])
|
||||||
{
|
{
|
||||||
$w .= ' AND ((' . $sqlwhere[0] . ') OR (' . $sqlwhere[2] . '))';
|
$w .= ' AND ((' . $sqlwhere[0] . ') OR (' . $sqlwhere[1] . '))';
|
||||||
$params[':coll_id_where0'] = $tmp_params[':coll_id_where0'];
|
$params[':coll_id_where0'] = $tmp_params[':coll_id_where0'];
|
||||||
$params[':coll_id_where1'] = $tmp_params[':coll_id_where1'];
|
$params[':coll_id_where1'] = $tmp_params[':coll_id_where1'];
|
||||||
}
|
}
|
||||||
@@ -1106,121 +874,13 @@ class task_period_outofdate extends task_abstract
|
|||||||
SET " . $sqlset[2] .
|
SET " . $sqlset[2] .
|
||||||
" WHERE " . $w;
|
" WHERE " . $w;
|
||||||
|
|
||||||
// printf("%d : %s \n%s", __LINE__, $sql, var_export($params, true));
|
|
||||||
|
|
||||||
$ret[] = array('sql'=>$sql, 'params'=>$params);
|
$ret[] = array('sql'=>$sql, 'params'=>$params);
|
||||||
|
|
||||||
// $stmt = $this->connbas->prepare($sql);
|
|
||||||
// $stmt->execute($params);
|
|
||||||
// $n = $stmt->rowCount();
|
|
||||||
// $stmt->closeCursor();
|
|
||||||
//
|
|
||||||
// $nchanged += $n;
|
|
||||||
// if($n > 0)
|
|
||||||
// $this->log(sprintf(("SQL=%s\n - %s changes"), $sql, $n));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return($ret);
|
return($ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function no_calcSQL($sxTaskSettings)
|
|
||||||
{
|
|
||||||
$ret = array();
|
|
||||||
|
|
||||||
$date1 = $date2 = time();
|
|
||||||
$field1 = $field2 = '';
|
|
||||||
|
|
||||||
// test : DATE 1
|
|
||||||
if(($field1 = trim($sxTaskSettings->field1)) != '')
|
|
||||||
{
|
|
||||||
if(($delta = (int) ($sxTaskSettings->fieldDv1)) > 0)
|
|
||||||
{
|
|
||||||
if($sxTaskSettings->fieldDs1 == '-')
|
|
||||||
$date1 += 86400 * $delta;
|
|
||||||
else
|
|
||||||
$date1 -= 86400 * $delta;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// test : DATE 2
|
|
||||||
if(($field2 = trim($sxTaskSettings->field2)) != '')
|
|
||||||
{
|
|
||||||
if(($delta = (int) ($sxTaskSettings->fieldDv2)) > 0)
|
|
||||||
{
|
|
||||||
if($sxTaskSettings->fieldDs2 == '-')
|
|
||||||
$date2 += 86400 * $delta;
|
|
||||||
else
|
|
||||||
$date2 -= 86400 * $delta;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$date1 = date("YmdHis", $date1);
|
|
||||||
$date2 = date("YmdHis", $date2);
|
|
||||||
|
|
||||||
$sqlset = array();
|
|
||||||
for($i = 0; $i <= 2; $i++)
|
|
||||||
{
|
|
||||||
$sqlset[$i] = '';
|
|
||||||
$x = 'status' . $i;
|
|
||||||
@list($tostat, $statval) = explode('_', (string) ($sxTaskSettings->{$x}));
|
|
||||||
if($tostat >= 4 && $tostat <= 63)
|
|
||||||
{
|
|
||||||
if($statval == '0')
|
|
||||||
$sqlset[$i] = 'status=status&~(1<<' . $tostat . ')';
|
|
||||||
elseif($statval == '1')
|
|
||||||
$sqlset[$i] = 'status=status|(1<<' . $tostat . ')';
|
|
||||||
}
|
|
||||||
$x = 'coll' . $i;
|
|
||||||
if(($tocoll = (string) ($sxTaskSettings->{$x})) != '')
|
|
||||||
$sqlset[$i] .= ($sqlset[$i] ? ', ' : '') . ('coll_id=\'' . $tocoll . '\'');
|
|
||||||
}
|
|
||||||
|
|
||||||
// $sqlupd = 'UPDATE record INNER JOIN prop ON prop.record_id=record.record_id';
|
|
||||||
|
|
||||||
if($sqlset[0] && $field1)
|
|
||||||
{
|
|
||||||
$sql = 'UPDATE prop AS p1 INNER JOIN record USING(record_id)' .
|
|
||||||
' SET ' . $sqlset[0] .
|
|
||||||
' WHERE p1.name=\'' . $field1 . '\' AND \'' . $date1 . '\'<=p1.value';
|
|
||||||
$ret[] = $sql;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($sqlset[1])
|
|
||||||
{
|
|
||||||
if($field1 && $field2)
|
|
||||||
{
|
|
||||||
$sql = 'UPDATE (prop AS p1 INNER JOIN prop AS p2 USING(record_id))' .
|
|
||||||
' INNER JOIN record USING(record_id)' .
|
|
||||||
' SET ' . $sqlset[1] .
|
|
||||||
' WHERE (p1.name=\'' . $field1 . '\' AND \'' . $date1 . '\'>p1.value)' .
|
|
||||||
' AND (p2.name=\'' . $field2 . '\' AND \'' . $date2 . '\'<=p2.value)';
|
|
||||||
$ret[] = $sql;
|
|
||||||
}
|
|
||||||
elseif($field1)
|
|
||||||
{
|
|
||||||
$sql = 'UPDATE prop AS p1 INNER JOIN record USING(record_id)' .
|
|
||||||
' SET ' . $sqlset[1] .
|
|
||||||
' WHERE p1.name=\'' . $field1 . '\' AND \'' . $date1 . '\'>p1.value';
|
|
||||||
$ret[] = $sql;
|
|
||||||
}
|
|
||||||
elseif($field2)
|
|
||||||
{
|
|
||||||
$sql = 'UPDATE prop AS p2 INNER JOIN record USING(record_id)' .
|
|
||||||
' SET ' . $sqlset[1] .
|
|
||||||
' WHERE p2.name=\'' . $field2 . '\' AND \'' . $date2 . '\'<=p2.value';
|
|
||||||
$ret[] = $sql;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if($sqlset[2] && $field2)
|
|
||||||
{
|
|
||||||
$sql = 'UPDATE prop AS p2 INNER JOIN record USING(record_id)' .
|
|
||||||
' SET ' . $sqlset[2] .
|
|
||||||
' WHERE p2.name=\'' . $field2 . '\' AND \'' . $date2 . '\'>p2.value';
|
|
||||||
$ret[] = $sql;
|
|
||||||
}
|
|
||||||
|
|
||||||
return($ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function facility()
|
public function facility()
|
||||||
{
|
{
|
||||||
@@ -1232,9 +892,6 @@ class task_period_outofdate extends task_abstract
|
|||||||
);
|
);
|
||||||
|
|
||||||
phrasea::headers(200, true, 'application/json', 'UTF-8', false);
|
phrasea::headers(200, true, 'application/json', 'UTF-8', false);
|
||||||
// return("hello4");
|
|
||||||
//var_dump($parm2);
|
|
||||||
//return;
|
|
||||||
$ret = NULL;
|
$ret = NULL;
|
||||||
switch($parm2['ACT'])
|
switch($parm2['ACT'])
|
||||||
{
|
{
|
||||||
@@ -1281,6 +938,6 @@ class task_period_outofdate extends task_abstract
|
|||||||
}
|
}
|
||||||
print(json_encode($ret));
|
print(json_encode($ret));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@@ -107,21 +107,26 @@ switch ($parm['action'])
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'SETTASKSTATUS':
|
case 'SETTASKSTATUS':
|
||||||
$parm = $request->get_parms("task_id", "status");
|
$parm = $request->get_parms('task_id', 'status', 'signal');
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$task_manager = new task_manager($appbox);
|
$task_manager = new task_manager($appbox);
|
||||||
$task = $task_manager->get_task($parm['task_id']);
|
$task = $task_manager->get_task($parm['task_id']);
|
||||||
|
$pid = (int)($task->get_pid());
|
||||||
$task->set_status($parm["status"]);
|
$task->set_status($parm["status"]);
|
||||||
|
$signal = (int)($parm['signal']);
|
||||||
|
if( $signal > 0 && $pid )
|
||||||
|
posix_kill($pid, $signal);
|
||||||
}
|
}
|
||||||
catch (Exception $e)
|
catch (Exception $e)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
$output = json_encode($pid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'SETSCHEDSTATUS':
|
case 'SETSCHEDSTATUS':
|
||||||
$parm = $request->get_parms('status');
|
$parm = $request->get_parms('status', 'signal');
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$task_manager = new task_manager($appbox);
|
$task_manager = new task_manager($appbox);
|
||||||
@@ -132,13 +137,6 @@ switch ($parm['action'])
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
$ret = new DOMDocument("1.0", "UTF-8");
|
|
||||||
$ret->standalone = true;
|
|
||||||
$ret->preserveWhiteSpace = false;
|
|
||||||
$root = $ret->appendChild($ret->createElement("result"));
|
|
||||||
$root->appendChild($ret->createCDATASection(var_export($parm, true)));
|
|
||||||
|
|
||||||
$output = $ret->saveXML();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'RESETTASKCRASHCOUNTER':
|
case 'RESETTASKCRASHCOUNTER':
|
||||||
@@ -267,7 +265,6 @@ switch ($parm['action'])
|
|||||||
$ret['tasks'] = array();
|
$ret['tasks'] = array();
|
||||||
foreach ($task_manager->get_tasks(true) as $task)
|
foreach ($task_manager->get_tasks(true) as $task)
|
||||||
{
|
{
|
||||||
// var_dump($task);
|
|
||||||
$_t = array(
|
$_t = array(
|
||||||
'id'=>$task->get_task_id()
|
'id'=>$task->get_task_id()
|
||||||
, 'pid' =>$task->get_pid()
|
, 'pid' =>$task->get_pid()
|
||||||
@@ -278,8 +275,22 @@ switch ($parm['action'])
|
|||||||
$ret['tasks'][$_t['id']] = $_t;
|
$ret['tasks'][$_t['id']] = $_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = json_encode($ret);
|
if(1)
|
||||||
|
{
|
||||||
|
$sql = 'SHOW PROCESSLIST';
|
||||||
|
$stmt = $appbox->get_connection()->prepare($sql);
|
||||||
|
$stmt->execute();
|
||||||
|
$rows = $stmt->fetchALL(PDO::FETCH_ASSOC);
|
||||||
|
$stmt->closeCursor();
|
||||||
|
$ret['db_processlist'] = array();
|
||||||
|
foreach($rows as $row)
|
||||||
|
{
|
||||||
|
if($row['Info'] != $sql)
|
||||||
|
$ret['db_processlist'][] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = json_encode($ret);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'UNMOUNTBASE':
|
case 'UNMOUNTBASE':
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||||
* @link www.phraseanet.com
|
* @link www.phraseanet.com
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once dirname(__FILE__) . "/../../lib/bootstrap.php";
|
require_once dirname(__FILE__) . "/../../lib/bootstrap.php";
|
||||||
|
|
||||||
$appbox = appbox::get_instance();
|
$appbox = appbox::get_instance();
|
||||||
@@ -52,31 +53,35 @@ $logdir = p4string::addEndSlash($registry->get('GV_RootPath') . 'logs');
|
|||||||
|
|
||||||
$phpcli = $registry->get('GV_cli');
|
$phpcli = $registry->get('GV_cli');
|
||||||
|
|
||||||
|
$nullfile = '';
|
||||||
switch ($system)
|
switch ($system)
|
||||||
{
|
{
|
||||||
case "DARWIN":
|
case "DARWIN":
|
||||||
$cmd = $phpcli . ' -f ' . $registry->get('GV_RootPath') . "bin/console scheduler:start";
|
$cmd = $phpcli . ' -f ' . $registry->get('GV_RootPath') . "bin/console scheduler:start";
|
||||||
|
$nullfile = '/dev/null';
|
||||||
break;
|
break;
|
||||||
case "LINUX":
|
case "LINUX":
|
||||||
$cmd = $phpcli . ' -f ' . $registry->get('GV_RootPath') . "bin/console scheduler:start";
|
$cmd = $phpcli . ' -f ' . $registry->get('GV_RootPath') . "bin/console scheduler:start";
|
||||||
|
$nullfile = '/dev/null';
|
||||||
break;
|
break;
|
||||||
case "WINDOWS":
|
case "WINDOWS":
|
||||||
case "WINDOWS NT":
|
case "WINDOWS NT":
|
||||||
$cmd = $phpcli . ' -f ' . $registry->get('GV_RootPath') . "bin/console scheduler:start";
|
$cmd = $phpcli . ' -f ' . $registry->get('GV_RootPath') . "bin/console scheduler:start";
|
||||||
|
$nullfile = 'NUL';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($logdir)
|
//if ($logdir)
|
||||||
{
|
//{
|
||||||
$descriptors[1] = array("file", $logdir . "scheduler.log", "a+");
|
// $descriptors[1] = array("file", $logdir . "scheduler.log", "a+");
|
||||||
$descriptors[2] = array("file", $logdir . "scheduler.error.log", "a+");
|
// $descriptors[2] = array("file", $logdir . "scheduler.error.log", "a+");
|
||||||
}
|
//}
|
||||||
else
|
//else
|
||||||
{
|
//{
|
||||||
$descriptors[1] = array("file", "NUL", "a+");
|
$descriptors[1] = array("file", $nullfile, "a+");
|
||||||
$descriptors[2] = array("file", "NUL", "a+");
|
$descriptors[2] = array("file", $nullfile, "a+");
|
||||||
}
|
//}
|
||||||
|
|
||||||
$pipes = null;
|
$pipes = null;
|
||||||
$cwd = $registry->get('GV_RootPath') . "bin/";
|
$cwd = $registry->get('GV_RootPath') . "bin/";
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of Phraseanet
|
* This file is part of Phraseanet
|
||||||
*
|
*
|
||||||
@@ -20,30 +19,74 @@ $appbox = appbox::get_instance();
|
|||||||
$session = $appbox->get_session();
|
$session = $appbox->get_session();
|
||||||
|
|
||||||
$request = http_request::getInstance();
|
$request = http_request::getInstance();
|
||||||
$parm = $request->get_parms('fil', 'act');
|
$parm = $request->get_parms('fil', 'log', 'id', 'act');
|
||||||
|
?>
|
||||||
$registry = $appbox->get_registry();
|
<html lang="<?php echo($session->get_I18n()); ?>">
|
||||||
$logdir = p4string::addEndSlash($registry->get('GV_RootPath') . 'logs');
|
<head>
|
||||||
$logfile = $logdir . $parm['fil'];
|
<style>
|
||||||
|
* {font-family: monospace}
|
||||||
if (file_exists($logfile))
|
BODY {margin: 0px; padding: 0px}
|
||||||
|
H1 { font-size: 18px; background-color:#CCCCCC; padding: 0px}
|
||||||
|
A { padding: 3px; color: #000000 }
|
||||||
|
A.current {background-color: #ffffff}
|
||||||
|
PRE {padding-left: 3px; padding-right: 3px}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>
|
||||||
|
logfile :
|
||||||
|
<?php
|
||||||
|
foreach(array('l' => 'log', 'o' => 'stdout', 'e' => 'stderr') as $k => $v)
|
||||||
{
|
{
|
||||||
if ($parm['act'] == 'CLR')
|
$cls = '';
|
||||||
|
if($k == $parm['log'])
|
||||||
|
$cls = 'current';
|
||||||
|
printf("<a class=\"%s\" href=\"/admin/showlogtask.php?fil=%s&log=%s&id=%s\">(%s)</a>\n"
|
||||||
|
, $cls
|
||||||
|
, urlencode($parm['fil'])
|
||||||
|
, urlencode($k)
|
||||||
|
, urlencode($parm['id'])
|
||||||
|
, $v);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</h1>
|
||||||
|
<?php
|
||||||
|
$registry = $appbox->get_registry();
|
||||||
|
$logdir = p4string::addEndSlash($registry->get('GV_RootPath') . 'logs');
|
||||||
|
$logfile = $logdir . $parm['fil'];
|
||||||
|
if($parm['log'])
|
||||||
|
$logfile .= '_' . $parm['log'];
|
||||||
|
if($parm['id'])
|
||||||
|
$logfile .= '_' . $parm['id'];
|
||||||
|
$logfile .= '.log';
|
||||||
|
|
||||||
|
if(file_exists($logfile))
|
||||||
|
{
|
||||||
|
if($parm['act'] == 'CLR')
|
||||||
{
|
{
|
||||||
file_put_contents($logfile, '');
|
file_put_contents($logfile, '');
|
||||||
|
return phrasea::redirect(sprintf("/admin/showlogtask.php?fil=%s&log=%s&id=%s"
|
||||||
return phrasea::redirect("/admin/showlogtask.php?fil=" . urlencode($parm['fil']));
|
, urlencode($parm['fil'])
|
||||||
|
, urlencode($parm['log'])
|
||||||
|
, urlencode($parm['id']))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("<html lang=\"" . $session->get_I18n() . "\"><body><h4>%s <a href=\"showlogtask.php?fil=%s&act=CLR\">effacer</a></h4>\n", $logfile, urlencode($parm['fil']));
|
printf("<h4>%s\n", $logfile);
|
||||||
print("<pre>\n");
|
printf(" <a href=\"/admin/showlogtask.php?fil=%s&log=%s&id=%s&act=CLR\">effacer</a>\n"
|
||||||
|
, urlencode($parm['fil'])
|
||||||
|
, urlencode($parm['log'])
|
||||||
|
, urlencode($parm['id']));
|
||||||
|
print("</h4>\n<pre>\n");
|
||||||
print(htmlentities(file_get_contents($logfile)));
|
print(htmlentities(file_get_contents($logfile)));
|
||||||
print("</pre>\n</body></html>");
|
print("</pre>\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("file <b>%s</b> does not exists\n", $logfile);
|
printf("<h4>file <b>%s</b> does not exists</h4>\n", $logfile);
|
||||||
}
|
}
|
||||||
|
?>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
@@ -30,12 +30,32 @@ if(!$user->ACL()->has_right('taskmanager'))
|
|||||||
|
|
||||||
phrasea::headers();
|
phrasea::headers();
|
||||||
$registry = $appbox->get_registry();
|
$registry = $appbox->get_registry();
|
||||||
|
|
||||||
$task_manager = new task_manager($appbox);
|
$task_manager = new task_manager($appbox);
|
||||||
|
|
||||||
|
$refresh_tasklist = false;
|
||||||
|
if($parm["act"] == "DELETETASK")
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$task = $task_manager->get_task($parm['tid']);
|
||||||
|
$task->delete();
|
||||||
|
$refresh_tasklist = true;
|
||||||
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html lang="<?php echo $session->get_I18n(); ?>">
|
<html lang="<?php echo $session->get_I18n(); ?>">
|
||||||
<head>
|
<head>
|
||||||
|
|
||||||
<link type="text/css" rel="stylesheet" href="/include/minify/f=skins/common/main.css,skins/admin/admincolor.css" />
|
<link type="text/css" rel="stylesheet" href="/include/minify/f=skins/common/main.css,skins/admin/admincolor.css" />
|
||||||
|
<link rel="stylesheet" href="/include/minify/f=include/jslibs/jquery.contextmenu.css,include/jslibs/jquery-ui-1.8.12/css/ui-lightness/jquery-ui-1.8.12.custom.css" type="text/css" media="screen" />
|
||||||
<style>
|
<style>
|
||||||
.divTop
|
.divTop
|
||||||
{
|
{
|
||||||
@@ -45,10 +65,38 @@ $task_manager = new task_manager($appbox);
|
|||||||
#redbox0 table{
|
#redbox0 table{
|
||||||
font-size:10px;
|
font-size:10px;
|
||||||
text-align:center;
|
text-align:center;
|
||||||
|
table-layout: fixed;
|
||||||
|
}
|
||||||
|
table.task_manager {
|
||||||
|
border: 1px solid #e0e0e0;
|
||||||
|
border-collapse: collapse;
|
||||||
|
table-layout: fixed;
|
||||||
|
}
|
||||||
|
table.task_manager tr {
|
||||||
|
height:auto;
|
||||||
|
}
|
||||||
|
table.task_manager th, table.task_manager td {
|
||||||
|
height:auto;
|
||||||
|
padding: 2px;
|
||||||
|
margin: 0px;
|
||||||
|
border: 1px solid #e0e0e0;
|
||||||
|
padding-left: 5px;
|
||||||
|
padding-right: 5px;
|
||||||
|
}
|
||||||
|
#db_processlist table {
|
||||||
|
border: 1px solid #e0e0e0;
|
||||||
|
border-collapse: collapse;
|
||||||
|
table-layout: fixed;
|
||||||
|
}
|
||||||
|
#db_processlist table th, table td {
|
||||||
|
height:auto;
|
||||||
|
padding: 2px;
|
||||||
|
margin: 0px;
|
||||||
|
border: 1px solid #e0e0e0;
|
||||||
|
padding-left: 5px;
|
||||||
|
padding-right: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
<link rel="stylesheet" href="/include/minify/f=include/jslibs/jquery.contextmenu.css,include/jslibs/jquery-ui-1.8.12/css/ui-lightness/jquery-ui-1.8.12.custom.css" type="text/css" media="screen" />
|
|
||||||
<script type="text/javascript" src="/include/minify/f=include/jslibs/jquery-1.5.2.js,include/jslibs/jquery-ui-1.8.12/development-bundle/ui/i18n/jquery-ui-i18n.js,include/jslibs/jquery.contextmenu.js"></script>
|
<script type="text/javascript" src="/include/minify/f=include/jslibs/jquery-1.5.2.js,include/jslibs/jquery-ui-1.8.12/development-bundle/ui/i18n/jquery-ui-i18n.js,include/jslibs/jquery.contextmenu.js"></script>
|
||||||
<script type="text/javascript" src="/include/jslibs/jquery-ui-1.8.12/js/jquery-ui-1.8.12.custom.min.js"></script>
|
<script type="text/javascript" src="/include/jslibs/jquery-ui-1.8.12/js/jquery-ui-1.8.12.custom.min.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@@ -67,8 +115,6 @@ $task_manager = new task_manager($appbox);
|
|||||||
$("#redbox1").width = ($("#tableau_center").width()-4);
|
$("#redbox1").width = ($("#tableau_center").width()-4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function newTask(tclass)
|
function newTask(tclass)
|
||||||
{
|
{
|
||||||
document.forms["task"].target = "";
|
document.forms["task"].target = "";
|
||||||
@@ -88,7 +134,7 @@ $task_manager = new task_manager($appbox);
|
|||||||
setSchedStatus('tostop');
|
setSchedStatus('tostop');
|
||||||
break;
|
break;
|
||||||
case "log":
|
case "log":
|
||||||
window.open("/admin/showlogtask.php?fil=<?php echo urlencode('scheduler.log') ?>", "SCHEDLOG");
|
window.open("/admin/showlogtask.php?fil=scheduler&log=l", "scheduler.log");
|
||||||
break;
|
break;
|
||||||
case "preferences":
|
case "preferences":
|
||||||
preferencesScheduler();
|
preferencesScheduler();
|
||||||
@@ -96,7 +142,6 @@ $task_manager = new task_manager($appbox);
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function doMenuTask(context, act)
|
function doMenuTask(context, act)
|
||||||
{
|
{
|
||||||
var tid = $(context).parent().attr('id').split('_').pop();
|
var tid = $(context).parent().attr('id').split('_').pop();
|
||||||
@@ -107,47 +152,12 @@ $task_manager = new task_manager($appbox);
|
|||||||
editTask(tid);
|
editTask(tid);
|
||||||
break;
|
break;
|
||||||
case "start":
|
case "start":
|
||||||
setTaskStatus(tid, 'tostart', true); // true : reset crash counter
|
setTaskStatus(tid, 'tostart', null, true); // null:no signal, true : reset crash counter
|
||||||
break;
|
break;
|
||||||
case "stop":
|
case "stop":
|
||||||
setTaskStatus(tid, 'tostop', false);
|
setTaskStatus(tid, 'tostop', 15, false); // 15 = SIGTERM
|
||||||
break;
|
break;
|
||||||
/*
|
|
||||||
case "fix":
|
|
||||||
switch(T_task[tid])
|
|
||||||
{
|
|
||||||
case "started_0":
|
|
||||||
case "starting_0":
|
|
||||||
case "stopping_0":
|
|
||||||
case "tostart_0":
|
|
||||||
case "tostop_0":
|
|
||||||
case "manual_0":
|
|
||||||
setTaskStatus(tid, 'stopped');
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "stopped_1":
|
|
||||||
case "starting_1":
|
|
||||||
case "stopping_1":
|
|
||||||
case "tostart_1":
|
|
||||||
case "tostop_1":
|
|
||||||
// case "manual_1":
|
|
||||||
// case "torestart_1":
|
|
||||||
setTaskStatus(tid, 'started');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
*/
|
|
||||||
case 'delete':
|
case 'delete':
|
||||||
switch(T_task[tid])
|
|
||||||
{
|
|
||||||
case "stopped_0":
|
|
||||||
case "started_0":
|
|
||||||
case "starting_0":
|
|
||||||
case "stopping_0":
|
|
||||||
case "tostart_0":
|
|
||||||
case "tostop_0":
|
|
||||||
case "manual_0":
|
|
||||||
case "torestart_0":
|
|
||||||
if(confirm("<?php echo p4string::MakeString(_('admin::tasks: supprimer la tache ?'), 'js', '"') ?>"))
|
if(confirm("<?php echo p4string::MakeString(_('admin::tasks: supprimer la tache ?'), 'js', '"') ?>"))
|
||||||
{
|
{
|
||||||
document.forms["taskManager"].target = "";
|
document.forms["taskManager"].target = "";
|
||||||
@@ -156,10 +166,8 @@ $task_manager = new task_manager($appbox);
|
|||||||
document.forms["taskManager"].submit();
|
document.forms["taskManager"].submit();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "log":
|
case "log":
|
||||||
window.open("/admin/showlogtask.php?fil=<?php echo urlencode('task_t_') ?>"+tid+"%2Elog", "TASKLOG_"+tid);
|
window.open("/admin/showlogtask.php?fil=task&id="+tid+"&log=l", "task_"+tid+".log");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -368,40 +376,24 @@ foreach($tasks as $t)
|
|||||||
|
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
if($parm["act"] == "DELETETASK")
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
$task = $task_manager->get_task($parm['tid']);
|
|
||||||
$task->delete();
|
|
||||||
}
|
|
||||||
catch(Exception $e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
<iframe id="zsched" src="about:blank" style="position:absolute; top:0px; left:0px; width:50px; height:50px; visibility:hidden"></iframe>
|
<iframe id="zsched" src="about:blank" style="position:absolute; top:0px; left:0px; width:50px; height:50px; visibility:hidden"></iframe>
|
||||||
|
|
||||||
<h1><?php echo _('admin::tasks: planificateur de taches') ?></h1>
|
<h1><?php echo _('admin::tasks: planificateur de taches') ?>
|
||||||
|
<span style="font-size:12px;">
|
||||||
<form method="post" name="taskManager" action="/admin/taskmanager.php" target="???" onsubmit="return(false);" >
|
|
||||||
<input type="hidden" name="act" value="" />
|
|
||||||
<input type="hidden" name="tid" value="" />
|
|
||||||
<input type="hidden" name="att" value="" />
|
|
||||||
</form>
|
|
||||||
<p>
|
|
||||||
<?php echo sprintf(_('Last update at %s.'), '<span id="pingTime"></span>'); ?>
|
<?php echo sprintf(_('Last update at %s.'), '<span id="pingTime"></span>'); ?>
|
||||||
<a id="newTaskButton" href="#"><?php echo _('admin::tasks: Nouvelle tache') ?></a>
|
</span>
|
||||||
</p>
|
</h1>
|
||||||
|
|
||||||
<table class="admintable task_manager" cellpadding="0" cellSpacing="0">
|
<table class="admintable task_manager" cellpadding="0" cellSpacing="0">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th style="width:20px;"></th>
|
<th style="width:20px;"></th>
|
||||||
<th style="width:40px;">ID</th>
|
<th style="text-align:center; width:40px;">ID</th>
|
||||||
<th style="width:80px;"><?php echo _('admin::tasks: statut de la tache') ?></th>
|
<th style="text-align:center; width:30px;">!</th>
|
||||||
<th style="width:60px;"><?php echo _('admin::tasks: process_id de la tache') ?></th>
|
<th style="text-align:center; width:80px;"><?php echo _('admin::tasks: statut de la tache') ?></th>
|
||||||
<th style="width:120px;"><?php echo _('admin::tasks: etat de progression de la tache') ?></th>
|
<th style="text-align:center; width:60px;"><?php echo _('admin::tasks: process_id de la tache') ?></th>
|
||||||
|
<th style="text-align:center; width:120px;"><?php echo _('admin::tasks: etat de progression de la tache') ?></th>
|
||||||
<th style="width:auto;"><?php echo _('admin::tasks: nom de la tache') ?></th>
|
<th style="width:auto;"><?php echo _('admin::tasks: nom de la tache') ?></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -411,23 +403,15 @@ foreach($tasks as $t)
|
|||||||
<img src="/skins/admin/dropdown.png"/>
|
<img src="/skins/admin/dropdown.png"/>
|
||||||
</td>
|
</td>
|
||||||
<td> </td>
|
<td> </td>
|
||||||
|
<td> </td>
|
||||||
<td style="text-align:center" id="STATUS_SCHED">
|
<td style="text-align:center" id="STATUS_SCHED"></td>
|
||||||
<img id="STATUSIMG_SCHED" style="display:none;" />
|
|
||||||
<img id='WARNING_SCHED' style='display:none' src="/skins/icons/alert.png" alt="" />
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td id="PID_SCHED" style="text-align:center;"> </td>
|
<td id="PID_SCHED" style="text-align:center;"> </td>
|
||||||
|
<td> </td>
|
||||||
<td>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td style="font-weight:900" class="taskname">TaskManager</td>
|
<td style="font-weight:900" class="taskname">TaskManager</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
$n = 0;
|
$n = 0;
|
||||||
foreach($task_manager->get_tasks() as $task)
|
foreach($task_manager->get_tasks($refresh_tasklist) as $task)
|
||||||
{
|
{
|
||||||
$n++;
|
$n++;
|
||||||
$tid = $task->get_task_id()
|
$tid = $task->get_task_id()
|
||||||
@@ -437,29 +421,40 @@ foreach($tasks as $t)
|
|||||||
<img src="/skins/admin/dropdown.png"/>
|
<img src="/skins/admin/dropdown.png"/>
|
||||||
</td>
|
</td>
|
||||||
<td style="text-align:center; font-weight:900"><?php echo $tid ?></td>
|
<td style="text-align:center; font-weight:900"><?php echo $tid ?></td>
|
||||||
|
<td style="text-align:center"><img id="WARNING_<?php echo $tid ?>" src="/skins/icons/alert.png" title="" style="display:none;"/></td>
|
||||||
<td style="text-align:center" id="STATUS_<?php echo $tid ?>">
|
<td style="text-align:center" id="STATUS_<?php echo $tid ?>"></td>
|
||||||
<img id="STATUSIMG_<?php echo $tid ?>" style="display:none;" />
|
<td style="text-align:center" id="PID_<?php echo $tid ?>"> </td>
|
||||||
<img id='WARNING_<?php echo $tid ?>' style='display:none' src="/skins/icons/alert.png" alt="" />
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td id="PID_<?php echo $tid ?>" style="text-align:center;width:60px;"> </td>
|
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
<div id="COMPBOX_<?php echo $tid ?>" style="position:relative; top:1px; left:5px; width:110px; height:5px; background-color:#787878">
|
<div style="position:relative; top:0px; left:0px; right:0px;" >
|
||||||
|
<div id="COMPBOX_<?php echo $tid ?>" style="position:absolute; top:1px; left:3px; right:3px; height:5px; background-color:#787878">
|
||||||
<div id="COMP_<?php echo $tid ?>" style="position:absolute; top:1px; left:0px; width:0%; height:3px; background-color:#FFFF80">
|
<div id="COMP_<?php echo $tid ?>" style="position:absolute; top:1px; left:0px; width:0%; height:3px; background-color:#FFFF80">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
<td class="taskname"><?php echo p4string::MakeString($task->get_title()) ?> [<?php echo p4string::MakeString($task::getName()) ?>]</td>
|
||||||
<td style="width:auto" class="taskname"><?php echo p4string::MakeString($task->get_title()) ?> [<?php echo p4string::MakeString($task::getName()) ?>]</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
// $i = 1 - $i;
|
|
||||||
}
|
}
|
||||||
?> </tbody>
|
?>
|
||||||
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<td class="dropdown scheduler">
|
||||||
|
<img id="newTaskButton" src="/skins/admin/dropdown.png"/>
|
||||||
|
</td>
|
||||||
|
<td colspan="6">
|
||||||
|
<?php echo _('admin::tasks: Nouvelle tache') ?>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<div id="db_processlist"></div>
|
||||||
|
<!--
|
||||||
|
<a id="newTaskButton" href="#"><?php echo _('admin::tasks: Nouvelle tache') ?></a>
|
||||||
|
-->
|
||||||
|
|
||||||
<?php ?>
|
<?php ?>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
@@ -471,7 +466,7 @@ foreach($tasks as $t)
|
|||||||
document.forms["task"].submit();
|
document.forms["task"].submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setTaskStatus(tid, status, resetCrashCounter)
|
function setTaskStatus(tid, status, signal, resetCrashCounter)
|
||||||
{
|
{
|
||||||
if(resetCrashCounter)
|
if(resetCrashCounter)
|
||||||
{
|
{
|
||||||
@@ -487,8 +482,8 @@ foreach($tasks as $t)
|
|||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/admin/adminFeedback.php",
|
url: "/admin/adminFeedback.php",
|
||||||
data : {task_id:tid, action:"SETTASKSTATUS", status:status},
|
data : {task_id:tid, action:"SETTASKSTATUS", status:status, signal:signal},
|
||||||
dataType:'xml',
|
dataType:'json',
|
||||||
success: function(ret)
|
success: function(ret)
|
||||||
{
|
{
|
||||||
pingScheduler(false); // false : just one time
|
pingScheduler(false); // false : just one time
|
||||||
@@ -502,7 +497,7 @@ foreach($tasks as $t)
|
|||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/admin/adminFeedback.php",
|
url: "/admin/adminFeedback.php",
|
||||||
data : { action:"SETSCHEDSTATUS", status:status },
|
data : { action:"SETSCHEDSTATUS", status:status },
|
||||||
dataType:'xml',
|
dataType:'json',
|
||||||
success: function(ret)
|
success: function(ret)
|
||||||
{
|
{
|
||||||
pingScheduler(false); // false : just one time
|
pingScheduler(false); // false : just one time
|
||||||
@@ -704,6 +699,16 @@ foreach($tasks as $t)
|
|||||||
else
|
else
|
||||||
$("#PID_"+id).html('-');
|
$("#PID_"+id).html('-');
|
||||||
|
|
||||||
|
if(ret.tasks[id].crashed)
|
||||||
|
{
|
||||||
|
// $("#WARNING_"+id).show().setAttribute("src", "/skins/icons/alert.png");
|
||||||
|
$("#WARNING_"+id).show().attr("title", "crashed "+ret.tasks[id].crashed+" times");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$("#WARNING_"+id).hide();
|
||||||
|
}
|
||||||
|
|
||||||
if(ret.tasks[id].completed && ret.tasks[id].completed>0 && ret.tasks[id].completed<=100)
|
if(ret.tasks[id].completed && ret.tasks[id].completed>0 && ret.tasks[id].completed<=100)
|
||||||
{
|
{
|
||||||
$("#COMP_"+id).width(ret.tasks[id].completed + "%");
|
$("#COMP_"+id).width(ret.tasks[id].completed + "%");
|
||||||
@@ -716,14 +721,30 @@ foreach($tasks as $t)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(ret.db_processlist)
|
||||||
|
{
|
||||||
|
var _table = document.createElement('table');
|
||||||
|
for(p in ret.db_processlist)
|
||||||
|
{
|
||||||
|
if(p==0)
|
||||||
|
{
|
||||||
|
var _tr = _table.appendChild(document.createElement('tr'));
|
||||||
|
for(c in ret.db_processlist[p])
|
||||||
|
_tr.appendChild(document.createElement('th')).appendChild(document.createTextNode(c));
|
||||||
|
}
|
||||||
|
var _tr = _table.appendChild(document.createElement('tr'));
|
||||||
|
for(c in ret.db_processlist[p])
|
||||||
|
_tr.appendChild(document.createElement('td')).appendChild(document.createTextNode(ret.db_processlist[p][c]));
|
||||||
|
}
|
||||||
|
$("#db_processlist").html(_table);
|
||||||
|
}
|
||||||
if(repeat)
|
if(repeat)
|
||||||
self.setTimeout("pingScheduler(true);", 1000);
|
self.setTimeout("pingScheduler(true);", 1000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function lauchScheduler()
|
function lauchScheduler()
|
||||||
{
|
{
|
||||||
url = "./runscheduler.php";
|
url = "./runscheduler.php";
|
||||||
@@ -734,11 +755,15 @@ foreach($tasks as $t)
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div id="scheduler-preferences" style="display:none;" title="<?php echo _('Preferences du TaskManager'); ?>">
|
<div id="scheduler-preferences" style="display:none;" title="<?php echo _('Preferences du TaskManager'); ?>">
|
||||||
|
|
||||||
<div style="margin:5px 0;"><span><?php echo _('Cette URL vous permet de controler le sheduler depuis un manager comme cron') ?></span></div>
|
<div style="margin:5px 0;"><span><?php echo _('Cette URL vous permet de controler le sheduler depuis un manager comme cron') ?></span></div>
|
||||||
<div style="margin:5px 0;"><input id="scheduler_key" style="width:100%;" type="text" readonly="readonly" value="<?php echo $registry->get('GV_ServerName') ?>admin/runscheduler.php?key=<?php echo phrasea::scheduler_key(); ?>" /></div>
|
<div style="margin:5px 0;"><input id="scheduler_key" style="width:100%;" type="text" readonly="readonly" value="<?php echo $registry->get('GV_ServerName') ?>admin/runscheduler.php?key=<?php echo phrasea::scheduler_key(); ?>" /></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<form method="post" name="taskManager" action="/admin/taskmanager.php" target="???" onsubmit="return(false);" >
|
||||||
|
<input type="hidden" name="act" value="" />
|
||||||
|
<input type="hidden" name="tid" value="" />
|
||||||
|
<input type="hidden" name="att" value="" />
|
||||||
|
</form>
|
||||||
<form method="post" name="task" action="/admin/task2.php" target="???" onsubmit="return(false);">
|
<form method="post" name="task" action="/admin/task2.php" target="???" onsubmit="return(false);">
|
||||||
<input type="hidden" name="act" value="???" />
|
<input type="hidden" name="act" value="???" />
|
||||||
<input type="hidden" name="tid" value="" />
|
<input type="hidden" name="tid" value="" />
|
||||||
|
Reference in New Issue
Block a user