Cleaned the shit out of RequestSync. Removed old comments and useless code
This commit is contained in:
parent
86b262ed8f
commit
289d5575ec
|
@ -28,7 +28,6 @@ class RequestSync(Loggable):
|
||||||
to airtime. In the process it packs the requests and retries for
|
to airtime. In the process it packs the requests and retries for
|
||||||
some number of times
|
some number of times
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_with_api_client(cls, watcher, requests):
|
def create_with_api_client(cls, watcher, requests):
|
||||||
apiclient = ac.AirtimeApiClient.create_right_config()
|
apiclient = ac.AirtimeApiClient.create_right_config()
|
||||||
|
@ -39,17 +38,10 @@ class RequestSync(Loggable):
|
||||||
self.watcher = watcher
|
self.watcher = watcher
|
||||||
self.requests = requests
|
self.requests = requests
|
||||||
self.apiclient = apiclient
|
self.apiclient = apiclient
|
||||||
self.retries = 1
|
|
||||||
self.request_wait = 0.3
|
|
||||||
|
|
||||||
def run_request(self):
|
def run_request(self):
|
||||||
self.logger.info("Attempting request with %d items." %
|
self.logger.info("Attempting request with %d items." %
|
||||||
len(self.requests))
|
len(self.requests))
|
||||||
# Note that we must attach the appropriate mode to every
|
|
||||||
# response. Also Not forget to attach the 'is_record' to any
|
|
||||||
# requests that are related to recorded shows
|
|
||||||
# TODO : recorded shows aren't flagged right
|
|
||||||
# Is this retry shit even necessary? Consider getting rid of this.
|
|
||||||
packed_requests = []
|
packed_requests = []
|
||||||
for request_event in self.requests:
|
for request_event in self.requests:
|
||||||
try:
|
try:
|
||||||
|
@ -62,12 +54,7 @@ class RequestSync(Loggable):
|
||||||
if hasattr(request_event, 'path'):
|
if hasattr(request_event, 'path'):
|
||||||
self.logger.info("Possibly related to path: '%s'" %
|
self.logger.info("Possibly related to path: '%s'" %
|
||||||
request_event.path)
|
request_event.path)
|
||||||
def make_req():
|
try: self.apiclient.send_media_monitor_requests( packed_requests )
|
||||||
self.apiclient.send_media_monitor_requests( packed_requests )
|
|
||||||
# TODO : none of the shit below is necessary. get rid of it
|
|
||||||
# eventually
|
|
||||||
for try_index in range(0,self.retries):
|
|
||||||
try: make_req()
|
|
||||||
# most likely we did not get json response as we expected
|
# most likely we did not get json response as we expected
|
||||||
except ValueError:
|
except ValueError:
|
||||||
self.logger.info("ApiController.php probably crashed, we \
|
self.logger.info("ApiController.php probably crashed, we \
|
||||||
|
@ -75,14 +62,9 @@ class RequestSync(Loggable):
|
||||||
valid json")
|
valid json")
|
||||||
self.logger.info("Trying again after %f seconds" %
|
self.logger.info("Trying again after %f seconds" %
|
||||||
self.request_wait)
|
self.request_wait)
|
||||||
time.sleep( self.request_wait )
|
|
||||||
except Exception as e: self.unexpected_exception(e)
|
except Exception as e: self.unexpected_exception(e)
|
||||||
else:
|
else:
|
||||||
self.logger.info("Request worked on the '%d' try" %
|
self.logger.info("Request was successful")
|
||||||
(try_index + 1))
|
|
||||||
break
|
|
||||||
else: self.logger.info("Failed to send request after '%d' tries..." %
|
|
||||||
self.retries)
|
|
||||||
self.watcher.flag_done() # poor man's condition variable
|
self.watcher.flag_done() # poor man's condition variable
|
||||||
|
|
||||||
class TimeoutWatcher(threading.Thread,Loggable):
|
class TimeoutWatcher(threading.Thread,Loggable):
|
||||||
|
|
Loading…
Reference in New Issue