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): simplify access to expiration time in DataRecord class #5082

Conversation

leandrodamascena
Copy link
Contributor

Issue number: #4818

Summary

Changes

This PR introduces a new method to simplify access to expiration times for idempotent operations. It streamlines the process of retrieving and working with expiration timestamps in the Idempotency record.

User experience

BEFORE

def my_response_hook(response: Dict, idempotent_data: DataRecord) -> Dict:
    # Return inserted Header data into the Idempotent Response
    response["x-idempotent-key"] = idempotent_data.idempotency_key

    # expiry_timestamp could be None so include if set
    expiry_timestamp = idempotent_data.expiry_timestamp
    if expiry_timestamp:
        expiry_time = datetime.datetime.fromtimestamp(int(expiry_timestamp))
        response["x-idempotent-expiration"] = expiry_time.isoformat()

    # Must return the response here
    return response

AFTER

def my_response_hook(response: Dict, idempotent_data: DataRecord) -> Dict:
    # Return inserted Header data into the Idempotent Response
    response["x-idempotent-key"] = idempotent_data.idempotency_key

    # expiry_timestamp can be None so include if set
    expiry_timestamp = idempotent_data.get_expiration_datetime()
    if expiry_timestamp:
        response["x-idempotent-expiration"] = expiry_timestamp.isoformat()

    # Must return the response here
    return response

Checklist

If your change doesn't seem to apply, please leave them unchecked.

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.

@leandrodamascena leandrodamascena requested a review from a team as a code owner August 26, 2024 22:02
@boring-cyborg boring-cyborg bot added the tests label Aug 26, 2024
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 26, 2024
@github-actions github-actions bot added the feature New feature or functionality label Aug 26, 2024
Copy link

@leandrodamascena
Copy link
Contributor Author

Pls I need your review here @sthulb!

@leandrodamascena leandrodamascena changed the title feat(idempotency): simplify access to expiration time feat(idempotency): simplify access to expiration time in DataRecord Aug 27, 2024
@leandrodamascena leandrodamascena changed the title feat(idempotency): simplify access to expiration time in DataRecord feat(idempotency): simplify access to expiration time in DataRecord class Aug 27, 2024
@leandrodamascena leandrodamascena merged commit 6acc5fa into aws-powertools:v3 Aug 27, 2024
17 checks passed
@leandrodamascena leandrodamascena deleted the idempotency/return-expire-time branch August 27, 2024 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or functionality size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Simplify experience in discovering how much time left before Idempotency record expiration
2 participants