Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
rtpascual committed Jul 18, 2024
1 parent 28a6825 commit ca2d0bd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
29 changes: 17 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 2 additions & 10 deletions packages/backend-function/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,7 @@ class FunctionFactory implements ConstructFactory<AmplifyFunction> {
return [];
}

const schedules = Array.isArray(this.props.schedule)
? this.props.schedule
: [this.props.schedule];

return schedules;
return this.props.schedule;
};
}

Expand Down Expand Up @@ -376,14 +372,10 @@ class AmplifyFunction
);
}

const timeIntervals = Array.isArray(props.schedule)
? props.schedule
: [props.schedule];

try {
const schedules = convertFunctionSchedulesToRuleSchedules(
functionLambda,
timeIntervals
props.schedule
);
const lambdaTarget = new targets.LambdaFunction(functionLambda);

Expand Down
6 changes: 5 additions & 1 deletion packages/backend-function/src/schedule_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ type CronPart =
*/
export const convertFunctionSchedulesToRuleSchedules = (
lambda: NodejsFunction,
schedules: FunctionSchedule[]
functionSchedules: FunctionSchedule | FunctionSchedule[]
) => {
const errors: string[] = [];
const ruleSchedules: Schedule[] = [];

const schedules = Array.isArray(functionSchedules)
? functionSchedules
: [functionSchedules];

schedules.forEach((schedule) => {
if (isTimeInterval(schedule)) {
const { value, unit } = parseTimeInterval(schedule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,13 @@ class DataStorageAuthWithTriggerTestProject extends TestProjectBase {
await this.checkLambdaResponse(funcWithSsm[0], 'It is working');
await this.checkLambdaResponse(funcWithAwsSdk[0], 'It is working');

// test schedule function event trigger once
// Test schedule function event trigger on first deployment in order to do the following:
// 1. reduce flakiness on subsequent deployments (ex. sandbox updates)
// 2. reduce deployment e2e testing time as we are only waiting for 70 seconds one time per deployment
if (this.checkInvocationCount) {
const invocationCount = await this.getLambdaResponse(funcWithSchedule[0]);

// wait 1 minute and 10 seconds for schedule to invoke lambda again
// wait 70 seconds for schedule to invoke lambda again
await new Promise((resolve) => setTimeout(resolve, 1000 * 70));

await this.checkLambdaResponse(funcWithSchedule[0], invocationCount + 2);
Expand Down

0 comments on commit ca2d0bd

Please sign in to comment.