CC-2098: Only push playlists that havent ended yet
-implemented. Removed ability to specify time ranges for now, and defaulted to looking from now to 24 hours ahead. Being able to specify time ranges was removed, since we are not using bi-directional communication between pypofetch and Airtime server.
This commit is contained in:
parent
343fb593ee
commit
1107a67579
|
@ -133,6 +133,7 @@ class ApiController extends Zend_Controller_Action
|
||||||
$this->_helper->viewRenderer->setNoRender(true);
|
$this->_helper->viewRenderer->setNoRender(true);
|
||||||
|
|
||||||
$api_key = $this->_getParam('api_key');
|
$api_key = $this->_getParam('api_key');
|
||||||
|
|
||||||
if(!in_array($api_key, $CC_CONFIG["apiKey"]))
|
if(!in_array($api_key, $CC_CONFIG["apiKey"]))
|
||||||
{
|
{
|
||||||
header('HTTP/1.0 401 Unauthorized');
|
header('HTTP/1.0 401 Unauthorized');
|
||||||
|
@ -142,12 +143,8 @@ class ApiController extends Zend_Controller_Action
|
||||||
|
|
||||||
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
|
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
|
||||||
|
|
||||||
$from = $this->_getParam("from");
|
$result = Schedule::GetScheduledPlaylists();
|
||||||
$to = $this->_getParam("to");
|
echo json_encode($result);
|
||||||
if (Schedule::ValidPypoTimeFormat($from) && Schedule::ValidPypoTimeFormat($to)) {
|
|
||||||
$result = Schedule::ExportRangeAsJson($from, $to);
|
|
||||||
echo json_encode($result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function notifyMediaItemStartPlayAction()
|
public function notifyMediaItemStartPlayAction()
|
||||||
|
|
|
@ -31,7 +31,7 @@ class RabbitMq
|
||||||
$EXCHANGE = 'airtime-schedule';
|
$EXCHANGE = 'airtime-schedule';
|
||||||
$channel->exchange_declare($EXCHANGE, 'direct', false, true);
|
$channel->exchange_declare($EXCHANGE, 'direct', false, true);
|
||||||
|
|
||||||
$data = json_encode(Schedule::ExportRangeAsJson());
|
$data = json_encode(Schedule::GetScheduledPlaylists());
|
||||||
$msg = new AMQPMessage($data, array('content_type' => 'text/plain'));
|
$msg = new AMQPMessage($data, array('content_type' => 'text/plain'));
|
||||||
|
|
||||||
$channel->basic_publish($msg, $EXCHANGE);
|
$channel->basic_publish($msg, $EXCHANGE);
|
||||||
|
|
|
@ -354,13 +354,14 @@ class Schedule {
|
||||||
* @return array
|
* @return array
|
||||||
* Returns empty array if nothing found
|
* Returns empty array if nothing found
|
||||||
*/
|
*/
|
||||||
public static function GetItems($p_fromDateTime, $p_toDateTime, $p_playlistsOnly = true)
|
|
||||||
|
public static function GetItems($p_currentDateTime, $p_toDateTime, $p_playlistsOnly = true)
|
||||||
{
|
{
|
||||||
global $CC_CONFIG, $CC_DBC;
|
global $CC_CONFIG, $CC_DBC;
|
||||||
$rows = array();
|
$rows = array();
|
||||||
if (!$p_playlistsOnly) {
|
if (!$p_playlistsOnly) {
|
||||||
$sql = "SELECT * FROM ".$CC_CONFIG["scheduleTable"]
|
$sql = "SELECT * FROM ".$CC_CONFIG["scheduleTable"]
|
||||||
." WHERE (starts >= TIMESTAMP '$p_fromDateTime') "
|
." WHERE (starts >= TIMESTAMP '$p_currentDateTime') "
|
||||||
." AND (ends <= TIMESTAMP '$p_toDateTime')";
|
." AND (ends <= TIMESTAMP '$p_toDateTime')";
|
||||||
$rows = $CC_DBC->GetAll($sql);
|
$rows = $CC_DBC->GetAll($sql);
|
||||||
foreach ($rows as &$row) {
|
foreach ($rows as &$row) {
|
||||||
|
@ -388,7 +389,7 @@ class Schedule {
|
||||||
." ON st.instance_id = si.id"
|
." ON st.instance_id = si.id"
|
||||||
." LEFT JOIN $CC_CONFIG[showTable] as sh"
|
." LEFT JOIN $CC_CONFIG[showTable] as sh"
|
||||||
." ON si.show_id = sh.id"
|
." ON si.show_id = sh.id"
|
||||||
." WHERE (st.starts >= TIMESTAMP '$p_fromDateTime')"
|
." WHERE (st.ends >= TIMESTAMP '$p_currentDateTime')"
|
||||||
." AND (st.ends <= TIMESTAMP '$p_toDateTime')"
|
." AND (st.ends <= TIMESTAMP '$p_toDateTime')"
|
||||||
//next line makes sure that we aren't returning items that
|
//next line makes sure that we aren't returning items that
|
||||||
//are past the show's scheduled timeslot.
|
//are past the show's scheduled timeslot.
|
||||||
|
@ -627,24 +628,16 @@ class Schedule {
|
||||||
* @param string $p_toDateTime
|
* @param string $p_toDateTime
|
||||||
* In the format "YYYY-MM-DD-HH-mm-SS"
|
* In the format "YYYY-MM-DD-HH-mm-SS"
|
||||||
*/
|
*/
|
||||||
public static function ExportRangeAsJson($p_fromDateTime = null , $p_toDateTime = null)
|
public static function GetScheduledPlaylists()
|
||||||
{
|
{
|
||||||
global $CC_CONFIG, $CC_DBC;
|
global $CC_CONFIG, $CC_DBC;
|
||||||
|
|
||||||
if (is_null($p_fromDateTime)) {
|
$t1 = new DateTime();
|
||||||
$t1 = new DateTime();
|
$range_start = $t1->format("Y-m-d H:i:s");
|
||||||
$t1->sub(new DateInterval("PT24H"));
|
|
||||||
$range_start = $t1->format("Y-m-d H:i:s");
|
$t2 = new DateTime();
|
||||||
} else {
|
$t2->add(new DateInterval("PT24H"));
|
||||||
$range_start = Schedule::PypoTimeToAirtimeTime($p_fromDateTime);
|
$range_end = $t2->format("Y-m-d H:i:s");
|
||||||
}
|
|
||||||
if (is_null($p_fromDateTime)) {
|
|
||||||
$t2 = new DateTime();
|
|
||||||
$t2->add(new DateInterval("PT24H"));
|
|
||||||
$range_end = $t2->format("Y-m-d H:i:s");
|
|
||||||
} else {
|
|
||||||
$range_end = Schedule::PypoTimeToAirtimeTime($p_toDateTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scheduler wants everything in a playlist
|
// Scheduler wants everything in a playlist
|
||||||
$data = Schedule::GetItems($range_start, $range_end, true);
|
$data = Schedule::GetItems($range_start, $range_end, true);
|
||||||
|
@ -720,25 +713,5 @@ class Schedule {
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove all items from the schedule in the given range.
|
|
||||||
*
|
|
||||||
* @param string $p_start
|
|
||||||
* In the format YYYY-MM-DD HH:MM:SS.nnnnnn
|
|
||||||
* @param string $p_end
|
|
||||||
* In the format YYYY-MM-DD HH:MM:SS.nnnnnn
|
|
||||||
*/
|
|
||||||
public static function RemoveItemsInRange($p_start, $p_end)
|
|
||||||
{
|
|
||||||
$items = Schedule::GetItems($p_start, $p_end);
|
|
||||||
foreach ($items as $item) {
|
|
||||||
$scheduleGroup = new ScheduleGroup($item["group_id"]);
|
|
||||||
$scheduleGroup->remove();
|
|
||||||
}
|
|
||||||
RabbitMq::PushSchedule();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,6 +110,7 @@ class SchedulerTests extends PHPUnit_TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
function testGetItems() {
|
function testGetItems() {
|
||||||
$i1 = new ScheduleGroup();
|
$i1 = new ScheduleGroup();
|
||||||
$groupId1 = $i1->add('2008-01-01 12:00:00.000', $this->storedFile->getId());
|
$groupId1 = $i1->add('2008-01-01 12:00:00.000', $this->storedFile->getId());
|
||||||
|
@ -123,5 +124,6 @@ class SchedulerTests extends PHPUnit_TestCase {
|
||||||
$i1->remove();
|
$i1->remove();
|
||||||
$i2->remove();
|
$i2->remove();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -189,30 +189,10 @@ class AirTimeApiClient(ApiClientInterface):
|
||||||
|
|
||||||
def get_schedule(self, start=None, end=None):
|
def get_schedule(self, start=None, end=None):
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
"""
|
|
||||||
calculate start/end time range (format: YYYY-DD-MM-hh-mm-ss,YYYY-DD-MM-hh-mm-ss)
|
|
||||||
(seconds are ignored, just here for consistency)
|
|
||||||
"""
|
|
||||||
tnow = time.localtime(time.time())
|
|
||||||
if (not start):
|
|
||||||
tstart = time.localtime(time.time() - 3600 * int(self.config["cache_for"]))
|
|
||||||
start = "%04d-%02d-%02d-%02d-%02d" % (tstart[0], tstart[1], tstart[2], tstart[3], tstart[4])
|
|
||||||
|
|
||||||
if (not end):
|
|
||||||
tend = time.localtime(time.time() + 3600 * int(self.config["prepare_ahead"]))
|
|
||||||
end = "%04d-%02d-%02d-%02d-%02d" % (tend[0], tend[1], tend[2], tend[3], tend[4])
|
|
||||||
|
|
||||||
range = {}
|
|
||||||
range['start'] = start
|
|
||||||
range['end'] = end
|
|
||||||
|
|
||||||
# Construct the URL
|
# Construct the URL
|
||||||
export_url = self.config["base_url"] + self.config["api_base"] + self.config["export_url"]
|
export_url = self.config["base_url"] + self.config["api_base"] + self.config["export_url"]
|
||||||
|
|
||||||
# Insert the start and end times into the URL
|
|
||||||
export_url = export_url.replace('%%from%%', range['start'])
|
|
||||||
export_url = export_url.replace('%%to%%', range['end'])
|
|
||||||
logger.info("Fetching schedule from %s", export_url)
|
logger.info("Fetching schedule from %s", export_url)
|
||||||
export_url = export_url.replace('%%api_key%%', self.config["api_key"])
|
export_url = export_url.replace('%%api_key%%', self.config["api_key"])
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ version_url = 'version/api_key/%%api_key%%'
|
||||||
# Schedule export path.
|
# Schedule export path.
|
||||||
# %%from%% - starting date/time in the form YYYY-MM-DD-hh-mm
|
# %%from%% - starting date/time in the form YYYY-MM-DD-hh-mm
|
||||||
# %%to%% - starting date/time in the form YYYY-MM-DD-hh-mm
|
# %%to%% - starting date/time in the form YYYY-MM-DD-hh-mm
|
||||||
export_url = 'schedule/api_key/%%api_key%%/from/%%from%%/to/%%to%%'
|
export_url = 'schedule/api_key/%%api_key%%'
|
||||||
|
|
||||||
# Update whether a schedule group has begun playing.
|
# Update whether a schedule group has begun playing.
|
||||||
update_item_url = 'notify-schedule-group-play/api_key/%%api_key%%/schedule_id/%%schedule_id%%'
|
update_item_url = 'notify-schedule-group-play/api_key/%%api_key%%/schedule_id/%%schedule_id%%'
|
||||||
|
|
|
@ -79,7 +79,7 @@ $endTime = date("Y-m-d H:i:s", time()+(60*60));
|
||||||
|
|
||||||
echo "Removing everything from the scheduler between $startTime and $endTime...";
|
echo "Removing everything from the scheduler between $startTime and $endTime...";
|
||||||
// Scheduler: remove any playlists for the next hour
|
// Scheduler: remove any playlists for the next hour
|
||||||
Schedule::RemoveItemsInRange($startTime, $endTime);
|
//Schedule::RemoveItemsInRange($startTime, $endTime);
|
||||||
// Check for succcess
|
// Check for succcess
|
||||||
$scheduleClear = Schedule::isScheduleEmptyInRange($startTime, "01:00:00");
|
$scheduleClear = Schedule::isScheduleEmptyInRange($startTime, "01:00:00");
|
||||||
if (!$scheduleClear) {
|
if (!$scheduleClear) {
|
||||||
|
|
Loading…
Reference in New Issue