You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2019/11/12 13:13:03 UTC

[incubator-shardingsphere-benchmark] branch master updated: feature[shadingsphere-benchmark-ui]: Add timeout prompt

This is an automated email from the ASF dual-hosted git repository.

zhaoyanan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shardingsphere-benchmark.git


The following commit(s) were added to refs/heads/master by this push:
     new 1dcaeaa  feature[shadingsphere-benchmark-ui]: Add timeout prompt
     new 12e9ba7  Merge pull request #23 from wqzwh/master
1dcaeaa is described below

commit 1dcaeaa7c5df560717879b84b2da76adeab77152
Author: wqzwh <wa...@163.com>
AuthorDate: Tue Nov 12 15:10:55 2019 +0800

    feature[shadingsphere-benchmark-ui]: Add timeout prompt
---
 shadingsphere-benchmark-ui/package.json     |  2 +-
 shadingsphere-benchmark-ui/src/utils/api.js | 70 ++++++++++++++++++++++++-----
 2 files changed, 61 insertions(+), 11 deletions(-)

diff --git a/shadingsphere-benchmark-ui/package.json b/shadingsphere-benchmark-ui/package.json
index 654ac63..d675ea2 100644
--- a/shadingsphere-benchmark-ui/package.json
+++ b/shadingsphere-benchmark-ui/package.json
@@ -11,9 +11,9 @@
     "build": "node build/build.js"
   },
   "dependencies": {
+    "axios": "^0.19.0",
     "echarts": "^4.3.0",
     "iview": "^3.5.1",
-    "jquery": "^3.4.1",
     "moment": "^2.24.0",
     "vue": "^2.5.2",
     "vue-echarts": "^4.0.4",
diff --git a/shadingsphere-benchmark-ui/src/utils/api.js b/shadingsphere-benchmark-ui/src/utils/api.js
index b7c33e4..1e51b6c 100644
--- a/shadingsphere-benchmark-ui/src/utils/api.js
+++ b/shadingsphere-benchmark-ui/src/utils/api.js
@@ -1,20 +1,70 @@
-import $ from 'jquery'
-
+import axios from 'axios'
+import { Notice } from 'iview'
 const HOST =
   'https://raw.githubusercontent.com/apache/incubator-shardingsphere-benchmark/master/report'
 
-function ajax(url, type) {
+axios.defaults.retry = 3
+axios.defaults.retryDelay = 2000
+
+axios.interceptors.response.use(undefined, err => {
+  var config = err.config
+  if (!config || !config.retry) return Promise.reject(err)
+
+  config.__retryCount = config.__retryCount || 0
+
+  if (config.__retryCount >= config.retry) {
+    return Promise.reject(err)
+  }
+
+  config.__retryCount += 1
+
+  var backoff = new Promise(resolve => {
+    setTimeout(() => {
+      resolve()
+    }, config.retryDelay || 1000)
+  })
+
+  return backoff.then(() => {
+    return axios(config)
+  })
+})
+
+function ajax(url, type, options) {
   return new Promise((resolve, reject) => {
-    $.getJSON(HOST + url, function(data, type, xhr) {
-      if (xhr.status === 200) {
-        resolve(data)
-      } else {
+    axios({
+      method: type,
+      url: HOST + url,
+      timeout: 3000,
+      responseType: 'json'
+    })
+      .then(
+        result => {
+          const { data, status } = result
+          if (status === 200) {
+            resolve(data)
+          }
+        },
+        error => {
+          const { message } = error
+          if (message.includes('timeout')) {
+            Notice.info({
+              title: 'Prompt information',
+              desc: 'please try again later!'
+            })
+          }
+          reject(error)
+        }
+      )
+      .catch((error) => {
+        Notice.error({
+          title: 'Prompt information',
+          description: error
+        })
         reject({
           error: true,
-          msg: xhr.status
+          msg: error
         })
-      }
-    })
+      })
   })
 }