Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(events,applicationautoscaling): specifying a schedule rate in seconds results in an error #13689

Merged
merged 5 commits into from
Mar 22, 2021

Conversation

nija-at
Copy link
Contributor

@nija-at nija-at commented Mar 19, 2021

A previous change - b1449a1 - introduced a validation that should have
been applied only when Duration is specified as a token. Instead, it was
applied for non token values as well.

Adjusting the validation so it only applies to when the duration is a
token.

fixes #13566


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

…onds results in an error

A previous change - b1449a1 - introduced a validation that should have
been applied only when Duration is specified as a token. Instead, it was
applied for non token values as well.

Adjusting the validation so it only applies to when the duration is a
token.

fixes #13566
@nija-at nija-at requested a review from a team March 19, 2021 11:48
@nija-at nija-at self-assigned this Mar 19, 2021
@gitpod-io
Copy link

gitpod-io bot commented Mar 19, 2021

@github-actions github-actions bot added @aws-cdk/aws-applicationautoscaling Related to AWS Application Auto Scaling @aws-cdk/aws-events Related to CloudWatch Events labels Mar 19, 2021
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Mar 19, 2021
Comment on lines 20 to 26
if (duration.isUnresolved()) {
const validDurationUnit = ['minute', 'minutes', 'hour', 'hours', 'day', 'days'];
if (!validDurationUnit.includes(duration.unitLabel())) {
throw new Error("Allowed units for scheduling are: 'minute', 'minutes', 'hour', 'hours', 'day' or 'days'");
}
return new LiteralSchedule(`rate(${duration.formatTokenToNumber()})`);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (duration.isUnresolved()) {
const validDurationUnit = ['minute', 'minutes', 'hour', 'hours', 'day', 'days'];
if (!validDurationUnit.includes(duration.unitLabel())) {
throw new Error("Allowed units for scheduling are: 'minute', 'minutes', 'hour', 'hours', 'day' or 'days'");
}
return new LiteralSchedule(`rate(${duration.formatTokenToNumber()})`);
}
if (duration.isUnresolved()) {
return new LiteralSchedule(`rate(${duration.formatTokenToNumber()})`);
}
const validDurationUnit = ['minute', 'minutes', 'hour', 'hours', 'day', 'days'];
if (!validDurationUnit.includes(duration.unitLabel())) {
throw new Error("Allowed units for scheduling are: 'minute', 'minutes', 'hour', 'hours', 'day' or 'days'");
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub is being weird, so I'll just comment here. It seems like there is still a problem in code, if duration is unresolved the validation will still happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if duration is unresolved the validation will still happen?

Yes, that's the intended change here. If duration is a token, it is not possible to perform unit conversion. So the original units specified during construction of the Duration object will be used. However, AWS events has a fixed set of units and hence the validation is required.

If Duration is not a token, then the units can be converted from the unsupported set of units to the supported set of units.

Makes sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I missed that duration.isUnresolved() is calling the isUnresolved method from the Duration class rather than the Token.isUnresolved method

@nija-at nija-at requested review from a team and NetaNir March 22, 2021 13:19
@mergify
Copy link
Contributor

mergify bot commented Mar 22, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify
Copy link
Contributor

mergify bot commented Mar 22, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify
Copy link
Contributor

mergify bot commented Mar 22, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify
Copy link
Contributor

mergify bot commented Mar 22, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 9f3528a
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 5d62331 into master Mar 22, 2021
@mergify mergify bot deleted the nija-at/schedule-seconds branch March 22, 2021 18:49
nija-at pushed a commit that referenced this pull request Mar 23, 2021
…onds results in an error (#13689)

A previous change - b1449a1 - introduced a validation that should have
been applied only when Duration is specified as a token. Instead, it was
applied for non token values as well.

Adjusting the validation so it only applies to when the duration is a
token.

fixes #13566


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
eladb pushed a commit that referenced this pull request Mar 24, 2021
…onds results in an error (#13689)

A previous change - b1449a1 - introduced a validation that should have
been applied only when Duration is specified as a token. Instead, it was
applied for non token values as well.

Adjusting the validation so it only applies to when the duration is a
token.

fixes #13566


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
…onds results in an error (aws#13689)

A previous change - b1449a1 - introduced a validation that should have
been applied only when Duration is specified as a token. Instead, it was
applied for non token values as well.

Adjusting the validation so it only applies to when the duration is a
token.

fixes aws#13566


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-applicationautoscaling Related to AWS Application Auto Scaling @aws-cdk/aws-events Related to CloudWatch Events contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(events): specifying a schedule duration in seconds results in an error
4 participants