Skip to content

Commit

Permalink
fix: Job API - correct handling on missed pre_aggregation (#7907)
Browse files Browse the repository at this point in the history
  • Loading branch information
ovr authored Mar 13, 2024
1 parent 111571d commit 6fcaff4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
32 changes: 18 additions & 14 deletions packages/cubejs-api-gateway/src/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import {
PreAggsSelector,
PreAggJob,
PreAggJobStatusItem,
PreAggJobStatusObject,
PreAggJobStatusResponse,
SqlApiRequest, MetaResponseResultFn,
} from './types/request';
Expand Down Expand Up @@ -1044,19 +1043,24 @@ class ApiGateway {
token: string,
): Promise<string> {
const preaggs = await compiler.preAggregations();
const preagg = preaggs.filter(pa => pa.id === job.preagg)[0];
const cube = metadata.cubeDefinitions[preagg.cube];
const [, status]: [boolean, string] =
await orchestrator.isPartitionExist(
requestId,
preagg.preAggregation.external,
cube.dataSource,
compiler.preAggregationsSchema,
job.target,
job.key,
token,
);
return status;
const preagg = preaggs.find(pa => pa.id === job.preagg);
if (preagg) {
const cube = metadata.cubeDefinitions[preagg.cube];
const [, status]: [boolean, string] =
await orchestrator.isPartitionExist(
requestId,
preagg.preAggregation.external,
cube.dataSource,
compiler.preAggregationsSchema,
job.target,
job.key,
token,
);

return status;
}

return 'pre_agg_not_found';
}

public async getPreAggregationsInQueue(
Expand Down
8 changes: 2 additions & 6 deletions packages/cubejs-api-gateway/src/types/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ type PreAggsJobsRequest = {

type PreAggJobStatusItemNotFound = {
token: string;
status: 'not_found';
status: 'not_found' | 'pre_agg_not_found';
};

type PreAggJobStatusItemFound = {
Expand All @@ -192,11 +192,7 @@ type PreAggJobStatusItemFound = {
type PreAggJobStatusItem = PreAggJobStatusItemNotFound | PreAggJobStatusItemFound;

type PreAggJobStatusObject = {
[token: string]: {
table: string;
status: string;
selector: PreAggsSelector;
}
[token: string]: Omit<PreAggJobStatusItem, 'token'>
};

type PreAggJobStatusResponse =
Expand Down
2 changes: 1 addition & 1 deletion packages/cubejs-server-core/src/core/RefreshScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ export class RefreshScheduler {
public async getCachedBuildJobs(
context: RequestContext,
tokens: string[],
): Promise<{ job: PreAggJob, token: string }[]> {
): Promise<{ job: PreAggJob | null, token: string }[]> {
const orchestratorApi = await this.serverCore.getOrchestratorApi(context);
const jobsPromise = Promise.all(
tokens.map(async (token) => {
Expand Down

0 comments on commit 6fcaff4

Please sign in to comment.