Skip to content

Commit e270757

Browse files
authored
chore(sdk): simplify ExecutionState interface (#329)
*Issue #, if available:* *Description of changes:* The ExecutionState interface has multiple duplicated parameters. Combining them into just the API parameters that are required for the interface. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent cc41d0e commit e270757

File tree

10 files changed

+167
-167
lines changed

10 files changed

+167
-167
lines changed

packages/aws-durable-execution-sdk-js-testing/src/test-runner/local/local-runner-storage.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
CheckpointDurableExecutionRequest,
44
CheckpointDurableExecutionResponse,
55
GetDurableExecutionStateCommand,
6+
GetDurableExecutionStateRequest,
67
GetDurableExecutionStateResponse,
78
LambdaClient,
89
} from "@aws-sdk/client-lambda";
@@ -31,33 +32,20 @@ export class LocalRunnerStorage implements ExecutionState {
3132
}
3233

3334
async getStepData(
34-
checkpointToken: string,
35-
durableExecutionArn: string,
36-
nextMarker: string,
35+
params: GetDurableExecutionStateRequest,
3736
): Promise<GetDurableExecutionStateResponse> {
3837
const response = await this.client.send(
39-
new GetDurableExecutionStateCommand({
40-
DurableExecutionArn: durableExecutionArn,
41-
CheckpointToken: checkpointToken,
42-
Marker: nextMarker,
43-
MaxItems: 1000,
44-
}),
38+
new GetDurableExecutionStateCommand(params),
4539
);
4640

4741
return response;
4842
}
4943

