-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat(iotevents): support timer actions #19949
Merged
+924
−6
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
address comment
commit baaa3d0c69d30d7eed6732fd1bd53d179d399f81
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 7 additions & 55 deletions
62
packages/@aws-cdk/aws-iotevents-actions/lib/set-timer-action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/@aws-cdk/aws-iotevents-actions/lib/timer-duration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as iotevents from '@aws-cdk/aws-iotevents'; | ||
import { Duration } from '@aws-cdk/core'; | ||
|
||
/** | ||
* The duration of the timer. | ||
*/ | ||
export abstract class TimerDuration { | ||
/** | ||
* Create a timer-duration from Duration. | ||
* | ||
* The range of the duration is 60-31622400 seconds. | ||
* The evaluated result of the duration expression is rounded down to the nearest whole number. | ||
* For example, if you set the timer to 60.99 seconds, the evaluated result of the duration expression is 60 seconds. | ||
*/ | ||
public static fromDuration(duration: Duration): TimerDuration { | ||
const seconds = duration.toSeconds(); | ||
if (seconds < 60) { | ||
throw new Error(`duration cannot be less than 60 seconds, got: ${duration.toString()}`); | ||
} | ||
if (seconds > 31622400) { | ||
throw new Error(`duration cannot be greater than 31622400 seconds, got: ${duration.toString()}`); | ||
} | ||
return new TimerDurationImpl(seconds.toString()); | ||
} | ||
|
||
/** | ||
* Create a timer-duration from Expression. | ||
* | ||
* You can use a string expression that includes numbers, variables ($variable.<variable-name>), | ||
* and input values ($input.<input-name>.<path-to-datum>) as the duration. | ||
* | ||
* The range of the duration is 60-31622400 seconds. | ||
* The evaluated result of the duration expression is rounded down to the nearest whole number. | ||
* For example, if you set the timer to 60.99 seconds, the evaluated result of the duration expression is 60 seconds. | ||
*/ | ||
public static fromExpression(expression: iotevents.Expression): TimerDuration { | ||
return new TimerDurationImpl(expression.evaluate()); | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public abstract _bind(): string; | ||
} | ||
|
||
class TimerDurationImpl extends TimerDuration { | ||
constructor(private readonly durationExpression: string) { | ||
super(); | ||
} | ||
|
||
public _bind() { | ||
return this.durationExpression; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be better off as it is I think.
This is implementation of
IAction
and is followingIntegration
in DESIGN_GUIDELINE as same as aws-events target.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm annoyed with that but it's not in scope here to ask you to fix an old contract I'm mad at. Maybe I'll get neurotic about it and do some excessive refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've understood that refactoring is necessary even in light of the current implementations.
I'll refactor it!