|
12 | 12 | from django.db.models import Q
|
13 | 13 | from django.http import Http404, HttpResponse
|
14 | 14 | from ispyb.connector.mysqlsp.main import ISPyBMySQLSPConnector as Connector
|
15 |
| -from ispyb.connector.mysqlsp.main import ISPyBNoResultException |
| 15 | +from ispyb.exception import ISPyBConnectionException, ISPyBNoResultException |
16 | 16 | from rest_framework import viewsets
|
17 | 17 |
|
18 | 18 | from viewer.models import Project
|
@@ -102,16 +102,23 @@ def get_remote_conn(force_error_display=False) -> Optional[SSHConnector]:
|
102 | 102 | conn: Optional[SSHConnector] = None
|
103 | 103 | try:
|
104 | 104 | conn = SSHConnector(**credentials)
|
| 105 | + except ISPyBConnectionException: |
| 106 | + # Got SSH tunnel but the ISPyB connection failed |
| 107 | + PrometheusMetrics.new_tunnel() |
105 | 108 | except Exception:
|
| 109 | + # Any other exception will be a problem with the SSH tunnel connection |
| 110 | + PrometheusMetrics.failed_tunnel() |
106 | 111 | if logging.DEBUG >= logger.level or force_error_display:
|
107 | 112 | logger.info("credentials=%s", credentials)
|
108 | 113 | logger.exception("Got the following exception creating Connector...")
|
109 |
| - if conn: |
110 |
| - logger.debug("Got remote connector") |
| 114 | + else: |
| 115 | + # No exception - we must have created an SSH tunnel |
111 | 116 | PrometheusMetrics.new_tunnel()
|
| 117 | + |
| 118 | + if conn: |
| 119 | + logger.debug("Got remote ISPyB connector") |
112 | 120 | else:
|
113 |
| - logger.debug("Failed to get a remote connector") |
114 |
| - PrometheusMetrics.failed_tunnel() |
| 121 | + logger.debug("Failed to get a remote ISPyB connector") |
115 | 122 |
|
116 | 123 | return conn
|
117 | 124 |
|
|
0 commit comments