CC-3336: Refactor schedule API used by pypo
-make sure that empty arrays are objects and not arrays -clean up some comments
This commit is contained in:
parent
1d02c56874
commit
b572b26b68
|
@ -287,8 +287,8 @@ class ApiController extends Zend_Controller_Action
|
||||||
|
|
||||||
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
|
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
|
||||||
|
|
||||||
$result = Application_Model_Schedule::GetScheduledPlaylists();
|
$data = Application_Model_Schedule::GetScheduledPlaylists();
|
||||||
echo json_encode($result);
|
echo json_encode($data, JSON_FORCE_OBJECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function notifyMediaItemStartPlayAction()
|
public function notifyMediaItemStartPlayAction()
|
||||||
|
|
|
@ -48,11 +48,16 @@ class PypoFetch(Thread):
|
||||||
self.cache_dir = os.path.join(config["cache_dir"], "scheduler")
|
self.cache_dir = os.path.join(config["cache_dir"], "scheduler")
|
||||||
logger.debug("Cache dir %s", self.cache_dir)
|
logger.debug("Cache dir %s", self.cache_dir)
|
||||||
try:
|
try:
|
||||||
if not os.path.exists(dir):
|
if not os.path.isdir(dir):
|
||||||
|
"""
|
||||||
|
We get here if path does not exist, or path does exist but
|
||||||
|
is a file. We are not handling the second case, but don't
|
||||||
|
think we actually care about handling it.
|
||||||
|
"""
|
||||||
logger.debug("Cache dir does not exist. Creating...")
|
logger.debug("Cache dir does not exist. Creating...")
|
||||||
os.makedirs(dir)
|
os.makedirs(dir)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.error(e)
|
pass
|
||||||
|
|
||||||
self.schedule_data = []
|
self.schedule_data = []
|
||||||
self.logger.info("PypoFetch: init complete")
|
self.logger.info("PypoFetch: init complete")
|
||||||
|
@ -276,6 +281,9 @@ class PypoFetch(Thread):
|
||||||
- runs the cleanup routine, to get rid of unused cached files
|
- runs the cleanup routine, to get rid of unused cached files
|
||||||
"""
|
"""
|
||||||
def process_schedule(self, schedule_data, bootstrapping):
|
def process_schedule(self, schedule_data, bootstrapping):
|
||||||
|
|
||||||
|
self.logger.debug(schedule_data)
|
||||||
|
|
||||||
media = schedule_data["media"]
|
media = schedule_data["media"]
|
||||||
|
|
||||||
# Download all the media and put playlists in liquidsoap "annotate" format
|
# Download all the media and put playlists in liquidsoap "annotate" format
|
||||||
|
@ -284,12 +292,12 @@ class PypoFetch(Thread):
|
||||||
except Exception, e: self.logger.error("%s", e)
|
except Exception, e: self.logger.error("%s", e)
|
||||||
|
|
||||||
# Send the data to pypo-push
|
# Send the data to pypo-push
|
||||||
scheduled_data = dict()
|
|
||||||
|
self.logger.debug("Pushing to pypo-push: "+ str(media))
|
||||||
scheduled_data['liquidsoap_annotation_queue'] = liquidsoap_annotation_queue
|
|
||||||
self.push_queue.put(media)
|
self.push_queue.put(media)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
TODO
|
||||||
# cleanup
|
# cleanup
|
||||||
try: self.cleanup()
|
try: self.cleanup()
|
||||||
except Exception, e: self.logger.error("%s", e)
|
except Exception, e: self.logger.error("%s", e)
|
||||||
|
@ -309,7 +317,7 @@ class PypoFetch(Thread):
|
||||||
media_item = media[mkey]
|
media_item = media[mkey]
|
||||||
|
|
||||||
if bootstrapping:
|
if bootstrapping:
|
||||||
check_for_crash(media_item)
|
check_for_previous_crash(media_item)
|
||||||
|
|
||||||
# create playlist directory
|
# create playlist directory
|
||||||
try:
|
try:
|
||||||
|
@ -356,7 +364,7 @@ class PypoFetch(Thread):
|
||||||
entry['annotate'] = pl_entry
|
entry['annotate'] = pl_entry
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
def check_for_crash(media_item):
|
def check_for_previous_crash(media_item):
|
||||||
start = media_item['start']
|
start = media_item['start']
|
||||||
end = media_item['end']
|
end = media_item['end']
|
||||||
|
|
||||||
|
@ -453,9 +461,6 @@ class PypoFetch(Thread):
|
||||||
|
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
try: os.mkdir(self.cache_dir)
|
|
||||||
except Exception, e: pass
|
|
||||||
|
|
||||||
# Bootstrap: since we are just starting up, we need to grab the
|
# Bootstrap: since we are just starting up, we need to grab the
|
||||||
# most recent schedule. After that we can just wait for updates.
|
# most recent schedule. After that we can just wait for updates.
|
||||||
success, self.schedule_data = self.api_client.get_schedule()
|
success, self.schedule_data = self.api_client.get_schedule()
|
||||||
|
@ -470,23 +475,16 @@ class PypoFetch(Thread):
|
||||||
message = self.fetch_queue.get(block=True, timeout=3600)
|
message = self.fetch_queue.get(block=True, timeout=3600)
|
||||||
self.handle_message(message)
|
self.handle_message(message)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
"""
|
|
||||||
There is a problem with the RabbitMq messenger service. Let's
|
|
||||||
log the error and get the schedule via HTTP polling
|
|
||||||
"""
|
|
||||||
self.logger.error("Exception, %s", e)
|
self.logger.error("Exception, %s", e)
|
||||||
|
|
||||||
status, self.schedule_data = self.api_client.get_schedule()
|
success, self.schedule_data = self.api_client.get_schedule()
|
||||||
if status == 1:
|
if success:
|
||||||
self.process_schedule(self.schedule_data, False)
|
self.process_schedule(self.schedule_data, False)
|
||||||
|
|
||||||
loops += 1
|
loops += 1
|
||||||
|
|
||||||
"""
|
|
||||||
Main loop of the thread:
|
|
||||||
Wait for schedule updates from RabbitMQ, but in case there arent any,
|
|
||||||
poll the server to get the upcoming schedule.
|
|
||||||
"""
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while True:
|
"""
|
||||||
self.main()
|
Entry point of the thread
|
||||||
|
"""
|
||||||
|
self.main()
|
||||||
|
|
Loading…
Reference in New Issue