Skip to content

Commit cba5680

Browse files
committed
Simplify changes by using EngineConstants's getProject method
1 parent 8f9e5d8 commit cba5680

11 files changed

Lines changed: 16 additions & 65 deletions

File tree

packages/engine/src/lib/handler/block-executor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ const executeAction: ActionHandler<BlockAction> = async ({
189189
token: constants.engineToken,
190190
apiUrl: constants.internalApiUrl,
191191
publicUrl: constants.publicUrl,
192-
tablesDatabaseId: constants.tablesDatabaseId,
193-
tablesDatabaseToken: constants.tablesDatabaseToken,
192+
tablesDatabaseId: await constants.getTablesDatabaseId(),
193+
tablesDatabaseToken: await constants.getTablesDatabaseToken(),
194194
},
195195
propsValue: processedInput,
196196
tags: createTagsManager(hookResponse),

packages/engine/src/lib/handler/context/engine-constants.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,19 @@ export class EngineConstants {
6868
public readonly serverHandlerId: string | null,
6969
public readonly testRunActionLimits: TestRunLimitSettings,
7070
public readonly isTestRun: boolean,
71-
public readonly tablesDatabaseId: number,
72-
public readonly tablesDatabaseToken: EncryptedObject,
7371
public readonly resumePayload?: ResumePayload,
7472
) {}
7573

74+
public async getTablesDatabaseId(): Promise<number> {
75+
const project = await this.getProject();
76+
return project.tablesDatabaseId;
77+
}
78+
79+
public async getTablesDatabaseToken(): Promise<EncryptedObject> {
80+
const project = await this.getProject();
81+
return project.tablesDatabaseToken;
82+
}
83+
7684
public static fromExecuteFlowInput(
7785
input: ExecuteFlowOperation,
7886
): EngineConstants {
@@ -99,8 +107,6 @@ export class EngineConstants {
99107
input.serverHandlerId ?? null,
100108
input.flowVersion.testRunActionLimits,
101109
input.runEnvironment === 'TESTING',
102-
input.tablesDatabaseId,
103-
input.tablesDatabaseToken,
104110
input.executionType === ExecutionType.RESUME
105111
? input.resumePayload
106112
: undefined,
@@ -133,8 +139,6 @@ export class EngineConstants {
133139
null,
134140
input.flowVersion.testRunActionLimits,
135141
true,
136-
input.tablesDatabaseId,
137-
input.tablesDatabaseToken,
138142
);
139143
}
140144

@@ -164,8 +168,6 @@ export class EngineConstants {
164168
null,
165169
input.flowVersion.testRunActionLimits,
166170
true,
167-
input.tablesDatabaseId,
168-
input.tablesDatabaseToken,
169171
);
170172
}
171173

@@ -195,8 +197,6 @@ export class EngineConstants {
195197
null,
196198
input.flowVersion.testRunActionLimits,
197199
input.test,
198-
input.tablesDatabaseId,
199-
input.tablesDatabaseToken,
200200
);
201201
}
202202

packages/engine/src/lib/helper/block-helper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ export const blockHelper = {
124124
token: params.engineToken,
125125
apiUrl: constants.internalApiUrl,
126126
publicUrl: params.publicUrl,
127-
tablesDatabaseId: constants.tablesDatabaseId,
128-
tablesDatabaseToken: constants.tablesDatabaseToken,
127+
tablesDatabaseId: await constants.getTablesDatabaseId(),
128+
tablesDatabaseToken: await constants.getTablesDatabaseToken(),
129129
},
130130
project: {
131131
id: params.projectId,

packages/engine/src/lib/resolve-variable.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ export async function resolveVariable(
1717
flowVersion: input.flowVersion,
1818
stepName: input.stepName,
1919
stepTestOutputs: input.stepTestOutputs,
20-
tablesDatabaseId: input.tablesDatabaseId,
21-
tablesDatabaseToken: input.tablesDatabaseToken,
2220
});
2321

