Massive refactor to use SihnonFramework and PEAR's Net_Gearman

This commit is contained in:
2011-04-21 23:31:21 +01:00
parent fa7b54b861
commit d3fe08d40f
75 changed files with 290 additions and 1410 deletions

View File

@@ -0,0 +1,9 @@
<?php
$main = RippingCluster_Main::instance();
$req = $main->request();
$this->smarty->assign('requested_page', htmlspecialchars($req->request_string()));
?>

View File

@@ -0,0 +1,10 @@
<?php
$main = RippingCluster_Main::instance();
$config = $main->config();
$this->smarty->assign('display_exceptions', $config->get('debug.display_exceptions'));
$this->smarty->assign('exception', $exception);
$this->smarty->assign('exception_type', get_class($exception));
?>

View File

@@ -0,0 +1,11 @@
<?php
$running_jobs = RippingCluster_Job::allWithStatus(RippingCluster_JobStatus::RUNNING, 5);
$completed_jobs = RippingCluster_Job::allWithStatus(RippingCluster_JobStatus::COMPLETE, 5);
$failed_jobs = RippingCluster_Job::allWithStatus(RippingCluster_JobStatus::FAILED, 5);
$this->smarty->assign('running_jobs', $running_jobs);
$this->smarty->assign('completed_jobs', $completed_jobs);
$this->smarty->assign('failed_jobs', $failed_jobs);
?>

View File

@@ -0,0 +1,13 @@
<?php
$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);
$this->smarty->assign('client_log_entries', $client_log_entries);
$this->smarty->assign('worker_log_entries', $worker_log_entries);
?>

View File

@@ -0,0 +1,96 @@
<?php
$main = RippingCluster_Main::instance();
$req = $main->request();
$config = $main->config();
if ($req->get('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
# the id of the single item to act upon. Work out which was used now.
$matches = $job_ids = array();
if (preg_match('/^(.*)\[(\d+)\]$/', $action, $matches)) {
$action = $matches[1];
$job_ids = array($matches[2]);
}
else {
$job_ids = $_POST['include'];
}
$jobs = array();
foreach ($job_ids as $job_id) {
$job = RippingCluster_Job::fromId($job_id);
if (!$job) {
throw new RippingCluster_Exception_InvalidParameters('job_id');
}
$jobs[] = $job;
}
switch ($action) {
case 'mark-failed': {
foreach ($jobs as $job) {
$job->updateStatus(RippingCluster_JobStatus::FAILED);
}
} break;
case 'retry': {
# Clone each of the selected jobs
foreach ($jobs as $job) {
$new_job = clone $job;
}
# Dispatch all the jobs in one run
RippingCluster_Job::runAllJobs();
# Redirect to the job queued page to show the jobs were successfully dispatched
RippingCluster_Page::redirect('rips/setup-rip/queued');
} break;
case 'delete': {
foreach ($jobs as $job) {
$job->delete();
}
} break;
case 'fix-broken-timestamps': {
foreach ($jobs as $job) {
$job->fixBrokenTimestamps();
}
} break;
default: {
throw new RippingCluster_Exception_InvalidParameters('action');
}
}
RippingCluster_Page::redirect('jobs');
} else {
if (isset($_POST['view'])) {
$statusName = urlencode($_POST['view']);
RippingCluster_Page::redirect("jobs/view/{$statusName}");
}
$statusName = $req->get('view', 'any');
switch ($statusName) {
case 'any': $status = null; break;
case 'queued': $status = RippingCluster_JobStatus::QUEUED; break;
case 'running': $status = RippingCluster_JobStatus::RUNNING; break;
case 'complete': $status = RippingCluster_JobStatus::COMPLETE; break;
case 'failed': $status = RippingCluster_JobStatus::FAILED; break;
default: throw new RippingCluster_Exception_InvalidParameters('view');
}
$jobs = array();
if ($status) {
$jobs = RippingCluster_Job::allWithStatus($status);
} else {
$jobs = RippingCluster_Job::all();
}
$this->smarty->assign('jobs', $jobs);
}
?>

View File

@@ -0,0 +1,9 @@
<?php
$client_log_entries = RippingCluster_ClientLogEntry::recent(30);
$worker_log_entries = RippingCluster_WorkerLogEntry::recent(30);
$this->smarty->assign('client_log_entries', $client_log_entries);
$this->smarty->assign('worker_log_entries', $worker_log_entries);
?>

View File

@@ -0,0 +1,36 @@
<?php
$main = RippingCluster_Main::instance();
$req = $main->request();
$config = $main->config();
// Grab the name of this source
$encoded_filename = null;
if ($req->get('submit')) {
$encoded_filename = RippingCluster_Main::issetelse($_POST['id'], 'RippingCluster_Exception_InvalidParameters');
// Create the jobs from the request
$jobs = RippingCluster_Job::fromPostRequest($_POST['plugin'], $_POST['id'], $_POST['rip-options'], $_POST['rips']);
// Spawn the background client process to run all the jobs
RippingCluster_Job::runAllJobs();
RippingCluster_Page::redirect('rips/setup-rip/queued');
} elseif ($req->get('queued')) {
$this->smarty->assign('rips_submitted', true);
} else {
$this->smarty->assign('rips_submitted', false);
$encoded_filename = $req->get('id', 'RippingCluster_Exception_InvalidParameters');
$plugin = $req->get('plugin', 'RippingCluster_Exception_InvalidParameters');
$source = RippingCluster_Source_PluginFactory::loadEncoded($plugin, $encoded_filename);
$this->smarty->assign('source', $source);
$this->smarty->assign('titles', $source->titles());
$this->smarty->assign('longest_title', $source->longestTitle());
$this->smarty->assign('default_output_directory', $config->get('rips.default.output_directory'));
}
?>

View File

@@ -0,0 +1,13 @@
<?php
$main = RippingCluster_Main::instance();
$req = $main->request();
$config = $main->config();
$plugin = $req->get('plugin', 'RippingCluster_Exception_InvalidParameters');
$source = RippingCluster_Source_PluginFactory::loadEncoded($plugin, $req->get('id', 'RippingCluster_Exception_InvalidParameters'));
$this->smarty->assign('source', $source);
$this->smarty->assign('titles', $source->titles());
?>

View File

@@ -0,0 +1,9 @@
<?php
$main = RippingCluster_Main::instance();
$config = $main->config();
$all_sources = RippingCluster_Source_PluginFactory::enumerateAll();
$this->smarty->assign('all_sources', $all_sources);
?>

View File

@@ -0,0 +1,28 @@
<?php
$main = RippingCluster_Main::instance();
$req = $main->request();
$config = $main->config();
// Grab the name of this source
$encoded_filename = null;
if ($req->get('confirm')) {
$plugin = $req->get('plugin', 'RippingCluster_Exception_InvalidParameters');
$encoded_filename = $req->get('id', 'RippingCluster_Exception_InvalidParameters');
$source = RippingCluster_Source_PluginFactory::loadEncoded($plugin, $encoded_filename, false);
$source->delete();
// Redirect back to the sources page
RippingCluster_Page::redirect('rips/sources');
} else {
$plugin = $req->get('plugin', 'RippingCluster_Exception_InvalidParameters');
$encoded_filename = $req->get('id', 'RippingCluster_Exception_InvalidParameters');
$source = RippingCluster_Source_PluginFactory::loadEncoded($plugin, $encoded_filename, false);
$this->smarty->assign('source', $source);
}
?>