Skip to content

Add 'set_task_metadata', associated test, and example in README#56

Merged
kevin-xu-scale merged 9 commits into
masterfrom
set-task-metadata
Oct 7, 2022
Merged

Add 'set_task_metadata', associated test, and example in README#56
kevin-xu-scale merged 9 commits into
masterfrom
set-task-metadata

Conversation

@kevin-xu-scale
Copy link
Copy Markdown
Contributor

No description provided.

Comment thread scaleapi/__init__.py Outdated
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:
Copy link
Copy Markdown
Collaborator

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?

Copy link
Copy Markdown
Contributor Author

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

Comment thread README.rst Outdated
.. code-block :: python

# set metadata on a task to be the contents of new_metadata
new_metadata = {'metadata': {'myKey': 'myValue'}}
Copy link
Copy Markdown
Collaborator

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'}?

Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown
Contributor Author

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?

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Collaborator

@fatihkurtoglu fatihkurtoglu Sep 29, 2022

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:

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.

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor Author

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

@kevin-xu-scale
Copy link
Copy Markdown
Contributor Author

The set metadata test will fail until the change to the API endpoint is merged and deployed

@kevin-xu-scale
Copy link
Copy Markdown
Contributor Author

@fatihkurtoglu Within this branch I've bumped the version to v2.10.0
I've also created a draft release here: https://github.com/scaleapi/scaleapi-python-client/releases/tag/untagged-981fad3f8d1fda94a748

Could you help me review/approve when able?
I'm unclear on whether or not I need to publish the release first, before this branch is merged into master, or vice versa
Thanks!

Copy link
Copy Markdown
Collaborator

@fatihkurtoglu fatihkurtoglu left a 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().

def cancel(self, clear_unique_id: bool = False):
"""Cancels the task"""
self._client.cancel_task(self.id, clear_unique_id)

Comment thread scaleapi/__init__.py Outdated
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:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def set_task_metadata(self, task_id: str, metadata: dict) -> Task:
def set_task_metadata(self, task_id: str, metadata: Dict) -> Task:

Comment thread README.rst Outdated
Set A Task's Metadata
^^^^^^^^^^^^^^^^^^^^^^^^^

Set a given task's `metadata`. Check out `Scale's API documentation`__ for more information.
Copy link
Copy Markdown
Collaborator

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.

Suggested change
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.

@fatihkurtoglu
Copy link
Copy Markdown
Collaborator

@fatihkurtoglu Within this branch I've bumped the version to v2.10.0 I've also created a draft release here: https://github.com/scaleapi/scaleapi-python-client/releases/tag/untagged-981fad3f8d1fda94a748

Could you help me review/approve when able? I'm unclear on whether or not I need to publish the release first, before this branch is merged into master, or vice versa Thanks!

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 v2.10.0. So the tag creation triggers a publish to pypi.

@kevin-xu-scale
Copy link
Copy Markdown
Contributor Author

@fatihkurtoglu changes implemented, new test added, squashing and merging now

@kevin-xu-scale kevin-xu-scale merged commit b7ffab5 into master Oct 7, 2022
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.

3 participants