Generic function to get server stats based on an SQL template Args: sid: The server ID did: The database ID template: The SQL template name check_long_running_query: Returns:
(sid, did, template, check_long_running_query=False,
only_data=False)
| 319 | |
| 320 | |
| 321 | def get_data(sid, did, template, check_long_running_query=False, |
| 322 | only_data=False): |
| 323 | """ |
| 324 | Generic function to get server stats based on an SQL template |
| 325 | Args: |
| 326 | sid: The server ID |
| 327 | did: The database ID |
| 328 | template: The SQL template name |
| 329 | check_long_running_query: |
| 330 | |
| 331 | Returns: |
| 332 | |
| 333 | """ |
| 334 | # Allow no server ID to be specified (so we can generate a route in JS) |
| 335 | # but throw an error if it's actually called. |
| 336 | if not sid: |
| 337 | return internal_server_error(errormsg=ERROR_SERVER_ID_NOT_SPECIFIED) |
| 338 | |
| 339 | sql = render_template( |
| 340 | "/".join([g.template_path, template]), did=did |
| 341 | ) |
| 342 | status, res = g.conn.execute_dict(sql) |
| 343 | |
| 344 | if not status: |
| 345 | return internal_server_error(errormsg=res) |
| 346 | |
| 347 | # Check the long running query status and set the row type. |
| 348 | if check_long_running_query: |
| 349 | get_long_running_query_status(res['rows']) |
| 350 | |
| 351 | if only_data: |
| 352 | return res['rows'] |
| 353 | |
| 354 | return ajax_response( |
| 355 | response=res['rows'], |
| 356 | status=200 |
| 357 | ) |
| 358 | |
| 359 | |
| 360 | def get_long_running_query_status(activities): |
no test coverage detected