CC-3131: Latency of stream authentication warning in Stream Settings page

- it compares boot time of liquidsoap and the time user clicks on "Save"
on stream setting page. The status only gets updated if the
"boot_time" > "user update time"
- as soon as a user click on save, status is set to "wating"
- since there is no timing issue, quering interval is reduced to 1 sec
This commit is contained in:
James 2011-11-29 20:15:38 -05:00
parent 85b8209db9
commit 9c65bfeba7
10 changed files with 71 additions and 29 deletions

View file

@ -772,15 +772,17 @@ class ApiController extends Zend_Controller_Action
$error_msg = $request->getParam('error_msg');
$stream_id = $request->getParam('stream_id');
Application_Model_StreamSetting::setLiquidsoapError($stream_id, $error_msg);
$boot_time = $request->getParam('boot_time');
Application_Model_StreamSetting::setLiquidsoapError($stream_id, $error_msg, $boot_time);
}
public function updateLiquidsoapConnectionAction(){
$request = $this->getRequest();
$stream_id = $request->getParam('stream_id');
$boot_time = $request->getParam('boot_time');
// setting error_msg as "" when there is no error_msg
Application_Model_StreamSetting::setLiquidsoapError($stream_id, "OK");
Application_Model_StreamSetting::setLiquidsoapError($stream_id, "OK", $boot_time);
}
/**

View file

@ -203,6 +203,11 @@ class PreferenceController extends Zend_Controller_Action
Application_Model_StreamSetting::setStreamSetting($values);
$data = array();
$data['setting'] = Application_Model_StreamSetting::getStreamSetting();
for($i=1;$i<=$num_of_stream;$i++){
Application_Model_StreamSetting::setLiquidsoapError($i, "waiting");
}
// store stream update timestamp
Application_Model_Preference::SetStreamUpdateTimestamp();
Application_Model_RabbitMq::SendMessageToPypo("update_stream_setting", $data);
$this->view->statusMsg = "<div class='success'>Stream Setting Updated.</div>";
}

View file

@ -573,6 +573,25 @@ class Application_Model_Preference
return $val;
}
}
/**
* Stores the last timestamp of user updating stream setting
*/
public static function SetStreamUpdateTimestamp() {
$now = time();
self::SetValue("stream_update_timestamp", $now);
}
/**
* Gets the last timestamp of user updating stream setting
*/
public static function GetStreamUpdateTimestemp() {
$update_time = self::GetValue("stream_update_timestamp");
if($update_time == null){
$update_time = 0;
}
return $update_time;
}
/* User specific preferences start */

View file

@ -113,22 +113,29 @@ class Application_Model_StreamSetting {
}
}
public static function setLiquidsoapError($stream_id, $msg){
/*
* Stores liquidsoap status if $boot_time > save time.
* save time is the time that user clicked save on stream setting page
*/
public static function setLiquidsoapError($stream_id, $msg, $boot_time=null){
global $CC_DBC;
$keyname = "s".$stream_id."_liquidsoap_error";
$sql = "SELECT COUNT(*) FROM cc_stream_setting"
." WHERE keyname = '$keyname'";
$result = $CC_DBC->GetOne($sql);
if ($result == 1){
$sql = "UPDATE cc_stream_setting"
." SET value = '$msg'"
$update_time = Application_Model_Preference::GetStreamUpdateTimestemp();
if($boot_time == null || $boot_time > $update_time ){
$keyname = "s".$stream_id."_liquidsoap_error";
$sql = "SELECT COUNT(*) FROM cc_stream_setting"
." WHERE keyname = '$keyname'";
}else{
$sql = "INSERT INTO cc_stream_setting (keyname, value, type)"
." VALUES ('$keyname', '$msg', 'string')";
$result = $CC_DBC->GetOne($sql);
if ($result == 1){
$sql = "UPDATE cc_stream_setting"
." SET value = '$msg'"
." WHERE keyname = '$keyname'";
}else{
$sql = "INSERT INTO cc_stream_setting (keyname, value, type)"
." VALUES ('$keyname', '$msg', 'string')";
}
$res = $CC_DBC->query($sql);
}
$res = $CC_DBC->query($sql);
}
public static function getLiquidsoapError($stream_id){

View file

@ -96,6 +96,8 @@ function checkLiquidsoapStatus(){
html = '<div class="stream-status status-good"><h3>Connected to the streaming server</h3></div>'
}else if(status == "N/A"){
html = '<div class="stream-status status-disabled"><h3>The stream is disabled</h3></div>'
}else if(status == "waiting"){
html = '<div class="stream-status status-info"><h3>Getting information from the server...</h3></div>'
}else{
html = '<div class="stream-status status-error"><h3>Can not connect to the streaming server</h3><p>'+status+'</p></div>'
}
@ -163,6 +165,6 @@ $(document).ready(function() {
})
showErrorSections()
setInterval('checkLiquidsoapStatus()', 7000)
setInterval('checkLiquidsoapStatus()', 1000)
});

View file

@ -93,10 +93,10 @@ generate_range_url = 'generate_range_dp.php'
get_stream_setting = 'get-stream-setting/format/json/api_key/%%api_key%%/'
#URL to update liquidsoap error msg
update_liquidsoap_error = 'update-liquidsoap-error/format/json/api_key/%%api_key%%/error_msg/%%error_msg%%/stream_id/%%stream_id%%'
update_liquidsoap_error = 'update-liquidsoap-error/format/json/api_key/%%api_key%%/error_msg/%%error_msg%%/stream_id/%%stream_id%%/boot_time/%%boot_time%%'
#URL to update liquidsoap connection
update_liquidsoap_connection = 'update-liquidsoap-connection/format/json/api_key/%%api_key%%/stream_id/%%stream_id%%'
update_liquidsoap_connection = 'update-liquidsoap-connection/format/json/api_key/%%api_key%%/stream_id/%%stream_id%%/boot_time/%%boot_time%%'
##############
# OBP config #

View file

@ -571,7 +571,7 @@ class AirTimeApiClient(ApiClientInterface):
except Exception, e:
logger.error("Exception: %s", e)
def notify_liquidsoap_error(self, error_msg, stream_id):
def notify_liquidsoap_error(self, error_msg, stream_id, time):
logger = logging.getLogger()
try:
url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["update_liquidsoap_error"])
@ -581,19 +581,21 @@ class AirTimeApiClient(ApiClientInterface):
encoded_msg = urllib.quote(error_msg, '')
url = url.replace("%%error_msg%%", encoded_msg)
url = url.replace("%%stream_id%%", stream_id)
url = url.replace("%%boot_time%%", time)
logger.debug(url)
req = urllib2.Request(url)
response = urllib2.urlopen(req).read()
except Exception, e:
logger.error("Exception: %s", e)
def notify_liquidsoap_connection(self, stream_id):
def notify_liquidsoap_connection(self, stream_id, time):
logger = logging.getLogger()
try:
url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["update_liquidsoap_connection"])
url = url.replace("%%api_key%%", self.config["api_key"])
url = url.replace("%%stream_id%%", stream_id)
url = url.replace("%%boot_time%%", time)
logger.debug(url)
req = urllib2.Request(url)
response = urllib2.urlopen(req).read()

View file

@ -39,13 +39,13 @@ end
def output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, user, s, stream) =
def on_error(msg)
system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --error='#{msg}' --stream-id=#{stream}")
log("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --error='#{msg}' --stream-id=#{stream}")
system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --error='#{msg}' --stream-id=#{stream} --time=#{time}")
log("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --error='#{msg}' --stream-id=#{stream} --time=#{time}")
5.
end
def on_connect()
system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --connect --stream-id=#{stream}")
log("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --connect --stream-id=#{stream}")
system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --connect --stream-id=#{stream} --time=#{time}")
log("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --connect --stream-id=#{stream} --time=#{time}")
end
if output_type == "icecast" then
user_ref = ref user

View file

@ -6,6 +6,8 @@ set("log.stdout", true)
set("server.telnet", true)
set("server.telnet.port", 1234)
time = gettimeofday()
queue = audio_to_stereo(request.queue(id="queue", length=0.5))
queue = cue_cut(queue)

View file

@ -50,6 +50,7 @@ parser.add_option("-m", "--media-id", help="ID of the file that is currently pla
parser.add_option("-e", "--error", action="store", dest="error", type="string", help="liquidsoap error msg.", metavar="error_msg")
parser.add_option("-s", "--stream-id", help="ID stream", metavar="stream_id")
parser.add_option("-c", "--connect", help="liquidsoap connected", action="store_true", metavar="connect")
parser.add_option("-t", "--time", help="liquidsoap boot up time", action="store", dest="time", metavar="time", type="string")
# parse options
(options, args) = parser.parse_args()
@ -80,23 +81,25 @@ class Notify:
response = self.api_client.notify_media_item_start_playing(data, media_id)
logger.debug("Response: "+json.dumps(response))
def notify_liquidsoap_error(self, error_msg, stream_id):
# @pram time: time that LS started
def notify_liquidsoap_error(self, error_msg, stream_id, time):
logger = logging.getLogger()
logger.debug('#################################################')
logger.debug('# Calling server to update liquidsoap error #')
logger.debug('#################################################')
logger.debug('error msg = '+ str(error_msg))
response = self.api_client.notify_liquidsoap_error(error_msg, stream_id)
response = self.api_client.notify_liquidsoap_error(error_msg, stream_id, time)
logger.debug("Response: "+json.dumps(response))
def notify_liquidsoap_connection(self, stream_id):
# @pram time: time that LS started
def notify_liquidsoap_connection(self, stream_id, time):
logger = logging.getLogger()
logger.debug('#################################################')
logger.debug('# Calling server to update liquidsoap connection#')
logger.debug('#################################################')
response = self.api_client.notify_liquidsoap_connection(stream_id)
response = self.api_client.notify_liquidsoap_connection(stream_id, time)
logger.debug("Response: "+json.dumps(response))
if __name__ == '__main__':
@ -112,13 +115,13 @@ if __name__ == '__main__':
if options.error and options.stream_id:
try:
n = Notify()
n.notify_liquidsoap_error(options.error, options.stream_id)
n.notify_liquidsoap_error(options.error, options.stream_id, options.time)
except Exception, e:
print e
elif options.connect and options.stream_id:
try:
n = Notify()
n.notify_liquidsoap_connection(options.stream_id)
n.notify_liquidsoap_connection(options.stream_id, options.time)
except Exception, e:
print e
else: