Updated code to use new Logging code in sihnon lib

This commit is contained in:
2011-04-24 10:40:14 +01:00
parent b896877591
commit dbaf4968ab
6 changed files with 90 additions and 16 deletions

View File

@@ -0,0 +1,76 @@
<?php
class RippingCluster_LogEntry extends SihnonFramework_LogEntry {
protected $job_id;
public static function initialise() {
self::$types['job_id'] = 'int';
}
protected function __construct($level, $category, $ctime, $pid, $file, $line, $message, $job_id) {
parent::__construct($level, $category, $ctime, $pid, $file, $line, $message);
$this->job_id = $job_id;
}
public static function fromArray($row) {
return new self(
$row['level'],
$row['category'],
$row['ctime'],
$row['pid'],
$row['file'],
$row['line'],
$row['message'],
$row['job_id']
);
}
public function values() {
return array(
$this->level,
$this->category,
$this->ctime,
static::$hostname,
static::$progname,
$this->pid,
$this->file,
$this->line,
$this->message,
$this->job_id,
);
}
public function jobId() {
return $this->job_id;
}
protected static function log($logger, $severity, $job_id, $message, $category = SihnonFramework_Log::CATEGORY_DEFAULT) {
$backtrace = debug_backtrace(false);
$entry = new self($severity, $category, time(), getmypid(), $backtrace[1]['file'], $backtrace[1]['line'], $message, $job_id);
$logger->log($entry);
}
public static function debug($logger, $job_id, $message, $category = SihnonFramework_Log::CATEGORY_DEFAULT) {
static::log($logger, SihnonFramework_Log::LEVEL_DEBUG, $job_id, $message, $category);
}
public static function info($logger, $job_id, $message, $category = SihnonFramework_Log::CATEGORY_DEFAULT) {
static::log($logger, SihnonFramework_Log::LEVEL_INFO, $job_id, $message, $category);
}
public static function warning($logger, $job_id, $message, $category = SihnonFramework_Log::CATEGORY_DEFAULT) {
static::log($logger, SihnonFramework_Log::LEVEL_WARNING, $job_id, $message, $category);
}
public static function error($logger, $job_id, $message, $category = SihnonFramework_Log::CATEGORY_DEFAULT) {
static::log($logger, SihnonFramework_Log::LEVEL_ERROR, $job_id, $message, $category);
}
}
RippingCluster_LogEntry::initialise();
?>

View File

@@ -16,19 +16,13 @@ class RippingCluster_Worker {
$config = RippingCluster_Main::instance()->config();
$this->gearman = new Net_Gearman_Worker('river.sihnon.net:4730');//$config->get('rips.job_servers'));
$this->gearman = new Net_Gearman_Worker($config->get('rips.job_servers'));
// Load all the plugin classes
RippingCluster_Worker_PluginFactory::scan();
$plugins = RippingCluster_Worker_PluginFactory::getValidPlugins();
foreach ($plugins as $plugin) {
$this->gearman->addAbility($plugin);
//$workerFunctions = RippingCluster_Worker_PluginFactory::getPluginWorkerFunctions($plugin);
//foreach ($workerFunctions as $function => $callback) {
// echo "Added ability $function\n";
// $this->gearman->addAbility($function);
//}
}
}

View File

@@ -14,7 +14,7 @@ try {
$config = $main->config();
$log = $main->log();
$client = new Net_Gearman_Client('river.sihnon.net:4730');//$config->get('rips.job_servers'));
$client = new Net_Gearman_Client($config->get('rips.job_servers'));
$set = new Net_Gearman_Set();
// Retrieve a list of Created jobs
@@ -34,7 +34,7 @@ try {
// Start the job queue
$result = $client->runSet($set);
$log->info("Job queue completed");
RippingCluster_LogEntry::info($log, 'Job queue completed', 'batch');
} catch (RippingCluster_Exception $e) {
die("Uncaught Exception (" . get_class($e) . "): " . $e->getMessage() . "\n");
@@ -46,7 +46,7 @@ function gearman_complete($method, $handle, $result) {
$log = $main->log();
/*$log->info("Job Complete", $job->id());*/
$log->info("Job complete");
RippingCluster_LogEntry::info($log, 'Job complete', 'batch');
}
function gearman_fail($task) {
@@ -57,7 +57,7 @@ function gearman_fail($task) {
$job->updateStatus(RippingCluster_JobStatus::FAILED);
$log->info("Job Failed", $job->id());*/
$log->info("Job failed");
RippingCluster_LogEntry::info($log, 'Job failed', 'batch');
}

View File

@@ -4,8 +4,10 @@ $job_id = $this->request->get('id');
$job = RippingCluster_Job::fromId($job_id);
$this->smarty->assign('job', $job);
$client_log_entries = RippingCluster_ClientLogEntry::recentForJob($job_id, 30);
$worker_log_entries = RippingCluster_WorkerLogEntry::recentForJob($job_id, 30);
$log = RippingCluster_Main::instance()->log();
$client_log_entries = RippingCluster_LogEntry::recentEntriesByField($log, 'webui', 'job_id', $job_id, 'ctime', SihnonFramework_Log::ORDER_DESC, 30);
$worker_log_entries = RippingCluster_LogEntry::recentEntriesByField($log, 'worker', 'job_id', $job_id, 'ctime', SihnonFramework_Log::ORDER_DESC, 30);
$this->smarty->assign('client_log_entries', $client_log_entries);
$this->smarty->assign('worker_log_entries', $worker_log_entries);

View File

@@ -4,7 +4,7 @@ $main = RippingCluster_Main::instance();
$req = $main->request();
$config = $main->config();
if ($req->get('submit')) {
if ($req->exists('submit')) {
$action = RippingCluster_Main::issetelse($_POST['action'], 'RippingCluster_Exception_InvalidParameters');
# If a bulk action was selected, the action will be a single term, otherwise it will also contain

View File

@@ -1,7 +1,9 @@
<?php
$client_log_entries = RippingCluster_ClientLogEntry::recent(30);
$worker_log_entries = RippingCluster_WorkerLogEntry::recent(30);
$log = RippingCluster_Main::instance()->log();
$client_log_entries = RippingCluster_LogEntry::recentEntries($log, 'webui', 30);
$worker_log_entries = RippingCluster_LogEntry::recentEntries($log, 'worker', 30);
$this->smarty->assign('client_log_entries', $client_log_entries);
$this->smarty->assign('worker_log_entries', $worker_log_entries);