CC-2096 Schedule changes should be sent to RabbitMQ at most once per user request
Implemented as a plugin to Zend. Now at most one schedule push to RabbitMQ will happen per user action. It's pretty sweet.
This commit is contained in:
parent
50432c0b66
commit
f9c8a7cc11
3 changed files with 47 additions and 23 deletions
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once (__DIR__."/configs/navigation.php");
|
require_once __DIR__."/configs/navigation.php";
|
||||||
require_once (__DIR__."/configs/ACL.php");
|
require_once __DIR__."/configs/ACL.php";
|
||||||
|
|
||||||
require_once 'propel/runtime/lib/Propel.php';
|
require_once 'propel/runtime/lib/Propel.php';
|
||||||
Propel::init(__DIR__."/configs/airtime-conf.php");
|
Propel::init(__DIR__."/configs/airtime-conf.php");
|
||||||
|
@ -10,8 +10,8 @@ Propel::init(__DIR__."/configs/airtime-conf.php");
|
||||||
$tz = ini_get('date.timezone') ? ini_get('date.timezone') : 'UTC';
|
$tz = ini_get('date.timezone') ? ini_get('date.timezone') : 'UTC';
|
||||||
date_default_timezone_set($tz);
|
date_default_timezone_set($tz);
|
||||||
|
|
||||||
require_once (__DIR__."/configs/constants.php");
|
require_once __DIR__."/configs/constants.php";
|
||||||
require_once (__DIR__."/configs/conf.php");
|
require_once __DIR__."/configs/conf.php";
|
||||||
require_once 'DB.php';
|
require_once 'DB.php';
|
||||||
|
|
||||||
require_once 'Soundcloud.php';
|
require_once 'Soundcloud.php';
|
||||||
|
@ -21,7 +21,7 @@ require_once 'Schedule.php';
|
||||||
require_once 'Shows.php';
|
require_once 'Shows.php';
|
||||||
require_once 'Users.php';
|
require_once 'Users.php';
|
||||||
require_once 'RabbitMq.php';
|
require_once 'RabbitMq.php';
|
||||||
|
require_once __DIR__.'/controllers/plugins/RabbitMqPlugin.php';
|
||||||
|
|
||||||
global $CC_CONFIG, $CC_DBC;
|
global $CC_CONFIG, $CC_DBC;
|
||||||
$dsn = $CC_CONFIG['dsn'];
|
$dsn = $CC_CONFIG['dsn'];
|
||||||
|
@ -36,6 +36,9 @@ $CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||||
//Zend_Session::start();
|
//Zend_Session::start();
|
||||||
Zend_Validate::setDefaultNamespaces("Zend");
|
Zend_Validate::setDefaultNamespaces("Zend");
|
||||||
|
|
||||||
|
$front = Zend_Controller_Front::getInstance();
|
||||||
|
$front->registerPlugin(new RabbitMqPlugin());
|
||||||
|
|
||||||
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
|
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
|
||||||
{
|
{
|
||||||
protected function _initDoctype()
|
protected function _initDoctype()
|
||||||
|
@ -48,9 +51,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
|
||||||
protected function _initHeadLink()
|
protected function _initHeadLink()
|
||||||
{
|
{
|
||||||
$view = $this->getResource('view');
|
$view = $this->getResource('view');
|
||||||
|
|
||||||
$view->headLink()->appendStylesheet('/css/redmond/jquery-ui-1.8.8.custom.css');
|
$view->headLink()->appendStylesheet('/css/redmond/jquery-ui-1.8.8.custom.css');
|
||||||
|
|
||||||
$this->view->headLink()->appendStylesheet('/css/pro_dropdown_3.css');
|
$this->view->headLink()->appendStylesheet('/css/pro_dropdown_3.css');
|
||||||
$this->view->headLink()->appendStylesheet('/css/styles.css');
|
$this->view->headLink()->appendStylesheet('/css/styles.css');
|
||||||
}
|
}
|
||||||
|
@ -70,14 +71,17 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
|
||||||
$view->headScript()->appendFile('/js/airtime/common/common.js','text/javascript');
|
$view->headScript()->appendFile('/js/airtime/common/common.js','text/javascript');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _initViewHelpers(){
|
protected function _initViewHelpers()
|
||||||
|
{
|
||||||
$view = $this->getResource('view');
|
$view = $this->getResource('view');
|
||||||
$view->addHelperPath('../application/views/helpers', 'Airtime_View_Helper');
|
$view->addHelperPath('../application/views/helpers', 'Airtime_View_Helper');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _initTitle(){
|
protected function _initTitle()
|
||||||
|
{
|
||||||
$view = $this->getResource('view');
|
$view = $this->getResource('view');
|
||||||
$view->headTitle(Application_Model_Preference::GetHeadTitle());
|
$view->headTitle(Application_Model_Preference::GetHeadTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
9
application/controllers/plugins/RabbitMqPlugin.php
Normal file
9
application/controllers/plugins/RabbitMqPlugin.php
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class RabbitMqPlugin extends Zend_Controller_Plugin_Abstract
|
||||||
|
{
|
||||||
|
public function dispatchLoopShutdown()
|
||||||
|
{
|
||||||
|
RabbitMq::PushScheduleFinal();
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,14 +3,24 @@ require_once 'php-amqplib/amqp.inc';
|
||||||
|
|
||||||
class RabbitMq
|
class RabbitMq
|
||||||
{
|
{
|
||||||
|
static private $doPush = FALSE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a flag to push the schedule at the end of the request.
|
||||||
|
*/
|
||||||
|
public static function PushSchedule() {
|
||||||
|
RabbitMq::$doPush = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Push the current schedule to RabbitMQ, to be picked up by Pypo.
|
* Push the current schedule to RabbitMQ, to be picked up by Pypo.
|
||||||
* Will push the schedule in the range from 24 hours ago to 24 hours
|
* Will push the schedule in the range from 24 hours ago to 24 hours
|
||||||
* in the future.
|
* in the future.
|
||||||
*/
|
*/
|
||||||
public static function PushSchedule() {
|
public static function PushScheduleFinal()
|
||||||
|
{
|
||||||
global $CC_CONFIG;
|
global $CC_CONFIG;
|
||||||
|
if (RabbitMq::$doPush) {
|
||||||
$conn = new AMQPConnection($CC_CONFIG["rabbitmq"]["host"],
|
$conn = new AMQPConnection($CC_CONFIG["rabbitmq"]["host"],
|
||||||
$CC_CONFIG["rabbitmq"]["port"],
|
$CC_CONFIG["rabbitmq"]["port"],
|
||||||
$CC_CONFIG["rabbitmq"]["user"],
|
$CC_CONFIG["rabbitmq"]["user"],
|
||||||
|
@ -28,6 +38,7 @@ class RabbitMq
|
||||||
$channel->close();
|
$channel->close();
|
||||||
$conn->close();
|
$conn->close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue