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(idempotency): Add function wrapper and decorator #1262

Merged
merged 73 commits into from
Feb 6, 2023

Conversation

KevenFuentes9
Copy link
Contributor

@KevenFuentes9 KevenFuentes9 commented Jan 27, 2023

Description of your changes

This PR includes the creation of the function wrapper as well as the decorator for the idempotency package, creating a wrapped function that will invoke the idempotency logic. This does not yet address the saving of the record into the persistence layer, but more so has the concurrently logic underlying the idempotency logic. The record saving/retrieving will be done in a subsequent PR. Once that is done, the wrapper and decorator will have the simple case Idempotency logic completed.

How to verify this change

Related issues, RFCs

Issue number: 447

PR status

Is this ready for review?: NO
Is it a breaking change?: NO

Checklist

  • My changes meet the tenets criteria
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in areas that should be flagged with a TODO, or hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding changes to the examples
  • My changes generate no new warnings
  • The code coverage hasn't decreased
  • I have added tests that prove my change is effective and works
  • New and existing unit tests pass locally and in Github Actions
  • Any dependent changes have been merged and published
  • The PR title follows the conventional commit semantics

Breaking change checklist

  • I have documented the migration process
  • I have added, implemented necessary warnings (if it can live side by side)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

vgphoenixcampos and others added 30 commits October 27, 2022 16:45
@pull-request-size pull-request-size bot added the size/L PRs between 100-499 LOC label Jan 27, 2023
@github-actions github-actions bot added the feature PRs that introduce new features or minor changes label Jan 28, 2023
@saragerion saragerion self-requested a review January 30, 2023 09:59
@saragerion
Copy link
Contributor

Thanks for opening this PR @KevenFuentes9! Great stuff :)
Haven't reviewed it yet, but I just wanted to acknowledge that I saw it and started looking into it.

@saragerion saragerion added the idempotency This item relates to the Idempotency Utility label Jan 30, 2023
@saragerion saragerion added this to the Idempotency - Beta release milestone Jan 30, 2023
@@ -10,8 +10,23 @@ class IdempotencyInvalidStatusError extends Error {

}

class IdempotencyInconsistentStateError extends Error {

Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: adding a meaningful and easy to understand error message for each of these Errors would improve the DX and help troubleshooting errors

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 added a message to this when the error is created since this error can happen in more than one type of scenario. That way we can tailor the message by the scenario

Copy link
Contributor

@saragerion saragerion left a comment

Choose a reason for hiding this comment

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

I left a few comments in the PR. I am happy to merge the PR as it is with the goal of accelerating progress, but I'd also like to discuss the comments I left, agree on the outcome, and ideally address them on the next steps if that is ok with you.
Let's sync on those and define a plan of action.


export class IdempotencyHandler<U> {

public constructor(private functiontoMakeIdempotent: AnyFunctionWithRecord<U>, private functionPayloadToBeHashed: unknown,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion for this constructor signature:
Rename functiontoMakeIdempotent to functionToMakeIdempotent

Question: why the explicit access modifiers in the parameters? (private)

}
}

public async process_idempotency(): Promise<U> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use camelCase for consistency?

classWithFunction.testing(inputRecord);
});

test('Then it will save the record to IN_PROGRESS', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: I see that in some places we use the string "IN_PROGRESS" and in others "INPROGRESS". I am in favour of the former for readability, but most importantly we should stick to one.

@saragerion saragerion merged commit eacb1d9 into aws-powertools:main Feb 6, 2023
@dreamorosi dreamorosi removed this from the Idempotency - Beta release milestone Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature PRs that introduce new features or minor changes idempotency This item relates to the Idempotency Utility size/L PRs between 100-499 LOC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants