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

Refactor batch request mechanism #383

Open
wants to merge 100 commits into
base: master
Choose a base branch
from
Open

Refactor batch request mechanism #383

wants to merge 100 commits into from

Conversation

ssssarah
Copy link
Contributor

@ssssarah ssssarah commented Feb 15, 2024

Motivated by:
Future batch retrieval feature, that could benefit from the existing mechanism, under some changes. + Aligning batch/single request logics (remove duplicate logic)

For the methods: Deprecate, Tag, Update, Update Schema, Register:

  • The logic of knowing which http method to use, which url to target, what query params to use, what headers to use, what payload to give and what exception to throw on error is prepared in prepared_methods.py. This information will either be used by the requests.request method (for synchronous calls, when performing these operations for one resource) or aiohttp.ClientSession.request (for asynchronous calls, when performing these operations for multiple resources)

  • When using BatchRequestHandler.batch_request_for_resources, the appropriate prepare_x should be provided. Everything else can either be found in the service instance or the kwargs.

  • BatchRequestHandler.batch_request provides a way to run a list of tasks. These tasks will be initialised using the task_creator parameter this method requires.

  • In the case of the methods cited above (deprecate, tag, update…), they all have the same task_creator method, which is defined by BatchRequestHandler.create_tasks_for_resources

In the effort to remove duplication of logic, some differences were spotted:

@ssssarah ssssarah marked this pull request as ready for review February 15, 2024 14:39
timeout=REQUEST_TIMEOUT
)
catch_http_error_nexus(response, RegistrationError)
data = payload

response_json = response.json()
resource.id = response_json["@id"]
# If resource had no context, update it with the one provided by the store.
if not hasattr(resource, "context"):
Copy link
Contributor

Choose a reason for hiding this comment

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

about this id/context addition to the resource when registering... it doesn't seem like a extreme change to make one general callback, I would say ... go for it if you already thought of a way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by a general callback?

Copy link
Contributor

Choose a reason for hiding this comment

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

there is a default callback method, that is shared within all the possible resource tasks, that is what I meant, why not to move the option of adding id/context there, to have one single method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The setting of the resource.id and context look harmless at first glance so I could see them happening for any resource operation. But are they really harmless?

First there's the question of harmonising the register_one and register_many callbacks before even thinking of making them the same as the other operations'

@crisely09
Copy link
Contributor

crisely09 commented Feb 22, 2024

@MFSY any thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants