SAAS-1229 - initial work on bandwidth limit within Airtime; overhaul TaskFactory to get tasks reflectively

This commit is contained in:
Duncan Sommerville 2015-11-19 16:08:25 -05:00
parent c328515f4b
commit 6c2d1f008b
4 changed files with 126 additions and 32 deletions

View file

@ -11,6 +11,8 @@ class ApiController extends Zend_Controller_Action
public function init()
{
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
//Ignore API key and session authentication for these APIs:
$ignoreAuth = array("live-info",
@ -101,14 +103,6 @@ class ApiController extends Zend_Controller_Action
exit();
}
public function pollCeleryAction() {
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$taskManager = TaskManager::getInstance();
$taskManager->runTask(TaskFactory::CELERY);
}
public function versionAction()
{
$this->_helper->json->sendJson( array(
@ -136,6 +130,35 @@ class ApiController extends Zend_Controller_Action
$this->_helper->json->sendJson(array());
}
/**
* Manually trigger the TaskManager task to poll for completed Celery tasks
*/
public function pollCeleryAction() {
$taskManager = TaskManager::getInstance();
$clazz = version_compare(phpversion(), '5.5.0', '<') ? get_class(new CeleryTask) : CeleryTask::class;
$taskManager->runTask($clazz);
}
/**
* TODO: move this function into a more generic analytics REST controller
*
* Update station bandwidth usage based on icecast log data
*/
public function bandwidthUsageAction() {
// FIXME: this function is using placeholder names
$bandwidthUsage = json_decode($this->getRequest()->getParam("bandwidth_usage"));
$usageBytes = 0;
foreach ($bandwidthUsage as $entry) {
Logging::info($entry);
// TODO: store the IP address for future use
$ts = strtotime($entry->timestamp);
if ($ts > Application_Model_Preference::getBandwidthLimitUpdateTimer()) {
$usageBytes += $entry->bytes;
}
}
Application_Model_Preference::incrementBandwidthLimitCounter($usageBytes);
}
//Used by the SaaS monitoring
public function onAirLightAction()
{

View file

@ -64,7 +64,8 @@ class PageLayoutInitPlugin extends Zend_Controller_Plugin_Abstract
// We can't afford to wait 7 minutes to run an upgrade: users could
// have several minutes of database errors while waiting for a
// schema change upgrade to happen after a deployment
$taskManager->runTask(TaskFactory::UPGRADE);
$clazz = version_compare(phpversion(), '5.5.0', '<') ? get_class(new UpgradeTask) : UpgradeTask::class;
$taskManager->runTask($clazz);
// Piggyback the TaskManager onto API calls. This provides guaranteed consistency
// (there is at least one API call made from pypo to Airtime every 7 minutes) and