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: idempotent function #349

Merged

Conversation

hossambarakat
Copy link
Contributor

Issue number: #348

Summary

Changes

Update the IdempotentAttribute to get the payload based on the following:

  • If the method only has one parameter, it will be used by default.
  • If there are 2 or more parameters, you must set the IdempotencyKey attribute on the parameter to use.

User experience

    public class Function
    {
        public Function()
        {
            Idempotency.Configure(builder => builder.UseDynamoDb("idempotency_table"));
        }
        
        public Task<string> FunctionHandler(string input, ILambdaContext context)
        {
            dummpy("hello", "world")
            return Task.FromResult(input.ToUpper());
        }

        [Idempotent]
        private string dummy(string argOne, [IdempotencyKey] string argTwo) {
            return "something";
        }
    }

Checklist

Please leave checklist items unchecked if they do not apply to your change.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

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

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@auto-assign auto-assign bot requested review from amirkaws and hjgraca July 9, 2023 16:55
@auto-assign auto-assign bot requested a review from sliedig July 9, 2023 16:55
@boring-cyborg boring-cyborg bot added documentation Improvements or additions to documentation tests labels Jul 9, 2023
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 9, 2023
@hjgraca hjgraca changed the title Feat: idempotent function feat: idempotent function Jul 10, 2023
@github-actions github-actions bot added the feature New features or minor changes label Jul 10, 2023
@hjgraca hjgraca linked an issue Jul 10, 2023 that may be closed by this pull request
2 tasks
private static bool IsPlacedOnRequestHandler(MethodBase method)
{
//Check if method has two arguments and the second one is of type ILambdaContext
return method.GetParameters().Length == 2 && method.GetParameters()[1].ParameterType == typeof(ILambdaContext);
Copy link
Contributor

Choose a reason for hiding this comment

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

Small note: ILambdaContext is an optional argument, which will return false on IsPlacedOnRequestHandler, but from the looks of it the if there is only one argument it is also valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You got it right, either one parameter or 2 parameters where the second parameter is ILambdaContext

Copy link
Contributor

@amirkaws amirkaws left a comment

Choose a reason for hiding this comment

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

LGTM

@hjgraca hjgraca merged commit fa2d71e into aws-powertools:develop Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/idempotency documentation Improvements or additions to documentation feature New features or minor changes size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Idempotent attribute on another method
3 participants