From 231ba69aee1ee8f90366dbff38ecdd2f92148732 Mon Sep 17 00:00:00 2001 From: Arik Fraimovich Date: Sun, 1 Sep 2019 17:28:01 +0300 Subject: [PATCH 1/3] Add scheduled status to query job metadata. --- redash/tasks/queries.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/redash/tasks/queries.py b/redash/tasks/queries.py index b76286c849..0ee9cd0ab0 100644 --- a/redash/tasks/queries.py +++ b/redash/tasks/queries.py @@ -403,6 +403,8 @@ def _annotate_query(self, query_runner): self.metadata['Task ID'] = self.task.request.id self.metadata['Query Hash'] = self.query_hash self.metadata['Queue'] = self.task.request.delivery_info['routing_key'] + self.metadata['Scheduled'] = self.scheduled_query is not None + return query_runner.annotate_query(self.query, self.metadata) def _log_progress(self, state): From 9a2d911527c04c34caab85a6fe8e1d97f89cad62 Mon Sep 17 00:00:00 2001 From: Arik Fraimovich Date: Sun, 1 Sep 2019 17:28:35 +0300 Subject: [PATCH 2/3] Add: option to set query group for adhoc/scheduled Redshift queries --- redash/query_runner/pg.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/redash/query_runner/pg.py b/redash/query_runner/pg.py index 9042138e2a..37133e7e63 100644 --- a/redash/query_runner/pg.py +++ b/redash/query_runner/pg.py @@ -266,12 +266,36 @@ def configuration_schema(cls): "type": "string", "title": "SSL Mode", "default": "prefer" - } + }, + "adhoc_query_group": { + "type": "string", + "title": "Query Group for Adhoc Queries", + "default": "default" + }, + "scheduled_query_group": { + "type": "string", + "title": "Query Group for Scheduled Queries", + "default": "default" + }, }, - "order": ['host', 'port', 'user', 'password'], + "order": ['host', 'port', 'user', 'password', 'dbname', 'sslmode', 'adhoc_query_group', 'scheduled_query_group'], "required": ["dbname", "user", "password", "host", "port"], "secret": ["password"] } + + def annotate_query(self, query, metadata): + annotated = super(Redshift, self).annotate_query(query, metadata) + + if metadata['Scheduled']: + query_group = self.configuration.get('scheduled_query_group') + else: + query_group = self.configuration.get('adhoc_query_group') + + if query_group: + set_query_group = 'set query_group to {};'.format(query_group) + annotated = '{}\n{}'.format(set_query_group, annotated) + + return annotated def _get_tables(self, schema): # Use svv_columns to include internal & external (Spectrum) tables and views data for Redshift From c0a681a3b1f31aaacf8524a32a83148e8c3a02d3 Mon Sep 17 00:00:00 2001 From: Arik Fraimovich Date: Sun, 1 Sep 2019 17:37:29 +0300 Subject: [PATCH 3/3] Scheduled might not be set for already enqueued queries. --- redash/query_runner/pg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redash/query_runner/pg.py b/redash/query_runner/pg.py index 37133e7e63..e9e4cc5431 100644 --- a/redash/query_runner/pg.py +++ b/redash/query_runner/pg.py @@ -286,7 +286,7 @@ def configuration_schema(cls): def annotate_query(self, query, metadata): annotated = super(Redshift, self).annotate_query(query, metadata) - if metadata['Scheduled']: + if metadata.get('Scheduled', False): query_group = self.configuration.get('scheduled_query_group') else: query_group = self.configuration.get('adhoc_query_group')