Skip to content

Commit

Permalink
feat: Provide status messages for ``/cubejs-api/v1/run-scheduled-refr…
Browse files Browse the repository at this point in the history
…esh` API
  • Loading branch information
paveltiunov committed Apr 11, 2020
1 parent efe2564 commit fb6623f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
6 changes: 4 additions & 2 deletions packages/cubejs-api-gateway/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,10 @@ class ApiGateway {
const requestStarted = new Date();
try {
const refreshScheduler = this.refreshScheduler();
await refreshScheduler.runScheduledRefresh(context, this.parseQueryParam(queryingOptions || {}));
res({}); // TODO status
res(await refreshScheduler.runScheduledRefresh(context, {
...this.parseQueryParam(queryingOptions || {}),
throwErrors: true
}));
} catch (e) {
this.handleError({
e, context, res, requestStarted
Expand Down
12 changes: 10 additions & 2 deletions packages/cubejs-server-core/core/RefreshScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class RefreshScheduler {

async runScheduledRefresh(context, queryingOptions) {
queryingOptions = { timezone: 'UTC', ...queryingOptions };
const { throwErrors, ...restOptions } = queryingOptions;
context = { requestId: `scheduler-${uuid()}`, ...context };
this.serverCore.logger('Refresh Scheduler Run', {
authInfo: context.authInfo,
Expand All @@ -87,9 +88,12 @@ class RefreshScheduler {
try {
const compilerApi = this.serverCore.getCompilerApi(context);
await Promise.all([
this.refreshCubesRefreshKey(context, compilerApi, queryingOptions),
this.refreshPreAggregations(context, compilerApi, queryingOptions)
this.refreshCubesRefreshKey(context, compilerApi, restOptions),
this.refreshPreAggregations(context, compilerApi, restOptions)
]);
return {
finished: true
};
} catch (e) {
if (e.error !== 'Continue wait') {
this.serverCore.logger('Refresh Scheduler Error', {
Expand All @@ -98,7 +102,11 @@ class RefreshScheduler {
requestId: context.requestId
});
}
if (throwErrors) {
throw e;
}
}
return { finished: false };
}

async refreshCubesRefreshKey(context, compilerApi, queryingOptions) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cubejs-server-core/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ class CubejsServerCore {

async runScheduledRefresh(context, queryingOptions) {
const scheduler = new RefreshScheduler(this);
await scheduler.runScheduledRefresh(context, queryingOptions);
return scheduler.runScheduledRefresh(context, queryingOptions);
}

async getDriver() {
Expand Down

0 comments on commit fb6623f

Please sign in to comment.