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):
|
||||
logger = logging.getLogger()
|
||||
response = ''
|
||||
response = None
|
||||
try:
|
||||
url = self.config["base_url"] + self.config["api_base"] + self.config["show_schedule_url"]
|
||||
logger.debug(url)
|
||||
|
@ -301,23 +301,37 @@ class AirTimeApiClient(ApiClientInterface):
|
|||
except Exception, e:
|
||||
logger.error("Exception: %s", e)
|
||||
|
||||
return response[u'shows']
|
||||
return response
|
||||
|
||||
def upload_recorded_show(self, data, headers):
|
||||
logger = logging.getLogger()
|
||||
response = ''
|
||||
try:
|
||||
url = self.config["base_url"] + self.config["api_base"] + self.config["upload_file_url"]
|
||||
logger.debug(url)
|
||||
url = url.replace("%%api_key%%", self.config["api_key"])
|
||||
retries = int(self.config["upload_retries"])
|
||||
retries_wait = int(self.config["upload_wait"])
|
||||
|
||||
request = urllib2.Request(url, data, headers)
|
||||
response = urllib2.urlopen(request).read().strip()
|
||||
url = self.config["base_url"] + self.config["api_base"] + self.config["upload_file_url"]
|
||||
logger.debug(url)
|
||||
url = url.replace("%%api_key%%", self.config["api_key"])
|
||||
|
||||
logger.info("uploaded show result %s", response)
|
||||
|
||||
except Exception, e:
|
||||
logger.error("Exception: %s", e)
|
||||
for i in range(0, retries):
|
||||
logger.debug("Upload attempt: %s", i+1)
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -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
|
||||
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(" ", "-")
|
||||
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(" ")
|
||||
|
||||
print "starting record"
|
||||
|
@ -145,6 +145,10 @@ class Record():
|
|||
def get_shows(self):
|
||||
|
||||
shows = self.api_client.get_shows_to_record()
|
||||
if shows is not None:
|
||||
shows = shows[u'shows']
|
||||
else:
|
||||
shows = []
|
||||
|
||||
if len(shows):
|
||||
self.process_shows(shows)
|
||||
|
|
Loading…
Reference in New Issue