Skip to content

Commit 6fcaff4

Browse files
authored
fix: Job API - correct handling on missed pre_aggregation (#7907)
1 parent 111571d commit 6fcaff4

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

packages/cubejs-api-gateway/src/gateway.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import {
3838
PreAggsSelector,
3939
PreAggJob,
4040
PreAggJobStatusItem,
41-
PreAggJobStatusObject,
4241
PreAggJobStatusResponse,
4342
SqlApiRequest, MetaResponseResultFn,
4443
} from './types/request';
@@ -1044,19 +1043,24 @@ class ApiGateway {
10441043
token: string,
10451044
): Promise<string> {
10461045
const preaggs = await compiler.preAggregations();
1047-
const preagg = preaggs.filter(pa => pa.id === job.preagg)[0];
1048-
const cube = metadata.cubeDefinitions[preagg.cube];
1049-
const [, status]: [boolean, string] =
1050-
await orchestrator.isPartitionExist(
1051-
requestId,
1052-
preagg.preAggregation.external,
1053-
cube.dataSource,
1054-
compiler.preAggregationsSchema,
1055-
job.target,
1056-
job.key,
1057-
token,
1058-
);
1059-
return status;
1046+
const preagg = preaggs.find(pa => pa.id === job.preagg);
1047+
if (preagg) {
1048+
const cube = metadata.cubeDefinitions[preagg.cube];
1049+
const [, status]: [boolean, string] =
1050+
await orchestrator.isPartitionExist(
1051+
requestId,
1052+
preagg.preAggregation.external,
1053+
cube.dataSource,
1054+
compiler.preAggregationsSchema,
1055+
job.target,
1056+
job.key,
1057+
token,
1058+
);
1059+
1060+
return status;
1061+
}
1062+
1063+
return 'pre_agg_not_found';
10601064
}
10611065

10621066
public async getPreAggregationsInQueue(

packages/cubejs-api-gateway/src/types/request.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ type PreAggsJobsRequest = {
179179

180180
type PreAggJobStatusItemNotFound = {
181181
token: string;
182-
status: 'not_found';
182+
status: 'not_found' | 'pre_agg_not_found';
183183
};
184184

185185
type PreAggJobStatusItemFound = {
@@ -192,11 +192,7 @@ type PreAggJobStatusItemFound = {
192192
type PreAggJobStatusItem = PreAggJobStatusItemNotFound | PreAggJobStatusItemFound;
193193

194194
type PreAggJobStatusObject = {
195-
[token: string]: {
196-
table: string;
197-
status: string;
198-
selector: PreAggsSelector;
199-
}
195+
[token: string]: Omit<PreAggJobStatusItem, 'token'>
200196
};
201197

202198
type PreAggJobStatusResponse =

packages/cubejs-server-core/src/core/RefreshScheduler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ export class RefreshScheduler {
725725
public async getCachedBuildJobs(
726726
context: RequestContext,
727727
tokens: string[],
728-
): Promise<{ job: PreAggJob, token: string }[]> {
728+
): Promise<{ job: PreAggJob | null, token: string }[]> {
729729
const orchestratorApi = await this.serverCore.getOrchestratorApi(context);
730730
const jobsPromise = Promise.all(
731731
tokens.map(async (token) => {

0 commit comments

Comments
 (0)