mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00
syslog + maillog in task / task-manager as service
fix task interfaces / cleanup fix tests using task manager
This commit is contained in:
@@ -22,6 +22,27 @@ abstract class task_abstract
|
||||
const SIGNAL_SCHEDULER_DIED = 'SIGNAL_SCHEDULER_DIED';
|
||||
const ERR_ALREADY_RUNNING = 114; // aka EALREADY (Operation already in progress)
|
||||
|
||||
// default min/max values for the 'restart task every n records' setting on tasks
|
||||
const MINRECS = 10;
|
||||
const MAXRECS = 100;
|
||||
// default min/max values for the 'overflow memory (Mo)' setting on tasks
|
||||
const MINMEGS = 20;
|
||||
const MAXMEGS = 256;
|
||||
// default min/max values for the 'period (seconds)' setting on tasks
|
||||
const MINPERIOD = 10;
|
||||
const MAXPERIOD = 3600;
|
||||
// default min/max values for the 'flush every n records' setting on tasks
|
||||
const MINFLUSH = 1;
|
||||
const MAXFLUSH = 100;
|
||||
|
||||
const LOG_DEBUG = Logger::DEBUG;
|
||||
const LOG_INFO = Logger::INFO;
|
||||
const LOG_WARNING = Logger::WARNING;
|
||||
const LOG_ERROR = Logger::ERROR;
|
||||
const LOG_CRITICAL = Logger::CRITICAL;
|
||||
const LOG_ALERT = Logger::ALERT;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Logger
|
||||
@@ -677,7 +698,7 @@ abstract class task_abstract
|
||||
|
||||
$current_memory = memory_get_usage();
|
||||
if ($current_memory >> 20 >= $this->maxmegs) {
|
||||
$this->log(sprintf("Max memory (%s M) reached (actual is %.02f M)", $this->maxmegs, ($current_memory >> 10) / 1024));
|
||||
$this->log(sprintf("Max memory (%s M) reached (actual is %.02f M)", $this->maxmegs, ($current_memory >> 10) / 1024), self::LOG_ERROR);
|
||||
$this->running = FALSE;
|
||||
$ret = self::STATE_MAXMEGSREACHED;
|
||||
}
|
||||
@@ -707,7 +728,7 @@ abstract class task_abstract
|
||||
|
||||
$current_memory = memory_get_usage();
|
||||
if ($current_memory >> 20 >= $this->maxmegs) {
|
||||
$this->log(sprintf("Max memory (%s M) reached (current is %.02f M)", $this->maxmegs, ($current_memory >> 10) / 1024));
|
||||
$this->log(sprintf("Max memory (%s M) reached (current is %.02f M)", $this->maxmegs, ($current_memory >> 10) / 1024), self::LOG_ERROR);
|
||||
$this->running = FALSE;
|
||||
$ret = self::STATE_MAXMEGSREACHED;
|
||||
}
|
||||
@@ -739,21 +760,23 @@ abstract class task_abstract
|
||||
protected function loadSettings(SimpleXMLElement $sx_task_settings)
|
||||
{
|
||||
$this->period = (integer) $sx_task_settings->period;
|
||||
if ($this->period <= 0 || $this->period >= 60 * 60) {
|
||||
$this->period = 60;
|
||||
if ($this->period < self::MINPERIOD || $this->period > self::MAXPERIOD) {
|
||||
$this->period = self::MINPERIOD;
|
||||
}
|
||||
|
||||
$this->maxrecs = (integer) $sx_task_settings->maxrecs;
|
||||
if ($sx_task_settings->maxrecs < 10 || $sx_task_settings->maxrecs > 1000) {
|
||||
$this->maxrecs = 100;
|
||||
if ($sx_task_settings->maxrecs < self::MINRECS || $sx_task_settings->maxrecs > self::MAXRECS) {
|
||||
$this->maxrecs = self::MINRECS;
|
||||
}
|
||||
|
||||
$this->maxmegs = (integer) $sx_task_settings->maxmegs;
|
||||
if ($sx_task_settings->maxmegs < 16 || $sx_task_settings->maxmegs > 512) {
|
||||
$this->maxmegs = 24;
|
||||
if ($sx_task_settings->maxmegs < self::MINMEGS || $sx_task_settings->maxmegs > self::MAXMEGS) {
|
||||
$this->maxmegs = self::MINMEGS;
|
||||
}
|
||||
|
||||
$this->record_buffer_size = (integer) $sx_task_settings->flush;
|
||||
if ($sx_task_settings->flush < 1 || $sx_task_settings->flush > 100) {
|
||||
$this->record_buffer_size = 10;
|
||||
if ($sx_task_settings->flush < self::MINFLUSH || $sx_task_settings->flush > self::MAXFLUSH) {
|
||||
$this->record_buffer_size = self::MINFLUSH;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -783,10 +806,11 @@ abstract class task_abstract
|
||||
$this->logger->addDebug(memory_get_usage() . " -- " . memory_get_usage(true));
|
||||
}
|
||||
|
||||
public function log($message)
|
||||
public function log($message, $level=self::LOG_INFO)
|
||||
{
|
||||
// nb : self::log_levels ARE standard log levels, ok with monolog
|
||||
if ($this->logger) {
|
||||
$this->logger->addInfo($message);
|
||||
$this->logger->addRecord($level, $message);
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
Reference in New Issue
Block a user