-
Notifications
You must be signed in to change notification settings - Fork 20
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
base: master
Are you sure you want to change the base?
Conversation
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"): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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'
@MFSY any thoughts? |
* batch retrieval * return action on error
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 therequests.request
method (for synchronous calls, when performing these operations for one resource) oraiohttp.ClientSession.request
(for asynchronous calls, when performing these operations for multiple resources)When using
BatchRequestHandler.batch_request_for_resources
, the appropriateprepare_x
should be provided. Everything else can either be found in theservice
instance or thekwargs
.BatchRequestHandler.batch_request
provides a way to run a list of tasks. These tasks will be initialised using thetask_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 byBatchRequestHandler.create_tasks_for_resources
In the effort to remove duplication of logic, some differences were spotted:
nexus-forge/kgforge/specializations/stores/bluebrain_nexus.py
Line 119 in 02da102
nexus-forge/kgforge/specializations/stores/bluebrain_nexus.py
Line 190 in 02da102
This has not been addressed in this MR but should be in the future.