diff --git a/redash/query_runner/mysql.py b/redash/query_runner/mysql.py index 05552eef7f..82f19394cf 100644 --- a/redash/query_runner/mysql.py +++ b/redash/query_runner/mysql.py @@ -14,6 +14,7 @@ ) from redash.settings import parse_boolean from redash.utils import json_dumps, json_loads +from redash.tasks.worker import JobTimeoutException try: import MySQLdb @@ -150,11 +151,13 @@ def _get_tables(self, schema): return list(schema.values()) + def run_query(self, query, user): ev = threading.Event() thread_id = "" r = Result() t = None + try: connection = self._connection() thread_id = connection.thread_id() @@ -164,6 +167,10 @@ def run_query(self, query, user): t.start() while not ev.wait(1): pass + except JobTimeoutException as e: + self._cancel(thread_id) + t.join() + raise e except (KeyboardInterrupt, InterruptException): error = self._cancel(thread_id) t.join() diff --git a/redash/tasks/worker.py b/redash/tasks/worker.py index 3f68351228..c74983afce 100644 --- a/redash/tasks/worker.py +++ b/redash/tasks/worker.py @@ -4,7 +4,7 @@ import time from rq import Worker as BaseWorker, Queue as BaseQueue, get_current_job from rq.utils import utcnow -from rq.timeouts import UnixSignalDeathPenalty, HorseMonitorTimeoutException +from rq.timeouts import UnixSignalDeathPenalty, HorseMonitorTimeoutException, JobTimeoutException from rq.job import Job as BaseJob, JobStatus