Skip to content

Commit

Permalink
Merge branch 'auto-ssh-tunnels' of github.com:getredash/redash into a…
Browse files Browse the repository at this point in the history
…uto-ssh-tunnels
  • Loading branch information
Omer Lachish committed Apr 30, 2020
2 parents 7f3b458 + 9029e6e commit c38d826
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
17 changes: 7 additions & 10 deletions client/app/pages/queries/hooks/useDataSourceSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import DataSource from "@/services/data-source";
import notification from "@/services/notification";

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
return new Promise((resolve) => setTimeout(resolve, ms));
}

function getSchema(dataSource, refresh = undefined) {
Expand All @@ -15,17 +15,16 @@ function getSchema(dataSource, refresh = undefined) {

const fetchSchemaFromJob = (data) => {
return sleep(1000).then(() => {
return axios.get(`api/jobs/${data.job.id}`).then(data => {
return axios.get(`api/jobs/${data.job.id}`).then((data) => {
if (data.job.status < 3) {
return fetchSchemaFromJob(data);
}
else if (data.job.status === 3) {
} else if (data.job.status === 3) {
return data.job.result;
} else {
return Promise.reject(new Error(data.job.error));
}
})
})
});
});
};

return DataSource.fetchSchema(dataSource, refresh)
Expand All @@ -47,11 +46,9 @@ export default function useDataSourceSchema(dataSource) {

const reloadSchema = useCallback(
(refresh = undefined) => {
const refreshToken = Math.random()
.toString(36)
.substr(2);
const refreshToken = Math.random().toString(36).substr(2);
refreshSchemaTokenRef.current = refreshToken;
getSchema(dataSource, refresh).then(data => {
getSchema(dataSource, refresh).then((data) => {
if (refreshSchemaTokenRef.current === refreshToken) {
setSchema(prepareSchema(data));
}
Expand Down
6 changes: 3 additions & 3 deletions client/app/services/data-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const DataSource = {
query: () => axios.get("api/data_sources"),
get: ({ id }) => axios.get(`api/data_sources/${id}`),
types: () => axios.get("api/data_sources/types"),
create: data => axios.post(`api/data_sources`, data),
save: data => axios.post(`api/data_sources/${data.id}`, data),
test: data => axios.post(`api/data_sources/${data.id}/test`),
create: (data) => axios.post(`api/data_sources`, data),
save: (data) => axios.post(`api/data_sources/${data.id}`, data),
test: (data) => axios.post(`api/data_sources/${data.id}/test`),
delete: ({ id }) => axios.delete(`api/data_sources/${id}`),
fetchSchema: (data, refresh = false) => {
const params = {};
Expand Down

0 comments on commit c38d826

Please sign in to comment.