Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
2.3 kB
2
Indexable
Never
Current code on server side
def get_existing_tests_status_summary(self):
        query = f"SELECT " \
                f"SUM(CASE WHEN {WORKFLOW_COLUMNS['status'][0]} = 'QUEUE' THEN 1 ELSE 0 END) AS queue_result, " \
                f"SUM(CASE WHEN {WORKFLOW_COLUMNS['status'][0]} = 'SCHEDULED' THEN 1 ELSE 0 END) AS scheduled_result, " \
                f"SUM(CASE WHEN {WORKFLOW_COLUMNS['status'][0]} = 'STARTING' THEN 1 ELSE 0 END) AS starting_result, " \
                f"SUM(CASE WHEN {WORKFLOW_COLUMNS['status'][0]} = 'IN_PROGRESS' THEN 1 ELSE 0 END) AS in_progress_result " \
                f"FROM {WORKFLOW_TABLE_NAME};"

        results = self.db.execute_dql_query(query)["results"][0]
    
        status_dict = {
            'queue': results['queue_result'],
            'scheduled': results['scheduled_result'],
            'starting': results['starting_result'],
            'in_progress': results['in_progress_result']
        }

        return {'status_statistics': status_dict}
    

I make calls to it as:
def get_status_statistics(self):
        status_statistics = self.__result_db_handler.get_existing_tests_status_summary()
        return status_statistics

status_summary = workflow_initiator.get_status_statistics()
return jsonify(
        {
            "test-id": start_workflow.perf_workflow_config.test_id,
            "message": __get_user_message(resource_message),
            "status_statistics": status_summary,
        }

On the client side
    if "message" in resp.json():
        click.echo(resp.json()["message"])
        click.echo()
    click.echo(f"Test ID: {resp.json()['test-id']} has been submitted")
    click.echo(
        f"Tests Queue Statistics:\nNumber of tests ahead in QUEUE:{resp.json()['status_statistics']['queue']} \nNumber of tests SCHEDULED:{resp.json()['status_statistics']['scheduled']} \nNumber of tests STARTING:{resp.json()['status_statistics']['starting']} \nNumber of tests IN_PROGRESS:{resp.json()['status_statistics']['in_progress']} \nURL to Grafana Dashboard: https://g-e479d6ef8a.grafana-workspace.us-west-2.amazonaws.com/d/GXuswQq4z/performance-test-results?orgId=1&from=now-5m&to=now&var-internal_workflow_id={resp.json()['test-id']}"
    )

Error log
 'queue': results['queue_result'],
TypeError: tuple indices must be integers or slices, not str
Leave a Comment