diff --git a/source/lib/RippingCluster/LogEntry.class.php b/source/lib/RippingCluster/LogEntry.class.php new file mode 100644 index 0000000..ce620fc --- /dev/null +++ b/source/lib/RippingCluster/LogEntry.class.php @@ -0,0 +1,76 @@ +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(); + +?> \ No newline at end of file diff --git a/source/lib/RippingCluster/Worker.class.php b/source/lib/RippingCluster/Worker.class.php index 5996f06..7ca0fe2 100644 --- a/source/lib/RippingCluster/Worker.class.php +++ b/source/lib/RippingCluster/Worker.class.php @@ -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); - //} } } diff --git a/webui/run-jobs.php b/webui/run-jobs.php index d2fc363..623dec6 100644 --- a/webui/run-jobs.php +++ b/webui/run-jobs.php @@ -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'); } diff --git a/webui/source/pages/job-details.php b/webui/source/pages/job-details.php index 3e342aa..86df585 100644 --- a/webui/source/pages/job-details.php +++ b/webui/source/pages/job-details.php @@ -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); diff --git a/webui/source/pages/jobs.php b/webui/source/pages/jobs.php index aea9ced..8dd9355 100644 --- a/webui/source/pages/jobs.php +++ b/webui/source/pages/jobs.php @@ -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 diff --git a/webui/source/pages/logs.php b/webui/source/pages/logs.php index 0bf7a8f..b144dcd 100644 --- a/webui/source/pages/logs.php +++ b/webui/source/pages/logs.php @@ -1,7 +1,9 @@ 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);