CC-2124 : Rebroadcast: Retry upload to Airtime on failed upload
added configurable number of upload retries as well as length between retries.
This commit is contained in:
parent
5100613049
commit
4bdd8d425d
|
@ -288,7 +288,7 @@ class AirTimeApiClient(ApiClientInterface):
|
||||||
|
|
||||||
def get_shows_to_record(self):
|
def get_shows_to_record(self):
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
response = ''
|
response = None
|
||||||
try:
|
try:
|
||||||
url = self.config["base_url"] + self.config["api_base"] + self.config["show_schedule_url"]
|
url = self.config["base_url"] + self.config["api_base"] + self.config["show_schedule_url"]
|
||||||
logger.debug(url)
|
logger.debug(url)
|
||||||
|
@ -301,23 +301,37 @@ class AirTimeApiClient(ApiClientInterface):
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.error("Exception: %s", e)
|
logger.error("Exception: %s", e)
|
||||||
|
|
||||||
return response[u'shows']
|
return response
|
||||||
|
|
||||||
def upload_recorded_show(self, data, headers):
|
def upload_recorded_show(self, data, headers):
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
response = ''
|
response = ''
|
||||||
try:
|
retries = int(self.config["upload_retries"])
|
||||||
url = self.config["base_url"] + self.config["api_base"] + self.config["upload_file_url"]
|
retries_wait = int(self.config["upload_wait"])
|
||||||
logger.debug(url)
|
|
||||||
url = url.replace("%%api_key%%", self.config["api_key"])
|
|
||||||
|
|
||||||
request = urllib2.Request(url, data, headers)
|
url = self.config["base_url"] + self.config["api_base"] + self.config["upload_file_url"]
|
||||||
response = urllib2.urlopen(request).read().strip()
|
logger.debug(url)
|
||||||
|
url = url.replace("%%api_key%%", self.config["api_key"])
|
||||||
|
|
||||||
logger.info("uploaded show result %s", response)
|
for i in range(0, retries):
|
||||||
|
logger.debug("Upload attempt: %s", i+1)
|
||||||
except Exception, e:
|
|
||||||
logger.error("Exception: %s", e)
|
try:
|
||||||
|
request = urllib2.Request(url, data, headers)
|
||||||
|
response = urllib2.urlopen(request).read().strip()
|
||||||
|
|
||||||
|
logger.info("uploaded show result %s", response)
|
||||||
|
break
|
||||||
|
|
||||||
|
except urllib2.HTTPError, e:
|
||||||
|
logger.error("Http error code: %s", e.code)
|
||||||
|
except urllib2.URLError, e:
|
||||||
|
logger.error("Server is down: %s", e.args)
|
||||||
|
except Exception, e:
|
||||||
|
logger.error("Exception: %s", e)
|
||||||
|
|
||||||
|
#wait some time before next retry
|
||||||
|
time.sleep(retries_wait)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
|
@ -20,3 +20,9 @@ show_schedule_url = 'recorded-shows/format/json/api_key/%%api_key%%'
|
||||||
|
|
||||||
# URL to upload the recorded show's file to Airtime
|
# URL to upload the recorded show's file to Airtime
|
||||||
upload_file_url = 'upload-recorded/format/json/api_key/%%api_key%%'
|
upload_file_url = 'upload-recorded/format/json/api_key/%%api_key%%'
|
||||||
|
|
||||||
|
#number of retries to upload file if connection problem
|
||||||
|
upload_retries = 3
|
||||||
|
|
||||||
|
#time to wait between attempts to upload file if connection problem (in seconds)
|
||||||
|
upload_wait = 60
|
||||||
|
|
|
@ -61,7 +61,7 @@ class ShowRecorder(Thread):
|
||||||
filename = self.filename.replace(" ", "-")
|
filename = self.filename.replace(" ", "-")
|
||||||
filepath = "%s%s.%s" % (config["base_recorded_files"], filename, self.filetype)
|
filepath = "%s%s.%s" % (config["base_recorded_files"], filename, self.filetype)
|
||||||
|
|
||||||
command = "ecasound -i alsa -o %s -t:%s -ge:3,1,0,-1" % (filepath, length)
|
command = "ecasound -i alsa -o %s -t:%s -ge:5,1,0,-1" % (filepath, length)
|
||||||
args = command.split(" ")
|
args = command.split(" ")
|
||||||
|
|
||||||
print "starting record"
|
print "starting record"
|
||||||
|
@ -145,6 +145,10 @@ class Record():
|
||||||
def get_shows(self):
|
def get_shows(self):
|
||||||
|
|
||||||
shows = self.api_client.get_shows_to_record()
|
shows = self.api_client.get_shows_to_record()
|
||||||
|
if shows is not None:
|
||||||
|
shows = shows[u'shows']
|
||||||
|
else:
|
||||||
|
shows = []
|
||||||
|
|
||||||
if len(shows):
|
if len(shows):
|
||||||
self.process_shows(shows)
|
self.process_shows(shows)
|
||||||
|
|
Loading…
Reference in New Issue