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: generic resource support #125

Merged
merged 7 commits into from
Apr 27, 2023
Merged

Conversation

dshafer
Copy link
Collaborator

@dshafer dshafer commented Mar 23, 2023

  • Update CHANGELOG.md
  • Update README.md (as needed)
  • New dependencies were added to pyproject.toml
  • pip install succeeds with a clean virtualenv
  • There are new or modified tests that cover changes
  • Test coverage is maintained or expanded

@dshafer dshafer marked this pull request as draft March 23, 2023 13:54
**kwargs,
):
super().__init__(**kwargs)
assert (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this raise a TypeError?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My thinking is that because any incorrect usage of this decorator will reveal itself at compile time, was can use an assert rather than raising a TypeError and get the same protection because any issue will be reliably detected in unit tests. Using the assert allows the check to be optimized out when running in production


retry_params = RetryParams(*retry_params)
if retry_params.retry_exception_filter and not any(
[
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could probably drop the square brackets and let it be a generator expression?

@bgrant
Copy link
Collaborator

bgrant commented Apr 24, 2023

The test failures are from coverage:

Coverage failure: total of 89 is less than fail-under=90

@@ -228,7 +230,9 @@ def get_response(self): # noqa: C901

resource = self.bound_endpoint.resource

if hasattr(resource, "is_dirty"):
if isinstance(resource, django.db.models.Model) and hasattr(
Copy link
Collaborator

Choose a reason for hiding this comment

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

The idea is that if it's not a Django Model we might not want to update it so often? Updates for those objects will have to be handled outside of DDA?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah- in finalize

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah, this auto-save functionality is pretty tightly coupled to the resources being Django models. This PR allows using non-django models as resources, but the cost is that the endpoint implementation must handle persistence on its own

)

logger.info(
"future_task_runner: method=%s, resource_id=%s",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be "generic_future_task_runner"?

Comment on lines 330 to 347
if retry_params is None:
raise

retry_params = RetryParams(*retry_params)
if retry_params.retry_exception_filter and not any(
[
f"{e.__class__.__module__}.{e.__class__.__name__}" == ex_type
for ex_type in retry_params.retry_exception_filter
]
):
# this exception is not retryable
raise

if retry_params.retries_remaining == 0:
# out of chances
raise

_log_retry_stats(endpoint_method_name, resource_instance_id, correlation_id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is all identical to the section in future_task_runner right? Could it be extracted as a function? Some below too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this part is slightly different because of the different function signatures and how the resource is passed to the task runner. I briefly attempted to extract out some commonality to make it less repetitive, but it didn't yield much. I'll take another look though.

)


def schedule_generic_future_task_runner(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks identical to schedule_future_task_runner unless I'm missing something.

@bgrant
Copy link
Collaborator

bgrant commented Apr 25, 2023

Also, so we don't forget: CHANGELOG addition needed

@dshafer dshafer marked this pull request as ready for review April 26, 2023 22:28
@bgrant bgrant self-requested a review April 26, 2023 23:02
bgrant
bgrant previously approved these changes Apr 26, 2023
Copy link
Collaborator

@bgrant bgrant left a comment

Choose a reason for hiding this comment

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

Thanks!

@dshafer dshafer merged commit 25c6224 into main Apr 27, 2023
@dshafer dshafer deleted the feature/generic-resource-support branch April 27, 2023 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants