feat: move stream stats status to pref table
This commit is contained in:
parent
2b533d4724
commit
406d42323a
|
@ -0,0 +1,29 @@
|
||||||
|
# pylint: disable=invalid-name
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
from ._migrations import legacy_migration_factory
|
||||||
|
|
||||||
|
UP = """
|
||||||
|
delete from cc_stream_setting
|
||||||
|
where "keyname" like '%_listener_stat_error';
|
||||||
|
"""
|
||||||
|
|
||||||
|
DOWN = """
|
||||||
|
delete from cc_pref
|
||||||
|
where "keystr" like 'stream_stats_status:%';
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("legacy", "0038_3_0_0_alpha_14_2"),
|
||||||
|
]
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(
|
||||||
|
code=legacy_migration_factory(
|
||||||
|
target="3.0.0-alpha.14.3",
|
||||||
|
sql=UP,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
]
|
|
@ -1 +1 @@
|
||||||
LEGACY_SCHEMA_VERSION = "3.0.0-alpha.14.2"
|
LEGACY_SCHEMA_VERSION = "3.0.0-alpha.14.3"
|
||||||
|
|
|
@ -1389,8 +1389,8 @@ class ApiController extends Zend_Controller_Action
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($data as $k => $v) {
|
foreach ($data as $stream_id => $status) {
|
||||||
Application_Model_StreamSetting::SetListenerStatError($k, $v);
|
Application_Model_Preference::SetListenerStatError($stream_id, $status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,15 +41,15 @@ class ListenerstatController extends Zend_Controller_Action
|
||||||
'his_time_end' => $endsDT->format('H:i'),
|
'his_time_end' => $endsDT->format('H:i'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$errorStatus = Application_Model_StreamSetting::GetAllListenerStatErrors();
|
$errorStatus = Application_Model_Preference::GetAllListenerStatErrors();
|
||||||
Logging::info($errorStatus);
|
Logging::info($errorStatus);
|
||||||
$out = [];
|
$out = [];
|
||||||
foreach ($errorStatus as $v) {
|
foreach ($errorStatus as $v) {
|
||||||
$key = explode('_listener_stat_error', $v['keyname']);
|
$key = explode(':', $v['keystr']);
|
||||||
if ($v['value'] != 'OK') {
|
if ($v['valstr'] != 'OK') {
|
||||||
$v['value'] = _('Please make sure admin user/password is correct on Settings->Streams page.');
|
$v['valstr'] = _('Please make sure admin user/password is correct on Settings->Streams page.');
|
||||||
}
|
}
|
||||||
$out[$key[0]] = $v['value'];
|
$out['stream ' . $key[1]] = $v['valstr'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->view->errorStatus = $out;
|
$this->view->errorStatus = $out;
|
||||||
|
|
|
@ -1677,4 +1677,21 @@ class Application_Model_Preference
|
||||||
|
|
||||||
return ($result !== false) ? $result : null;
|
return ($result !== false) ? $result : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function GetAllListenerStatErrors()
|
||||||
|
{
|
||||||
|
$sql = <<<'SQL'
|
||||||
|
SELECT *
|
||||||
|
FROM cc_pref
|
||||||
|
WHERE keystr LIKE 'stream_stats_status:%'
|
||||||
|
SQL;
|
||||||
|
|
||||||
|
return Application_Common_Database::prepareAndExecute($sql, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function SetListenerStatError($stream_id, $value)
|
||||||
|
{
|
||||||
|
$stream_id = trim($stream_id, 's');
|
||||||
|
self::setValue("stream_stats_status:{$stream_id}", $value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -436,29 +436,6 @@ class Application_Model_StreamSetting
|
||||||
self::setValue($stream . '_admin_pass', $v, 'string');
|
self::setValue($stream . '_admin_pass', $v, 'string');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function GetAllListenerStatErrors()
|
|
||||||
{
|
|
||||||
$sql = 'SELECT * FROM cc_stream_setting WHERE keyname like :p1';
|
|
||||||
$mounts = Application_Common_Database::prepareAndExecute($sql, [':p1' => '%_mount']);
|
|
||||||
|
|
||||||
$mps = [];
|
|
||||||
|
|
||||||
foreach ($mounts as $mount) {
|
|
||||||
$mps[] = "'" . $mount['value'] . "_listener_stat_error'";
|
|
||||||
}
|
|
||||||
|
|
||||||
$in = implode(',', $mps);
|
|
||||||
|
|
||||||
$sql = "SELECT * FROM cc_stream_setting WHERE keyname IN ( {$in} )";
|
|
||||||
|
|
||||||
return Application_Common_Database::prepareAndExecute($sql, []);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function SetListenerStatError($key, $v)
|
|
||||||
{
|
|
||||||
self::setValue($key, $v, 'string');
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getIcecastVorbisMetadata()
|
public static function getIcecastVorbisMetadata()
|
||||||
{
|
{
|
||||||
return self::getValue('icecast_vorbis_metadata', '');
|
return self::getValue('icecast_vorbis_metadata', '');
|
||||||
|
|
|
@ -122,10 +122,10 @@ class ListenerStat(Thread):
|
||||||
stats.append(mount_stats)
|
stats.append(mount_stats)
|
||||||
else:
|
else:
|
||||||
stats.append(self.get_shoutcast_stats(v))
|
stats.append(self.get_shoutcast_stats(v))
|
||||||
self.update_listener_stat_error(v["mount"], "OK")
|
self.update_listener_stat_error(k, "OK")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
try:
|
try:
|
||||||
self.update_listener_stat_error(v["mount"], str(e))
|
self.update_listener_stat_error(k, str(e))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Exception: %s", e)
|
logger.error("Exception: %s", e)
|
||||||
|
|
||||||
|
@ -135,8 +135,7 @@ class ListenerStat(Thread):
|
||||||
self.legacy_client.push_stream_stats(stats)
|
self.legacy_client.push_stream_stats(stats)
|
||||||
|
|
||||||
def update_listener_stat_error(self, stream_id, error):
|
def update_listener_stat_error(self, stream_id, error):
|
||||||
keyname = "%s_listener_stat_error" % stream_id
|
data = {stream_id: error}
|
||||||
data = {keyname: error}
|
|
||||||
self.legacy_client.update_stream_setting_table(data)
|
self.legacy_client.update_stream_setting_table(data)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
Loading…
Reference in New Issue