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

feat(iotevents): support timer actions #19949

Merged
merged 4 commits into from
Aug 3, 2022

Conversation

yamatatsu
Copy link
Contributor

This PR is a part of roadmap in #17711. And if this PR is merged, I will close this issue and create some good first issues to implement rest actions and expressions.

This PR supports the timer actions (SetTimerAction, ResetTimerAction and ClearTimerAction) and timeout() expression.

These allow to embed a timer to the state machine of the detector model.
Below figure illustrate the state machine Device Heartbeat. This detector model is used to alert if the message is interrupted for a certain period of time. The integ-test included in this PR is example of creating Device Heartbeat detector model.

stateDiagram-v2
  [*] --> Online: set a timer on input message
  Online --> Online: reset the timer\non input messages
  Online --> Offline: timeout the timer
  Offline --> Online: input messages
Loading

All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

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

@gitpod-io
Copy link

gitpod-io bot commented Apr 18, 2022

@aws-cdk-automation aws-cdk-automation requested a review from a team April 18, 2022 01:38
@github-actions github-actions bot added the p2 label Apr 18, 2022
@TheRealAmazonKendra TheRealAmazonKendra changed the base branch from v1-main to main July 13, 2022 00:06
Copy link
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

Apologies for our delay in getting to this review. Now that we've moved the branch to v2, can you please take a look at resolving the conflicts and/or opening a new PR for this if resolving them is too messy?

@mergify mergify bot dismissed TheRealAmazonKendra’s stale review July 31, 2022 13:03

Pull request has been modified.

Copy link
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

Thanks for your work on this! Overall this looks quite good. Please see my specific feedback inline.

packages/@aws-cdk/aws-iotevents-actions/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents-actions/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents-actions/README.md Outdated Show resolved Hide resolved
*
* @default - none, required if no `durationExpression` is defined.
*/
readonly duration?: cdk.Duration;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a fan of mutually exclusive props. I think this should go in the direction of one required prop that gets translated properly into Duration or Expression. Take a look at the model of this we use for Schedule in aws-events.

Copy link
Contributor Author

@yamatatsu yamatatsu Aug 2, 2022

Choose a reason for hiding this comment

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

Cool! 🤩 I will implement as it. Thank you!

}
}

bind(_scope: Construct, _options: iotevents.ActionBindOptions): iotevents.ActionConfig {
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
bind(_scope: Construct, _options: iotevents.ActionBindOptions): iotevents.ActionConfig {
public _bind(_scope: Construct, _options: iotevents.ActionBindOptions): iotevents.ActionConfig {

Copy link
Contributor Author

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 following Integration in DESIGN_GUIDELINE as same as aws-events target.

Copy link
Contributor

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.

Copy link
Contributor Author

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!

@mergify mergify bot dismissed TheRealAmazonKendra’s stale review August 2, 2022 14:57

Pull request has been modified.

@TheRealAmazonKendra TheRealAmazonKendra changed the title feat(iotevents): Support the timer actions feat(iotevents): support timer actions Aug 3, 2022
- Set variable to detector instanse
- Invoke a Lambda function

## Use timer
Copy link
Contributor

Choose a reason for hiding this comment

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

Excellent README!

iotevents.Expression.inputAttribute(input, 'payload.temperature'),
),
],
new actions.SetVariableAction(
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch

}
}

bind(_scope: Construct, _options: iotevents.ActionBindOptions): iotevents.ActionConfig {
Copy link
Contributor

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.

Copy link
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

Looks great!

@mergify
Copy link
Contributor

mergify bot commented Aug 3, 2022

Thank you for contributing! Your pull request will be updated from main 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: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 9c62a4a
  • 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 af301dd into aws:main Aug 3, 2022
@mergify
Copy link
Contributor

mergify bot commented Aug 3, 2022

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

josephedward pushed a commit to josephedward/aws-cdk that referenced this pull request Aug 30, 2022
This PR is a part of roadmap in aws#17711. And if this PR is merged, I will close this issue and create some good first issues to implement rest actions and expressions.

This PR supports the timer actions (`SetTimerAction`, `ResetTimerAction` and `ClearTimerAction`) and `timeout()` expression.

These allow to embed a timer to the state machine of the detector model.
Below figure illustrate the state machine [Device Heartbeat](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-examples-dhb.html). This detector model is used to alert if the message is interrupted for a certain period of time. The integ-test included in this PR is example of creating Device Heartbeat detector model.

```mermaid
stateDiagram-v2
  [*] --> Online: set a timer on input message
  Online --> Online: reset the timer\non input messages
  Online --> Offline: timeout the timer
  Offline --> Online: input messages
```

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants