コード例 #1
0
    def _post(self,
              resource,
              data,
              query_id=None,
              subcategory=None,
              second_query_id=None,
              **options):
        """Queries the REST service and returns the result"""

        if isinstance(query_id, list):
            query_id = ','.join(query_id)

        response = execute(host=self._configuration.host,
                           version=self._configuration.version,
                           sid=self.session_id,
                           category=self._category,
                           method='post',
                           data=data,
                           subcategory=subcategory,
                           query_id=query_id,
                           second_query_id=second_query_id,
                           resource=resource,
                           options=options)

        return OpenCGAResponseList(response, query_id)
コード例 #2
0
    def _rest_retry(self, method, resource, query_id=None, subcategory=None,
                    second_query_id=None, data=None, **options):
        """Invokes the specified HTTP method, with retries if they are specified in the configuration
        :return: an instance of OpenCGAResponseList"""

        query_ids_str = self._get_query_id_str(query_id)

        def exec_retry():
            return execute(host=self._cfg.host,
                           version=self._cfg.version,
                           sid=self.session_id,
                           category=self._category,
                           subcategory=subcategory,
                           method=method,
                           query_id=query_ids_str,
                           second_query_id=second_query_id,
                           resource=resource,
                           data=data,
                           options=options)

        def notify_retry(exc_type, exc_val, exc_tb):
            if self.on_retry:
                self.on_retry(self, exc_type, exc_val, exc_tb, dict(
                    method=method, resource=resource, query_id=query_id,
                    category=self._category, subcategory=subcategory,
                    second_query_id=second_query_id, data=data,
                    options=options
                ))

        response = retry(
            exec_retry, self._cfg.max_attempts, self._cfg.min_retry_secs, self._cfg.max_retry_secs,
            login_handler=self._client_login_handler if self.login_handler else None,
            on_retry=notify_retry)

        return OpenCGAResponseList(response, query_ids_str)