cc-4105: Removed wrong error handling from api_client. Split up controller action to make it reusable through other actions
This commit is contained in:
parent
ebd12448ee
commit
a1c205edff
2 changed files with 42 additions and 18 deletions
|
@ -387,15 +387,18 @@ class ApiController extends Zend_Controller_Action
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function uploadRecordedAction()
|
public function uploadRecordAction() {
|
||||||
{
|
|
||||||
//this file id is the recording for this show instance.
|
|
||||||
$show_instance_id = $this->_getParam('showinstanceid');
|
$show_instance_id = $this->_getParam('showinstanceid');
|
||||||
$file_id = $this->_getParam('fileid');
|
$file_id = $this->_getParam('fileid');
|
||||||
|
|
||||||
$this->view->fileid = $file_id;
|
$this->view->fileid = $file_id;
|
||||||
$this->view->showinstanceid = $show_instance_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;
|
$showCanceled = false;
|
||||||
$file = Application_Model_StoredFile::Recall($file_id);
|
$file = Application_Model_StoredFile::Recall($file_id);
|
||||||
//$show_instance = $this->_getParam('show_instance');
|
//$show_instance = $this->_getParam('show_instance');
|
||||||
|
@ -531,9 +534,18 @@ class ApiController extends Zend_Controller_Action
|
||||||
$mode = $info_json['mode'];
|
$mode = $info_json['mode'];
|
||||||
unset( $info_json['mode'] );
|
unset( $info_json['mode'] );
|
||||||
// TODO : uncomment the following line to actually do something
|
// 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
|
// 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 );
|
Logging::log( $info_json );
|
||||||
|
|
||||||
}
|
}
|
||||||
die(json_encode( array('successes' => 19, 'fails' => 123) ));
|
die(json_encode( array('successes' => 19, 'fails' => 123) ));
|
||||||
}
|
}
|
||||||
|
|
|
@ -363,7 +363,14 @@ class AirTimeApiClient():
|
||||||
|
|
||||||
return response
|
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
|
logger = self.logger
|
||||||
try:
|
try:
|
||||||
url = self.construct_url('reload_metadata_group')
|
url = self.construct_url('reload_metadata_group')
|
||||||
|
@ -379,28 +386,33 @@ class AirTimeApiClient():
|
||||||
if not 'mode' in action:
|
if not 'mode' in action:
|
||||||
self.logger.debug("Warning: Sending a request element without a 'mode'")
|
self.logger.debug("Warning: Sending a request element without a 'mode'")
|
||||||
self.logger.debug("Here is the the request: '%s'" % str(action) )
|
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))
|
md_list = dict((i, json.dumps(convert_dict_value_to_utf8(md))) for i,md in enumerate(valid_actions))
|
||||||
|
|
||||||
data = urllib.urlencode(md_list)
|
data = urllib.urlencode(md_list)
|
||||||
req = urllib2.Request(url, data)
|
req = urllib2.Request(url, data)
|
||||||
response = self.get_response_from_server(req)
|
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)
|
response = json.loads(response)
|
||||||
# TODO : this request returns a more detailed response of what
|
# TODO : this request returns a more detailed response of what
|
||||||
# happened through a json array. Hence we should handle errors
|
# happened through a json array. Hence we should handle errors
|
||||||
# differently
|
# differently
|
||||||
if("error" not in response and is_record):
|
# we would like to move all of this to the controller since we are
|
||||||
url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["upload_recorded"])
|
# not doing anything here
|
||||||
url = url.replace("%%fileid%%", str(response[u'id']))
|
#if("error" not in response and is_record):
|
||||||
url = url.replace("%%showinstanceid%%", str(md_list['MDATA_KEY_TRACKNUMBER']))
|
#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("%%api_key%%", self.config["api_key"])
|
#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 = self.get_response_from_server(url)
|
||||||
response = json.loads(response)
|
#response = json.loads(response)
|
||||||
logger.info("associate recorded %s", response)
|
#logger.info("associate recorded %s", response)
|
||||||
return response
|
return response
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.error('Exception: %s', e)
|
logger.error('Exception: %s', e)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue