-
Notifications
You must be signed in to change notification settings - Fork 33
Add 'set_task_metadata', associated test, and example in README #56
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
Conversation
scaleapi/__init__.py
Outdated
@@ -114,6 +115,22 @@ def clear_task_unique_id(self, task_id: str) -> Task: | |||
endpoint = f"task/{task_id}/unique_id" | |||
return Task(self.api.delete_request(endpoint), self) | |||
|
|||
def set_task_metadata(self, task_id: str, metadata: json) -> Task: |
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.
Just thinking about whether we should expect a JSON or a Dict/object as input?
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.
Revised to expect Dict instead of JSON
README.rst
Outdated
.. code-block :: python | ||
|
||
# set metadata on a task to be the contents of new_metadata | ||
new_metadata = {'metadata': {'myKey': 'myValue'}} |
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.
I think we append metadata in the method? So users should only pass {'myKey': 'myValue'}
?
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.
Also should we govern that in the method? When they check the API guide they may think they need to pass metadata as well, but appending that ourselves is probably a better user experience.
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.
Possible oversight here, but the current implementation of the API endpoint does expect that the customer will provide the metadata in the format of `{"metadata": {"key": "value"}}.
Should we revise the endpoint and also update the SDK to reflect this change?
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.
Ah.. yeah, we probably should - sorry I missed that nuance.
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.
No matter what we choose, I think we should be consistent all over the place.
If endpoint expects a metadata
as the main key then we should:
- expect user to follow that format
- is this enforced in API? If not, we may also govern that in SDK as an additional measure. metadata key to be there, be an object? and be the only key in the main object?
- We may not add extra metadata in the method: https://github.com/scaleapi/scaleapi-python-client/pull/56/files#diff-09863685c9b788d64d266a4468f8e7f893e1d1c7773c9e20c6757b70fd378608R130 just expect user to do that if API expects.
payload = {"metadata": metadata}
Or we should update the API just to accept any object and store under metadata. (so users does not need to add extra metadata field) -> I'm pro to this.
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 API currently does enforce having the "metadata" key
I'll revise the logic in the API and then revise the behavior in the SDK today so that they are consistent
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.
PR created for change to API endpoint: https://github.com/scaleapi/scaleapi/pull/47725
The set metadata test will fail until the change to the API endpoint is merged and deployed |
@fatihkurtoglu Within this branch I've bumped the version to Could you help me review/approve when able? |
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.
@kevin-xu-scale looks good to me. I would also implement set_metadata as a method under Task object too. i.e. we have cancel_task at API level, but also implemented Task.cancel().
scaleapi-python-client/scaleapi/tasks.py
Lines 87 to 89 in 4c46e1a
def cancel(self, clear_unique_id: bool = False): | |
"""Cancels the task""" | |
self._client.cancel_task(self.id, clear_unique_id) |
scaleapi/__init__.py
Outdated
@@ -114,6 +114,21 @@ def clear_task_unique_id(self, task_id: str) -> Task: | |||
endpoint = f"task/{task_id}/unique_id" | |||
return Task(self.api.delete_request(endpoint), self) | |||
|
|||
def set_task_metadata(self, task_id: str, metadata: dict) -> Task: |
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.
def set_task_metadata(self, task_id: str, metadata: dict) -> Task: | |
def set_task_metadata(self, task_id: str, metadata: Dict) -> Task: |
README.rst
Outdated
Set A Task's Metadata | ||
^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
Set a given task's `metadata`. Check out `Scale's API documentation`__ for more information. |
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.
I think in .rst files, double tick makes it as a code format.
Set a given task's `metadata`. Check out `Scale's API documentation`__ for more information. | |
Set a given task's ``metadata``. Check out `Scale's API documentation`__ for more information. |
Once this PR is merged, it will have the 2.10.0 version in the master. Then you can release your version with the tag |
@fatihkurtoglu changes implemented, new test added, squashing and merging now |
No description provided.