From a1c205edff009516db5940be22b8f586f3b856b6 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 16 Jul 2012 16:43:48 -0400 Subject: [PATCH] cc-4105: Removed wrong error handling from api_client. Split up controller action to make it reusable through other actions --- .../application/controllers/ApiController.php | 22 ++++++++--- python_apps/api_clients/api_client.py | 38 ++++++++++++------- 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 8d32b32d5..c4ead7782 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -387,15 +387,18 @@ class ApiController extends Zend_Controller_Action } } - public function uploadRecordedAction() - { - //this file id is the recording for this show instance. + public function uploadRecordAction() { $show_instance_id = $this->_getParam('showinstanceid'); $file_id = $this->_getParam('fileid'); - $this->view->fileid = $file_id; $this->view->showinstanceid = $show_instance_id; + $this->uploadRecordActionParam($show_instance_id, $file_id); + } + // The paramterized version of the uploadRecordAction controller. We want this controller's action + // to be invokable from other controllers instead being of only through http + public function uploadRecordActionParam($show_instance_id, $file_id) + { $showCanceled = false; $file = Application_Model_StoredFile::Recall($file_id); //$show_instance = $this->_getParam('show_instance'); @@ -531,9 +534,18 @@ class ApiController extends Zend_Controller_Action $mode = $info_json['mode']; unset( $info_json['mode'] ); // TODO : uncomment the following line to actually do something - // array_push($responses, $this->dispatchMetaDataAction($info_json, $info_json['mode'])); + $response = $this->dispatchMetaDataAction($info_json, $info_json['mode']); + array_push($responses, $this->dispatchMetaDataAction($info_json, $info_json['mode'])); // Like wise, remove the following line when done + // On recorded show requests we do some extra work here. Not sure what it actually is and it + // was usually called from the python api + if( $info_json['is_record'] ) { + // TODO : must check for error in $response before proceeding... + $this->uploadRecordActionParam($info_json['showinstanceid'],$info_json['fileid']); + } + // TODO : Remove this line when done debugging this shit Logging::log( $info_json ); + } die(json_encode( array('successes' => 19, 'fails' => 123) )); } diff --git a/python_apps/api_clients/api_client.py b/python_apps/api_clients/api_client.py index 1cc1e26cc..94db6eddd 100644 --- a/python_apps/api_clients/api_client.py +++ b/python_apps/api_clients/api_client.py @@ -363,7 +363,14 @@ class AirTimeApiClient(): return response - def send_media_monitor_requests(self, action_list, is_record=False): + def send_media_monitor_requests(self, action_list): + """ + Send a gang of media monitor events at a time. actions_list is a list of dictionaries + where every dictionary is representing an action. Every action dict must contain a 'mode' + key that says what kind of action it is and an optional 'is_record' key that says whether + the show was recorded or not. The value of this key does not matter, only if it's present + or not. + """ logger = self.logger try: url = self.construct_url('reload_metadata_group') @@ -379,28 +386,33 @@ class AirTimeApiClient(): if not 'mode' in action: self.logger.debug("Warning: Sending a request element without a 'mode'") self.logger.debug("Here is the the request: '%s'" % str(action) ) - else: valid_actions.append(action) + else: + # We alias the value of is_record to true or false no + # matter what it is based on if it's absent in the action + if 'is_record' in action: + self.logger.debug("Sending a 'recorded' action") + action['is_record'] = True + else: action['is_record'] = False + valid_actions.append(action) md_list = dict((i, json.dumps(convert_dict_value_to_utf8(md))) for i,md in enumerate(valid_actions)) - data = urllib.urlencode(md_list) req = urllib2.Request(url, data) response = self.get_response_from_server(req) - # We no longer have a single mode for every http request. - #logger.info("update media %s, filepath: %s, mode: %s", response, md_list['MDATA_KEY_FILEPATH'], mode) response = json.loads(response) # TODO : this request returns a more detailed response of what # happened through a json array. Hence we should handle errors # differently - if("error" not in response and is_record): - url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["upload_recorded"]) - url = url.replace("%%fileid%%", str(response[u'id'])) - url = url.replace("%%showinstanceid%%", str(md_list['MDATA_KEY_TRACKNUMBER'])) - url = url.replace("%%api_key%%", self.config["api_key"]) + # we would like to move all of this to the controller since we are + # not doing anything here + #if("error" not in response and is_record): + #url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["upload_recorded"]) url = url.replace("%%fileid%%", str(response[u'id'])) + #url = url.replace("%%showinstanceid%%", str(md_list['MDATA_KEY_TRACKNUMBER'])) + #url = url.replace("%%api_key%%", self.config["api_key"]) - response = self.get_response_from_server(url) - response = json.loads(response) - logger.info("associate recorded %s", response) + #response = self.get_response_from_server(url) + #response = json.loads(response) + #logger.info("associate recorded %s", response) return response except Exception, e: logger.error('Exception: %s', e)