Skip to content

Commit

Permalink
feat: add configurable timeout to querybook (#1207)
Browse files Browse the repository at this point in the history
* feat: add configurable timeout to querybook

* remove print

* remove unless comment
  • Loading branch information
czgu authored Mar 31, 2023
1 parent 354b08d commit 4e234d6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion querybook/server/datasources/query_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def cancel_query_and_notify():
"RETRY", # Very unlikely case, because query normally do not retry
):

task.revoke() # last attempt to cancel it
task.revoke(terminate=True) # last attempt to cancel it
cancel_query_and_notify()
elif task.state == "ABORTED":
# In this case, the task is already aborted, but the status is running
Expand Down
6 changes: 6 additions & 0 deletions querybook/server/lib/query_executor/clients/presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(
password: Optional[str] = None,
proxy_user: Optional[str] = None,
impersonate: bool = False,
connection_timeout: int = None,
*args: Any,
**kwargs: Any
) -> None:
Expand All @@ -59,6 +60,10 @@ def __init__(
host = presto_conf.host
port = 8080 if not presto_conf.port else presto_conf.port

requests_kwargs = {}
if connection_timeout and connection_timeout > 0:
requests_kwargs["timeout"] = connection_timeout

connection = presto.connect(
host,
port=port,
Expand All @@ -69,6 +74,7 @@ def __init__(
schema=presto_conf.schema,
source="querybook",
protocol=presto_conf.protocol,
requests_kwargs=requests_kwargs,
)
self._connection = connection
super(PrestoClient, self).__init__()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
<p>See [here](https://prestodb.github.io/docs/current/installation/jdbc.html) for more details.</p>""",
),
),
(
"connection_timeout",
FormField(
field_type=FormFieldType.Number,
helper="Max number of seconds before timing out the request",
),
),
)

trino_executor_template = StructFormField(
Expand Down
16 changes: 12 additions & 4 deletions querybook/webapp/ui/SmartForm/SmartForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ function SimpleFormField<T>({
value: T;
onChange: onChangeFunc<T>;
}) {
const onFieldChange = React.useCallback(
(newVal: any) => onChange('', newVal),
[onChange]
);
const {
description,
hidden,
Expand All @@ -56,6 +52,18 @@ function SimpleFormField<T>({
field_type: fieldType,
options,
} = formField;

const onFieldChange = React.useCallback(
(newVal: any) => {
if (fieldType === 'number') {
newVal = Number(newVal);
}

return onChange('', newVal);
},
[onChange, fieldType]
);

let controlDOM: React.ReactChild;
if (fieldType === 'string' || fieldType === 'number') {
const inputProps = {
Expand Down

0 comments on commit 4e234d6

Please sign in to comment.