def _default_success_callback( self, response: FacebookResponse, request_index: int, object_id: int = None ): """ A method that can be used to log when the batch object has completed successfully. This is intended to be used as a default callback to fallback to in case a user does not provide one. :param response: Facebook response object. :param request_index: The index of the request in the whole batch. :param object_id: The ID of the object being updated. """ request = self._requests[request_index] batch_response = FacebookBatchResponse(request=request, response=response) self._responses[request_index] = batch_response self._errors[request_index] = None if object_id is None: object_id = response.json().get("id") logger.debug( "Request #{}: Object with id [{}] updated successfully!".format( request_index, str(object_id) ) )
def _default_failure_callback( self, response: FacebookResponse, request_index: int, object_id: int = None ): """ A method that can be used to raise exceptions when the batch object is used for bulk operations. This callback raises a custom FacebookAPIError. This is intended to be used as a default callback to fallback to in case a user does not provide one. :param response: Facebook response object. :param request_index: The index of the request in the whole batch. :param object_id: (Optional) The ID of the object being updated. """ request = self._requests[request_index] batch__error = FacebookBatchRequestError( request=request, request_error=response.error() ) self._responses[request_index] = None self._errors[request_index] = batch__error error_msg = ["#{} -".format(request_index)] if object_id: error_msg.append("Error updating object with id [{}].".format(object_id)) error_msg.append(str(batch__error)) logger.error(" ".join(error_msg))
def _update_insights_throttle_limit(self, response: FacebookResponse): """ For /insights call every response contains x-fb-ads-insights-throttle header representing current throttle limit parameter for async insights jobs for current app/account. We need this information to adjust number of running async jobs for optimal performance. """ ads_insights_throttle = response.headers().get( "x-fb-ads-insights-throttle") if ads_insights_throttle: ads_insights_throttle = json.loads(ads_insights_throttle) self._ads_insights_throttle = self.Throttle( per_application=ads_insights_throttle.get( "app_id_util_pct", 0), per_account=ads_insights_throttle.get("acc_id_util_pct", 0), )
def failure(response: FacebookResponse): raise response.error()
def success(response: FacebookResponse): records.append(response.json())
def _batch_success_handler(self, response: FacebookResponse): """Update job status from response""" self._job = ObjectParser(reuse_object=self._job).parse_single(response.json()) self._check_status()