2422
const executionState = await testExecutionContext.stateFromFlowVersion({

packages/engine/test/handler/test-helper.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ export const generateMockEngineConstants = (params?: Partial<EngineConstants>):
3030
params?.serverHandlerId ?? null,
3131
params?.testRunActionLimits ?? { isEnabled: false, limits: [] },
3232
params?.isTestRun ?? false,
33-
params?.tablesDatabaseId ?? 1,
34-
params?.tablesDatabaseToken ?? { iv: 'test-iv', data: 'test-data' },
3533
params?.resumePayload,
3634
)
3735
}

packages/engine/test/resolve-variable.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ describe('resolveVariable', () => {
1616
engineToken: 'test-engine-token',
1717
internalApiUrl: 'https://test-api.com',
1818
publicUrl: 'https://test-public.com',
19-
tablesDatabaseId: 1,
20-
tablesDatabaseToken: { iv: 'test-iv', data: 'test-data' },
2119
flowVersion: {
2220
id: 'flow-version-id',
2321
flowId: 'flow-id',
@@ -148,8 +146,6 @@ describe('resolveVariable', () => {
148146
flowVersion: mockInput.flowVersion,
149147
stepName: mockInput.stepName,
150148
stepTestOutputs: mockInput.stepTestOutputs,
151-
tablesDatabaseId: mockInput.tablesDatabaseId,
152-
tablesDatabaseToken: mockInput.tablesDatabaseToken,
153149
});
154150

155151
expect(mockTestExecutionContext.stateFromFlowVersion).toHaveBeenCalledWith({
@@ -190,8 +186,6 @@ describe('resolveVariable', () => {
190186
flowVersion: mockInput.flowVersion,
191187
stepName: mockInput.stepName,
192188
stepTestOutputs: undefined,
193-
tablesDatabaseId: mockInput.tablesDatabaseId,
194-
tablesDatabaseToken: mockInput.tablesDatabaseToken,
195189
});
196190
});
197191
});

packages/server/worker/src/lib/api/server-api.service.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ export const engineApiService = (engineToken: string) => {
8787
responseType: 'arraybuffer',
8888
});
8989
},
90-
async getProject(): Promise<Project> {
91-
return client.get<Project>('/v1/worker/project', {});
92-
},
9390
async updateJobStatus(request: UpdateJobRequest): Promise<void> {
9491
await client.post('/v1/engine/update-job', request);
9592
},

packages/server/worker/src/lib/engine/engine-runner.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@ import {
2727
} from '@openops/shared';
2828
import chalk from 'chalk';
2929

30-
type EngineConstants =
31-
| 'publicUrl'
32-
| 'internalApiUrl'
33-
| 'engineToken'
34-
| 'tablesDatabaseId'
35-
| 'tablesDatabaseToken';
30+
type EngineConstants = 'publicUrl' | 'internalApiUrl' | 'engineToken';
3631

