Skip to content

Commit

Permalink
feat(buckets.py): added limit option to remove command (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
odarotto committed Sep 11, 2024
1 parent cd22f85 commit 01a5fc8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion workflow/cli/buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ def buckets():
)
@click.option("-p", "--parent", type=str, required=False, help="Filter by parent.")
@click.option("-f", "--force", is_flag=True, help="Do not prompt for confirmation")
@click.option(
"-l", "--limit", type=int, required=False, help="Limit of Work objects to remove."
)
def remove(
bucket: str,
status: Optional[str] = None,
event: Optional[Tuple[int]] = None,
tag: Optional[Tuple[str]] = None,
parent: Optional[str] = None,
force: bool = False,
limit: Optional[int] = 100,
):
"""Remove work[s] from the buckets.
Expand All @@ -55,8 +59,9 @@ def remove(
tag (Optional[Tuple[str]], optional): Filter by tag. Defaults to None.
parent (Optional[str], optional): Filter by parent. Defaults to None.
force (bool, optional): Do not prompt for confirmation. Defaults to False.
limit (int, optional): Limit of Work objects to remove. Defaults to False.
"""
http = HTTPContext()
http = HTTPContext(backends=["buckets"])
events: Optional[List[int]] = None
tags: Optional[List[str]] = None
if event:
Expand All @@ -70,6 +75,7 @@ def remove(
tags=tags,
parent=parent,
force=force,
limit=limit,
)


Expand Down
4 changes: 3 additions & 1 deletion workflow/http/buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def delete_many(
tags: Optional[List[str]] = None,
parent: Optional[str] = None,
force: bool = False,
limit: Optional[int] = 100
) -> bool:
"""Delete works belonging to a pipeline from the buckets backend.
Expand All @@ -161,6 +162,7 @@ def delete_many(
event (Optional[List[int]]): The event to delete works with.
force (bool, optional): Whether to force the deletion without requiring
user confirmation. Defaults to False.
limit (int, optional): Limit of Work objects to remove. Defaults to False.
Returns:
bool: Whether any works were deleted.
Expand All @@ -171,7 +173,7 @@ def delete_many(
query.update({"tags": {"$in": tags}} if tags else {})
query.update({"config.parent": parent} if parent else {})
projection = {"id": True}
result = self.view(query, projection)
result = self.view(query, projection, limit=limit)
ids: List[str] = []
if result:
ids = [work["id"] for work in result]
Expand Down

0 comments on commit 01a5fc8

Please sign in to comment.