mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
Switch task manager logging to monolog
This commit is contained in:
@@ -26,25 +26,18 @@ class task_Scheduler
|
||||
|
||||
const ERR_ALREADY_RUNNING = 114; // aka EALREADY (Operation already in progress)
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Monolog\Logger
|
||||
*/
|
||||
private $logger;
|
||||
private $method;
|
||||
private $input;
|
||||
protected $output;
|
||||
|
||||
protected function log($message)
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
$logdir = $registry->get('GV_RootPath') . 'logs/';
|
||||
|
||||
logs::rotate($logdir . "scheduler_l.log");
|
||||
logs::rotate($logdir . "scheduler_o.log");
|
||||
logs::rotate($logdir . "scheduler_e.log");
|
||||
|
||||
$date_obj = new DateTime();
|
||||
$message = sprintf("%s\t%s", $date_obj->format(DATE_ATOM), $message);
|
||||
|
||||
if ($this->input && ! ($this->input->getOption('nolog'))) {
|
||||
file_put_contents($logdir . "scheduler_l.log", $message . "\n", FILE_APPEND);
|
||||
}
|
||||
$this->logger->addInfo($message);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -58,11 +51,10 @@ class task_Scheduler
|
||||
* @throws Exception if scheduler is already running
|
||||
* @todo doc all possible exception
|
||||
*/
|
||||
public function run(InputInterface $input = null, OutputInterface $output = null)
|
||||
public function run(\Monolog\Logger $logger)
|
||||
{
|
||||
require_once dirname(__FILE__) . '/../../bootstrap.php';
|
||||
$this->input = $input;
|
||||
$this->output = $output;
|
||||
$this->logger = $logger;
|
||||
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$registry = $appbox->get_registry();
|
||||
|
||||
@@ -119,8 +111,6 @@ class task_Scheduler
|
||||
pcntl_signal(SIGCHLD, SIG_IGN);
|
||||
}
|
||||
|
||||
$logdir = $registry->get('GV_RootPath') . 'logs/';
|
||||
|
||||
$conn = appbox::get_instance(\bootstrap::getCore())->get_connection();
|
||||
|
||||
$taskPoll = array(); // the poll of tasks
|
||||
@@ -216,10 +206,6 @@ class task_Scheduler
|
||||
$this->log("schedstatus == 'stopping', waiting tasks to end");
|
||||
}
|
||||
|
||||
logs::rotate($logdir . "scheduler_t.log");
|
||||
logs::rotate($logdir . "scheduler_o.log");
|
||||
logs::rotate($logdir . "scheduler_e.log");
|
||||
|
||||
// initialy, all tasks are supposed to be removed from the poll
|
||||
foreach ($taskPoll as $tkey => $task) {
|
||||
$taskPoll[$tkey]["todel"] = true;
|
||||
@@ -229,10 +215,6 @@ class task_Scheduler
|
||||
$tkey = "t_" . $task->getID();
|
||||
$status = $task->getState();
|
||||
|
||||
logs::rotate($logdir . "task_t_" . $task->getID() . ".log");
|
||||
logs::rotate($logdir . "task_o_" . $task->getID() . ".log");
|
||||
logs::rotate($logdir . "task_e_" . $task->getID() . ".log");
|
||||
|
||||
if ( ! isset($taskPoll[$tkey])) {
|
||||
// the task is not in the poll, add it
|
||||
$phpcli = $registry->get('GV_cli');
|
||||
@@ -240,18 +222,12 @@ class task_Scheduler
|
||||
case "WINDOWS":
|
||||
$cmd = $phpcli;
|
||||
$args = array('-f', $registry->get('GV_RootPath') . 'bin/console', '--', '-q', 'task:run', $task->getID(), '--runner=scheduler');
|
||||
if ($this->input && ($this->input->getOption('notasklog'))) {
|
||||
$args[] = 'notasklog';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
case "DARWIN":
|
||||
case "LINUX":
|
||||
$cmd = $phpcli;
|
||||
$args = array('-f', $registry->get('GV_RootPath') . 'bin/console', '--', '-q', 'task:run', $task->getID(), '--runner=scheduler');
|
||||
if ($this->input && ($this->input->getOption('notasklog'))) {
|
||||
$args[] = 'notasklog';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -344,8 +320,10 @@ class task_Scheduler
|
||||
|
||||
if ($this->method == self::METHOD_PROC_OPEN) {
|
||||
if ( ! $taskPoll[$tkey]["process"]) {
|
||||
$descriptors[1] = array('file', $logdir . "task_o_" . $taskPoll[$tkey]['task']->getID() . ".log", 'a+');
|
||||
$descriptors[2] = array('file', $logdir . "task_e_" . $taskPoll[$tkey]['task']->getID() . ".log", 'a+');
|
||||
$tmpFile = tempnam(sys_get_temp_dir(), 'task');
|
||||
|
||||
$descriptors[1] = array('file', $tmpFile, 'a+');
|
||||
$descriptors[2] = array('file', $tmpFile, 'a+');
|
||||
|
||||
$taskPoll[$tkey]["process"] = proc_open(
|
||||
$taskPoll[$tkey]["cmd"] . ' ' . implode(' ', $taskPoll[$tkey]["args"])
|
||||
|
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Monolog\Logger;
|
||||
|
||||
abstract class task_abstract
|
||||
{
|
||||
const LAUCHED_BY_BROWSER = 1;
|
||||
@@ -19,6 +21,11 @@ abstract class task_abstract
|
||||
const SIGNAL_SCHEDULER_DIED = 'SIGNAL_SCHEDULER_DIED';
|
||||
const ERR_ALREADY_RUNNING = 114; // aka EALREADY (Operation already in progress)
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Logger
|
||||
*/
|
||||
protected $logger;
|
||||
protected $suicidable = false;
|
||||
protected $launched_by = 0;
|
||||
|
||||
@@ -113,7 +120,7 @@ abstract class task_abstract
|
||||
return $row['status'];
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* to be overwritten by tasks : echo text to be included in <head> in task interface
|
||||
*/
|
||||
public function printInterfaceHEAD()
|
||||
@@ -121,7 +128,7 @@ abstract class task_abstract
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* to be overwritten by tasks : echo javascript to be included in <head> in task interface
|
||||
*/
|
||||
public function printInterfaceJS()
|
||||
@@ -139,9 +146,9 @@ abstract class task_abstract
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getGraphicForm()
|
||||
{
|
||||
return false;
|
||||
@@ -489,10 +496,9 @@ abstract class task_abstract
|
||||
return $lockFD;
|
||||
}
|
||||
|
||||
final public function run($runner, $input = null, $output = null)
|
||||
final public function run($runner, $logger)
|
||||
{
|
||||
$this->input = $input;
|
||||
$this->output = $output;
|
||||
$this->logger = $logger;
|
||||
|
||||
$lockFD = $this->lockTask();
|
||||
|
||||
@@ -503,7 +509,7 @@ abstract class task_abstract
|
||||
$exception = NULL;
|
||||
try {
|
||||
$this->run2();
|
||||
} catch (Exception $exception) {
|
||||
} catch (\Exception $exception) {
|
||||
|
||||
}
|
||||
|
||||
@@ -669,27 +675,12 @@ abstract class task_abstract
|
||||
$d = debug_backtrace(false);
|
||||
|
||||
$lastt = $t;
|
||||
echo "\n" . memory_get_usage() . " -- " . memory_get_usage(true) . "\n";
|
||||
$this->logger->addDebug(memory_get_usage() . " -- " . memory_get_usage(true));
|
||||
}
|
||||
|
||||
public function log($message)
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
$logdir = $registry->get('GV_RootPath') . 'logs/';
|
||||
|
||||
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);
|
||||
}
|
||||
$this->logger->addInfo($message);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
Reference in New Issue
Block a user