3732
export type CodeArtifact = {
3833
name: string;

packages/server/worker/src/lib/engine/index.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,18 @@ import {
1414
ResolveVariableOperation,
1515
TriggerHookType,
1616
} from '@openops/shared';
17-
import { engineApiService } from '../api/server-api.service';
1817
import { webhookUtils } from '../utils/webhook-utils';
1918
import { callEngineLambda } from './call-engine';
2019
import { EngineRunner } from './engine-runner';
2120
import { blockEngineUtil } from './flow-enginer-util';
2221

2322
export const engineRunner: EngineRunner = {
2423
async executeFlow(engineToken, operation) {
25-
const project = await engineApiService(engineToken).getProject();
26-
2724
const input: ExecuteFlowOperation = {
2825
...operation,
2926
engineToken,
3027
publicUrl: await networkUtls.getPublicUrl(),
3128
internalApiUrl: networkUtls.getInternalApiUrl(),
32-
tablesDatabaseId: project.tablesDatabaseId,
33-
tablesDatabaseToken: project.tablesDatabaseToken,
3429
};
3530

3631
return callEngineLambda(EngineOperationType.EXECUTE_FLOW, input);
@@ -49,7 +44,6 @@ export const engineRunner: EngineRunner = {
4944
'[EngineHelper#executeTrigger]',
5045
);
5146

52-
const project = await engineApiService(engineToken).getProject();
5347
const triggerBlock = await blockEngineUtil.getTriggerBlock(
5448
engineToken,
5549
operation.flowVersion,
@@ -74,45 +68,34 @@ export const engineRunner: EngineRunner = {
7468
internalApiUrl: networkUtls.getInternalApiUrl(),
7569
webhookSecret: await webhookSecretsUtils.getWebhookSecret(lockedVersion),
7670
engineToken,
77-
tablesDatabaseId: project.tablesDatabaseId,
78-
tablesDatabaseToken: project.tablesDatabaseToken,
7971
};
8072

8173
return callEngineLambda(EngineOperationType.EXECUTE_TRIGGER_HOOK, input);
8274
},
8375

8476
async executeProp(engineToken, operation) {
85-
const project = await engineApiService(engineToken).getProject();
86-
8777
const input: ExecutePropsOptions = {
8878
...operation,
8979
publicUrl: await networkUtls.getPublicUrl(),
9080
internalApiUrl: networkUtls.getInternalApiUrl(),
9181
engineToken,
92-
tablesDatabaseId: project.tablesDatabaseId,
93-
tablesDatabaseToken: project.tablesDatabaseToken,
9482
};
9583

9684
return callEngineLambda(EngineOperationType.EXECUTE_PROPERTY, input);
9785
},
9886

9987
async executeValidateAuth(engineToken, operation) {
100-
const project = await engineApiService(engineToken).getProject();
101-
10288
const input: ExecuteValidateAuthOperation = {
10389
...operation,
10490
publicUrl: await networkUtls.getPublicUrl(),
10591
internalApiUrl: networkUtls.getInternalApiUrl(),
10692
engineToken,
107-
tablesDatabaseId: project.tablesDatabaseId,
108-
tablesDatabaseToken: project.tablesDatabaseToken,
10993
};
11094

11195
return callEngineLambda(EngineOperationType.EXECUTE_VALIDATE_AUTH, input);
11296
},
11397

11498
async executeAction(engineToken, operation) {
115-
const project = await engineApiService(engineToken).getProject();
11699
const lockedFlowVersion = await blockEngineUtil.lockBlockInFlowVersion({
117100
engineToken,
118101
flowVersion: operation.flowVersion,
@@ -127,23 +110,17 @@ export const engineRunner: EngineRunner = {
127110
internalApiUrl: networkUtls.getInternalApiUrl(),
128111
engineToken,
129112
stepTestOutputs: operation.stepTestOutputs,
130-
tablesDatabaseId: project.tablesDatabaseId,
131-
tablesDatabaseToken: project.tablesDatabaseToken,
132113
};
133114

134115
return callEngineLambda(EngineOperationType.EXECUTE_STEP, input);
135116
},
136117

137118
async executeVariable(engineToken, operation) {
138-
const project = await engineApiService(engineToken).getProject();
139-
140119
const input: ResolveVariableOperation = {
141120
...operation,
142121
publicUrl: await networkUtls.getPublicUrl(),
143122
internalApiUrl: networkUtls.getInternalApiUrl(),
144123
engineToken,
145-
tablesDatabaseId: project.tablesDatabaseId,
146-
tablesDatabaseToken: project.tablesDatabaseToken,
147124
};
148125

149126
return callEngineLambda(EngineOperationType.RESOLVE_VARIABLE, input);

packages/server/worker/src/lib/executors/flow-job-executor.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@ import {
2525
import { engineApiService } from '../api/server-api.service';
2626
import { engineRunner } from '../engine';
2727

28-
type EngineConstants =
29-
| 'internalApiUrl'
30-
| 'publicUrl'
31-
| 'engineToken'
32-
| 'tablesDatabaseId'
33-
| 'tablesDatabaseToken';
28+
type EngineConstants = 'internalApiUrl' | 'publicUrl' | 'engineToken';
3429

3530
async function prepareInput(
3631
flowVersion: FlowVersion,

0 commit comments

Comments
 (0)