Merge branch 'saas-dev' into saas-installer-albert
Conflicts: python_apps/api_clients/api_clients/api_client.py
This commit is contained in:
commit
01ea6f27ae
11 changed files with 128 additions and 81 deletions
|
@ -85,6 +85,7 @@ api_config['get_files_without_silan_value'] = 'get-files-without-silan-value/api
|
|||
api_config['update_cue_values_by_silan'] = 'update-cue-values-by-silan/api_key/%%api_key%%'
|
||||
api_config['api_base'] = 'api'
|
||||
api_config['bin_dir'] = '/usr/lib/airtime/api_clients/'
|
||||
api_config['update_metadata_on_tunein'] = 'update-metadata-on-tunein/api_key/%%api_key%%'
|
||||
|
||||
|
||||
|
||||
|
@ -532,6 +533,9 @@ class AirtimeApiClient(object):
|
|||
#TODO
|
||||
self.logger.error(str(e))
|
||||
|
||||
def update_metadata_on_tunein(self):
|
||||
self.services.update_metadata_on_tunein()
|
||||
|
||||
|
||||
class InvalidContentType(Exception):
|
||||
pass
|
||||
|
|
|
@ -14,7 +14,7 @@ import traceback
|
|||
import pure
|
||||
|
||||
from Queue import Empty
|
||||
from threading import Thread
|
||||
from threading import Thread, Timer
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
from api_clients import api_client
|
||||
|
@ -441,6 +441,12 @@ class PypoFetch(Thread):
|
|||
|
||||
return success
|
||||
|
||||
# This function makes a request to Airtime to see if we need to
|
||||
# push metadata to TuneIn. We have to do this because TuneIn turns
|
||||
# off metadata if it does not receive a request every 5 minutes.
|
||||
def update_metadata_on_tunein(self):
|
||||
self.api_client.update_metadata_on_tunein()
|
||||
Timer(120, self.update_metadata_on_tunein).start()
|
||||
|
||||
def main(self):
|
||||
#Make sure all Liquidsoap queues are empty. This is important in the
|
||||
|
@ -452,8 +458,10 @@ class PypoFetch(Thread):
|
|||
|
||||
self.set_bootstrap_variables()
|
||||
|
||||
self.update_metadata_on_tunein()
|
||||
|
||||
# Bootstrap: since we are just starting up, we need to grab the
|
||||
# most recent schedule. After that we fetch the schedule every 30
|
||||
# most recent schedule. After that we fetch the schedule every 8
|
||||
# minutes or wait for schedule updates to get pushed.
|
||||
success = self.persistent_manual_schedule_fetch(max_attempts=5)
|
||||
|
||||
|
@ -463,6 +471,7 @@ class PypoFetch(Thread):
|
|||
loops = 1
|
||||
while True:
|
||||
self.logger.info("Loop #%s", loops)
|
||||
manual_fetch_needed = False
|
||||
try:
|
||||
"""
|
||||
our simple_queue.get() requires a timeout, in which case we
|
||||
|
@ -478,17 +487,26 @@ class PypoFetch(Thread):
|
|||
Currently we are checking every POLL_INTERVAL seconds
|
||||
"""
|
||||
|
||||
|
||||
message = self.fetch_queue.get(block=True, timeout=self.listener_timeout)
|
||||
manual_fetch_needed = False
|
||||
self.handle_message(message)
|
||||
except Empty, e:
|
||||
except Empty as e:
|
||||
self.logger.info("Queue timeout. Fetching schedule manually")
|
||||
self.persistent_manual_schedule_fetch(max_attempts=5)
|
||||
except Exception, e:
|
||||
manual_fetch_needed = True
|
||||
except Exception as e:
|
||||
top = traceback.format_exc()
|
||||
self.logger.error('Exception: %s', e)
|
||||
self.logger.error("traceback: %s", top)
|
||||
|
||||
try:
|
||||
if manual_fetch_needed:
|
||||
self.persistent_manual_schedule_fetch(max_attempts=5)
|
||||
except Exception as e:
|
||||
top = traceback.format_exc()
|
||||
self.logger.error('Failed to manually fetch the schedule.')
|
||||
self.logger.error('Exception: %s', e)
|
||||
self.logger.error("traceback: %s", top)
|
||||
|
||||
loops += 1
|
||||
|
||||
def run(self):
|
||||
|
@ -496,3 +514,4 @@ class PypoFetch(Thread):
|
|||
Entry point of the thread
|
||||
"""
|
||||
self.main()
|
||||
self.logger.info('PypoFetch thread exiting')
|
||||
|
|
|
@ -30,6 +30,7 @@ class PypoFile(Thread):
|
|||
self.media_queue = schedule_queue
|
||||
self.media = None
|
||||
self.cache_dir = os.path.join(config["cache_dir"], "scheduler")
|
||||
self._config = self.read_config_file(CONFIG_PATH)
|
||||
|
||||
def copy_file(self, media_item):
|
||||
"""
|
||||
|
@ -60,11 +61,9 @@ class PypoFile(Thread):
|
|||
if do_copy:
|
||||
self.logger.debug("copying from %s to local cache %s" % (src, dst))
|
||||
try:
|
||||
config = self.read_config_file(CONFIG_PATH)
|
||||
CONFIG_SECTION = "general"
|
||||
username = config.get(CONFIG_SECTION, 'api_key')
|
||||
|
||||
host = config.get(CONFIG_SECTION, 'base_url')
|
||||
username = self._config.get(CONFIG_SECTION, 'api_key')
|
||||
host = self._config.get(CONFIG_SECTION, 'base_url')
|
||||
url = "http://%s/rest/media/%s/download" % (host, media_item["id"])
|
||||
with open(dst, "wb") as handle:
|
||||
response = requests.get(url, auth=requests.auth.HTTPBasicAuth(username, ''), stream=True, verify=False)
|
||||
|
@ -205,3 +204,4 @@ class PypoFile(Thread):
|
|||
Entry point of the thread
|
||||
"""
|
||||
self.main()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue