How to use the api/cancellablePromise function in api

To help you get started, we’ve selected a few api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cloudera / hue / desktop / core / src / desktop / js / api / apiHelper.js View on Github external
fetchQueryExecutionAnalysis(options) {
    const self = this;
    //var url = '/metadata/api/workload_analytics/get_impala_query/';
    const url = '/impala/api/query/alanize';
    const deferred = $.Deferred();

    let tries = 0;

    const cancellablePromises = [];

    const promise = new CancellablePromise(deferred, undefined, cancellablePromises);

    const pollForAnalysis = () => {
      if (tries === 10) {
        deferred.reject();
        return;
      }
      tries++;
      cancellablePromises.pop(); // Remove the last one
      cancellablePromises.push(
        deferred,
        self
          .simplePost(
            url,
            {
              cluster: JSON.stringify(options.compute),
              query_id: '"' + options.queryId + '"'
github cloudera / hue / desktop / core / src / desktop / js / api / apiHelper.js View on Github external
const deferred = $.Deferred();

    const request = self.simplePost(NAV_URLS.LIST_TAGS, undefined, {
      silenceErrors: options.silenceErrors,
      successCallback: function(data) {
        if (data && data.tags) {
          deferred.resolve(data.tags);
        } else {
          deferred.resolve({});
        }
      },
      errorCallback: deferred.reject
    });

    return new CancellablePromise(deferred, request);
  }
github cloudera / hue / desktop / core / src / desktop / js / api / apiHelper.js View on Github external
dbTables[path.join('.')] = true;
  });
  const data = {
    dbTables: ko.mapping.toJSON(Object.keys(dbTables))
  };

  const request = apiHelper.simplePost(url, data, {
    silenceErrors: options.silenceErrors,
    successCallback: function(data) {
      data.hueTimestamp = Date.now();
      deferred.resolve(data);
    },
    errorCallback: deferred.reject
  });

  return new CancellablePromise(deferred, request);
};
github cloudera / hue / desktop / core / src / desktop / js / api / apiHelper.js View on Github external
const request = self.simplePost(
      SEARCH_API,
      {
        query_s: ko.mapping.toJSON(options.query),
        limit: options.limit || 100,
        raw_query: !!options.rawQuery,
        sources: options.sources ? ko.mapping.toJSON(options.sources) : '["sql"]'
      },
      {
        silenceErrors: options.silenceErrors,
        successCallback: deferred.resolve,
        errorCallback: deferred.reject
      }
    );

    return new CancellablePromise(deferred, request);
  }
github cloudera / hue / desktop / core / src / desktop / js / api / apiHelper.js View on Github external
dbTables[path.join('.')] = true;
  });
  const data = {
    dbTables: ko.mapping.toJSON(Object.keys(dbTables))
  };

  const request = apiHelper.simplePost(url, data, {
    silenceErrors: options.silenceErrors,
    successCallback: function(data) {
      data.hueTimestamp = Date.now();
      deferred.resolve(data);
    },
    errorCallback: deferred.reject
  });

  return new CancellablePromise(deferred, request);
};
github cloudera / hue / desktop / core / src / desktop / js / api / apiHelper.js View on Github external
const request = self.simplePost(
      SEARCH_API,
      {
        query_s: ko.mapping.toJSON(options.query),
        limit: options.limit || 100,
        raw_query: !!options.rawQuery,
        sources: options.sources ? ko.mapping.toJSON(options.sources) : '["sql"]'
      },
      {
        silenceErrors: options.silenceErrors,
        successCallback: deferred.resolve,
        errorCallback: deferred.reject
      }
    );

    return new CancellablePromise(deferred, request);
  }
github cloudera / hue / desktop / core / src / desktop / js / api / apiHelper.js View on Github external
snippet: ko.mapping.toJSON({
          type: 'nav'
        })
      },
      {
        silenceErrors: options.silenceErrors,
        successCallback: function(data) {
          data = data.entity || data;
          data.hueTimestamp = Date.now();
          deferred.resolve(data);
        },
        errorCallback: deferred.reject
      }
    );

    return new CancellablePromise(deferred, request);
  }
github cloudera / hue / desktop / core / src / desktop / js / api / apiHelper.js View on Github external
const self = this;
    const deferred = $.Deferred();

    const request = self.simplePost(
      FORMAT_SQL_API,
      {
        statements: options.statements
      },
      {
        silenceErrors: options.silenceErrors,
        successCallback: deferred.resolve,
        errorCallback: deferred.reject
      }
    );

    return new CancellablePromise(deferred, request);
  }
}
github cloudera / hue / desktop / core / src / desktop / js / api / apiHelper.js View on Github external
if (response && response.query_status && response.query_status.status) {
            const status = response.query_status.status;
            if (status === 'available') {
              deferred.resolve();
            } else if (status === 'running' || status === 'starting' || status === 'waiting') {
              waitTimeout = window.setTimeout(() => {
                waitForAvailable();
              }, 500);
            } else {
              deferred.reject();
            }
          }
        })
        .fail(deferred.reject);

      cancellablePromises.push(new CancellablePromise(request, request));
    };
github cloudera / hue / desktop / core / src / desktop / js / api / apiHelper.js View on Github external
},
      {
        silenceErrors: options.silenceErrors,
        successCallback: function(response) {
          if (response.status === 0 && response.details) {
            response.details.hueTimestamp = Date.now();
            deferred.resolve(response.details);
          } else {
            deferred.reject();
          }
        },
        errorCallback: deferred.reject
      }
    );

    return new CancellablePromise(deferred, request);
  }