5044
async checkpoint(
51-
checkpointToken: string,
52-
data: CheckpointDurableExecutionRequest,
45+
params: CheckpointDurableExecutionRequest,
5346
): Promise<CheckpointDurableExecutionResponse> {
5447
const response = await this.client.send(
55-
new CheckpointDurableExecutionCommand({
56-
DurableExecutionArn: data.DurableExecutionArn,
57-
CheckpointToken: checkpointToken,
58-
ClientToken: data.ClientToken,
59-
Updates: data.Updates,
60-
}),
48+
new CheckpointDurableExecutionCommand(params),
6149
);
6250

6351
return response;

packages/aws-durable-execution-sdk-js/src/context/execution-context/execution-context.test.ts

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,12 @@ describe("initializeExecutionContext", () => {
246246

247247
// Verify
248248
expect(mockExecutionState.getStepData).toHaveBeenCalledWith(
249-
mockCheckpointToken,
250-
"test-durable-execution-arn",
251-
"token1",
249+
{
250+
CheckpointToken: mockCheckpointToken,
251+
DurableExecutionArn: "test-durable-execution-arn",
252+
Marker: "token1",
253+
MaxItems: 1000,
254+
},
252255
expectLogger,
253256
);
254257
expect(result.executionContext._stepData).toEqual({
@@ -305,15 +308,21 @@ describe("initializeExecutionContext", () => {
305308

306309
// Verify
307310
expect(mockExecutionState.getStepData).toHaveBeenCalledWith(
308-
mockCheckpointToken,
309-
"test-durable-execution-arn",
310-
"token1",
311+
{
312+
CheckpointToken: mockCheckpointToken,
313+
DurableExecutionArn: "test-durable-execution-arn",
314+
Marker: "token1",
315+
MaxItems: 1000,
316+
},
311317
expectLogger,
312318
);
313319
expect(mockExecutionState.getStepData).toHaveBeenCalledWith(
314-
mockCheckpointToken,
315-
"test-durable-execution-arn",
316-
"token2",
320+
{
321+
CheckpointToken: mockCheckpointToken,
322+
DurableExecutionArn: "test-durable-execution-arn",
323+
Marker: "token2",
324+
MaxItems: 1000,
325+
},
317326
expectLogger,
318327
);
319328
expect(result.executionContext._stepData).toEqual({
@@ -358,16 +367,22 @@ describe("initializeExecutionContext", () => {
358367

359368
// Verify
360369
expect(mockExecutionState.getStepData).toHaveBeenCalledWith(
361-
mockCheckpointToken,
362-
"test-durable-execution-arn",
363-
"token1",
370+
{
371+
CheckpointToken: mockCheckpointToken,
372+
DurableExecutionArn: "test-durable-execution-arn",
373+
Marker: "token1",
374+
MaxItems: 1000,
375+
},
364376
expectLogger,
365377
);
366378

367379
expect(mockExecutionState.getStepData).toHaveBeenCalledWith(
368-
mockCheckpointToken,
369-
"test-durable-execution-arn",
370-
"token2",
380+
{
381+
CheckpointToken: mockCheckpointToken,
382+
DurableExecutionArn: "test-durable-execution-arn",
383+
Marker: "token2",
384+
MaxItems: 1000,
385+
},
371386
expectLogger,
372387
);
373388

@@ -400,9 +415,12 @@ describe("initializeExecutionContext", () => {
400415

401416
// Verify
402417
expect(mockExecutionState.getStepData).toHaveBeenCalledWith(
403-
mockCheckpointToken,
404-
"test-durable-execution-arn",
405-
"token1",
418+
{
419+
CheckpointToken: mockCheckpointToken,
420+
DurableExecutionArn: "test-durable-execution-arn",
421+
Marker: "token1",
422+
MaxItems: 1000,
423+
},
406424
expectLogger,
407425
);
408426
expect(mockExecutionState.getStepData).toHaveBeenCalledTimes(1); // Should only be called once
@@ -437,9 +455,12 @@ describe("initializeExecutionContext", () => {
437455

438456
// Verify - should handle undefined operations gracefully and get execution event from pagination
439457
expect(mockExecutionState.getStepData).toHaveBeenCalledWith(
440-
mockCheckpointToken,
441-
"test-durable-execution-arn",
442-
"token1",
458+
{
459+
CheckpointToken: mockCheckpointToken,
460+
DurableExecutionArn: "test-durable-execution-arn",
461+
Marker: "token1",
462+
MaxItems: 1000,
463+
},
443464
expectLogger,
444465
);
445466
expect(result.executionContext._stepData).toEqual({});
@@ -482,9 +503,12 @@ describe("initializeExecutionContext", () => {
482503

483504
// Verify
484505
expect(mockExecutionState.getStepData).toHaveBeenCalledWith(
485-
mockCheckpointToken,
486-
"test-durable-execution-arn",
487-
"token1",
506+
{
507+
CheckpointToken: mockCheckpointToken,
508+
DurableExecutionArn: "test-durable-execution-arn",
509+
Marker: "token1",
510+
MaxItems: 1000,
511+
},
488512
expectLogger,
489513
);
490514
expect(result.executionContext._stepData).toEqual({

packages/aws-durable-execution-sdk-js/src/context/execution-context/execution-context.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ export const initializeExecutionContext = async (
4040

4141
while (nextMarker) {
4242
const response = await state.getStepData(
43-
checkpointToken,
44-
durableExecutionArn,
45-
nextMarker,
43+
{
44+
CheckpointToken: checkpointToken,
45+
Marker: nextMarker,
46+
DurableExecutionArn: durableExecutionArn,
47+
MaxItems: 1000,
48+
},
4649
initLogger,
4750
);
4851
operationsArray.push(...(response.Operations || []));

packages/aws-durable-execution-sdk-js/src/handlers/run-in-child-context-handler/run-in-child-context-integration.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,11 @@ describe("Run In Child Context Integration Tests", () => {
7272
getStepData: jest.fn().mockResolvedValue({}),
7373
checkpoint: jest
7474
.fn()
75-
.mockImplementation(
76-
(taskToken: string, data: CheckpointDurableExecutionRequest) => {
77-
const checkpointToken = data.CheckpointToken;
78-
checkpointCalls.push({ checkpointToken, data });
79-
return Promise.resolve({ CheckpointToken: "mock-token" });
80-
},
81-
),
75+
.mockImplementation((data: CheckpointDurableExecutionRequest) => {
76+
const checkpointToken = data.CheckpointToken;
77+
checkpointCalls.push({ checkpointToken, data });
78+
return Promise.resolve({ CheckpointToken: "mock-token" });
79+
}),
8280
},
8381
_stepData: {},
8482
terminationManager: mockTerminationManager,

packages/aws-durable-execution-sdk-js/src/storage/api-storage.test.ts

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,12 @@ describe("ApiStorage", () => {
7272
mockLambdaClient.send.mockResolvedValue(mockResponse);
7373

7474
// Call getStepData
75-
const result = await apiStorage.getStepData(
76-
"checkpoint-token",
77-
"durable-execution-arn",
78-
"next-marker",
79-
);
75+
const result = await apiStorage.getStepData({
76+
CheckpointToken: "checkpoint-token",
77+
DurableExecutionArn: "durable-execution-arn",
78+
Marker: "next-marker",
79+
MaxItems: 1000,
80+
});
8081

8182
// Verify that GetDurableExecutionStateCommand was constructed with the correct parameters
8283
expect(GetDurableExecutionStateCommand).toHaveBeenCalledWith({
@@ -103,7 +104,7 @@ describe("ApiStorage", () => {
103104
// Create checkpoint data
104105
const checkpointData: CheckpointDurableExecutionRequest = {
105106
DurableExecutionArn: "test-durable-execution-arn",
106-
CheckpointToken: "",
107+
CheckpointToken: "task-token",
107108
Updates: [
108109
{
109110
Id: "test-step-1",
@@ -115,7 +116,7 @@ describe("ApiStorage", () => {
115116
};
116117

117118
// Call checkpoint
118-
const result = await apiStorage.checkpoint("task-token", checkpointData);
119+
const result = await apiStorage.checkpoint(checkpointData);
119120

120121
// Verify that CheckpointDurableExecutionCommand was constructed with the correct parameters
121122
expect(CheckpointDurableExecutionCommand).toHaveBeenCalledWith({
@@ -140,18 +141,18 @@ describe("ApiStorage", () => {
140141

141142
// Call getStepData and expect it to throw
142143
await expect(
143-
apiStorage.getStepData(
144-
"task-token",
145-
"durable-execution-arn",
146-
"next-token",
147-
),
144+
apiStorage.getStepData({
145+
CheckpointToken: "task-token",
146+
DurableExecutionArn: "durable-execution-arn",
147+
Marker: "next-token",
148+
}),
148149
).rejects.toThrow("Lambda client error");
149150

150151
// Call checkpoint and expect it to throw
151152
await expect(
152-
apiStorage.checkpoint("task-token", {
153+
apiStorage.checkpoint({
153154
DurableExecutionArn: "",
154-
CheckpointToken: "",
155+
CheckpointToken: "task-token",
155156
Updates: [
156157
{
157158
Id: "test-step-2",
@@ -174,11 +175,11 @@ describe("ApiStorage", () => {
174175

175176
// Call getStepData and expect it to throw
176177
try {
177-
await apiStorage.getStepData(
178-
"checkpoint-token",
179-
"test-execution-arn",
180-
"next-marker",
181-
);
178+
await apiStorage.getStepData({
179+
CheckpointToken: "checkpoint-token",
180+
DurableExecutionArn: "test-execution-arn",
181+
Marker: "next-marker",
182+
});
182183
} catch (_error) {
183184
// Expected to throw
184185
}
@@ -204,13 +205,13 @@ describe("ApiStorage", () => {
204205

205206
const checkpointData: CheckpointDurableExecutionRequest = {
206207
DurableExecutionArn: "test-execution-arn-2",
207-
CheckpointToken: "",
208+
CheckpointToken: "checkpoint-token",
208209
Updates: [],
209210
};
210211

211212
// Call checkpoint and expect it to throw
212213
try {
213-
await apiStorage.checkpoint("checkpoint-token", checkpointData);
214+
await apiStorage.checkpoint(checkpointData);
214215
} catch (_error) {
215216
// Expected to throw
216217
}
@@ -233,11 +234,11 @@ describe("ApiStorage", () => {
233234

234235
// Call getStepData and expect it to throw
235236
await expect(
236-
apiStorage.getStepData(
237-
"checkpoint-token",
238-
"test-execution-arn",
239-
"next-marker",
240-
),
237+
apiStorage.getStepData({
238+
CheckpointToken: "checkpoint-token",
239+
DurableExecutionArn: "test-execution-arn",
240+
Marker: "next-marker",
241+
}),
241242
).rejects.toThrow("Network error");
242243

243244
// Verify error was logged
@@ -269,9 +270,11 @@ describe("ApiStorage", () => {
269270

270271
try {
271272
await apiStorage.getStepData(
272-
"checkpoint-token",
273-
"test-execution-arn",
274-
"next-marker",
273+
{
274+
CheckpointToken: "checkpoint-token",
275+
DurableExecutionArn: "test-execution-arn",
276+
Marker: "next-marker",
277+
},
275278
mockLogger,
276279
);
277280
} catch (_error) {
@@ -303,16 +306,12 @@ describe("ApiStorage", () => {
303306

304307
const checkpointData: CheckpointDurableExecutionRequest = {
305308
DurableExecutionArn: "test-execution-arn",
306-
CheckpointToken: "",
309+
CheckpointToken: "checkpoint-token",
307310
Updates: [],
308311
};
309312

310313
try {
311-
await apiStorage.checkpoint(
312-
"checkpoint-token",
313-
checkpointData,
314-
mockLogger,
315-
);
314+
await apiStorage.checkpoint(checkpointData, mockLogger);
316315
} catch (_error) {
317316
// Expected to throw
318317
}

0 commit comments

Comments
 (0)