How to use the bioblend.ConnectionError function in bioblend

To help you get started, we’ve selected a few bioblend examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github galaxyproject / bioblend / bioblend / _tests / TestGalaxyInstance.py View on Github external
def test_get_retry(self):
        # We set the client to try twice, with a delay of 5 seconds between
        # attempts. So, we expect the call to take at least 5 seconds before
        # failing.
        self.gi.max_get_attempts = 2
        self.gi.get_retry_delay = 5
        start = time.time()
        try:
            self.gi.libraries.get_libraries()
            self.fail("Call to show_libraries should have raised a ConnectionError")
        except ConnectionError:
            end = time.time()
        duration = end - start
        self.assertGreater(duration, self.gi.get_retry_delay, "Didn't seem to retry long enough")
github refinery-platform / refinery-platform / refinery / tool_manager / test_utils.py View on Github external
def test_get_workflows_with_connection_error(self):
        with mock.patch.object(
            bioblend.galaxy.workflows.WorkflowClient,
            "get_workflows",
            side_effect=bioblend.ConnectionError("Bad Connection")
        ):
            with self.assertRaises(RuntimeError) as context:
                get_workflows()
            self.assertIn(
                "Unable to retrieve workflows from '{}'".format(
                    self.workflow_engine.instance.base_url
                ),
                str(context.exception)
            )
github refinery-platform / refinery-platform / refinery / tool_manager / tests.py View on Github external
                       side_effect=bioblend.ConnectionError("Bad connection"))
    def test_galaxy_cleanup_methods_are_called_on_bioblend_exception(
            self, invoke_workflow_mock):
        settings.REFINERY_GALAXY_ANALYSIS_CLEANUP = "always"

        self.create_tool(
            ToolDefinition.WORKFLOW,
            annotation_file_name="LIST:PAIR.json"
        )
        self.tool.update_galaxy_data(
            self.tool.GALAXY_IMPORT_HISTORY_DICT,
            {"id": self.GALAXY_ID_MOCK}
        )
        self.tool.update_galaxy_data(
            self.tool.COLLECTION_INFO,
            {"id": "coffee"}
        )
github galaxyproject / bioblend / bioblend / galaxy / histories / __init__.py View on Github external
else:
            if wait:
                maxwait = sys.maxsize
            else:
                maxwait = 0
        params = {
            'gzip': gzip,
            'include_hidden': include_hidden,
            'include_deleted': include_deleted,
        }
        url = '%s/exports' % self._make_url(history_id)
        time_left = maxwait
        while True:
            try:
                r = self._put(payload={}, url=url, params=params)
            except ConnectionError as e:
                if e.status_code == 202:  # export is not ready
                    if time_left > 0:
                        log.warning("Waiting for the export of history %s to complete. Will wait %i more s", history_id, time_left)
                        time.sleep(1)
                        time_left -= 1
                    else:
                        return ''
                else:
                    raise
            else:
                break
        jeha_id = r['download_url'].rsplit('/', 1)[-1]
        return jeha_id
github galaxyproject / bioblend / bioblend / galaxy / client.py View on Github external
def _delete(self, payload=None, id=None, deleted=False, contents=None, url=None, params=None):
        """
        Do a generic DELETE request, composing the url from the contents of the
        arguments. Alternatively, an explicit ``url`` can be provided to use
        for the request. ``payload`` must be a dict that contains additional
        request arguments which will be sent along with the request body.

        :return: The decoded response.
        """
        if not url:
            url = self._make_url(module_id=id, deleted=deleted, contents=contents)
        r = self.gi.make_delete_request(url, payload=payload, params=params)
        if r.status_code == 200:
            return r.json()
        # @see self.body for HTTP response body
        raise ConnectionError("Unexpected HTTP status code: %s" % r.status_code,
                              body=r.text, status_code=r.status_code)
github galaxyproject / bioblend / bioblend / galaxyclient.py View on Github external
params['key'] = self.key
        else:
            params = self.default_params

        payload = json.dumps(payload)
        headers = self.json_headers
        r = requests.put(url, data=payload, params=params, headers=headers,
                         verify=self.verify, timeout=self.timeout)
        if r.status_code == 200:
            try:
                return r.json()
            except Exception as e:
                raise ConnectionError("Request was successful, but cannot decode the response content: %s" %
                                      e, body=r.content, status_code=r.status_code)
        # @see self.body for HTTP response body
        raise ConnectionError("Unexpected HTTP status code: %s" % r.status_code,
                              body=r.text, status_code=r.status_code)
github refinery-platform / refinery-platform / refinery / tool_manager / models.py View on Github external
def func_wrapper(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except bioblend.ConnectionError as e:
            error_message = (
                "Error while interacting with bioblend: {}".format(e)
            )
            logger.error(error_message)
            args[0].analysis.cancel()
            return
    return func_wrapper
github galaxyproject / bioblend / bioblend / galaxyclient.py View on Github external
else:
            payload = json.dumps(payload)
            headers = self.json_headers
            post_params = params

        r = requests.post(url, data=payload, headers=headers,
                          verify=self.verify, params=post_params,
                          timeout=self.timeout)
        if r.status_code == 200:
            try:
                return r.json()
            except Exception as e:
                raise ConnectionError("Request was successful, but cannot decode the response content: %s" %
                                      e, body=r.content, status_code=r.status_code)
        # @see self.body for HTTP response body
        raise ConnectionError("Unexpected HTTP status code: %s" % r.status_code,
                              body=r.text, status_code=r.status_code)
github galaxyproject / ephemeris / src / ephemeris / install_tool_deps.py View on Github external
def _install(tool_client, tool_id):
    try:
        tool_client.install_dependencies(tool_id)
    except ConnErr as e:
        if e.status_code in timeout_codes:
            log.warning(e.body)
        else:
            raise