Skip to content

Commit

Permalink
updated job rm cli
Browse files Browse the repository at this point in the history
  • Loading branch information
cms21 committed Oct 30, 2023
1 parent 9d4d76d commit 42295f0
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions balsam/cmdline/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,12 @@ def modify(job_ids: List[int], tags: List[str], state: JobState) -> None:
@job.command()
@click.option("-i", "--id", "job_ids", multiple=True, type=int)
@click.option("-t", "--tag", "tags", multiple=True, type=str, callback=validate_tags)
@click.option("-s", "--state", type=str, callback=validate_state)
@click.option("-ns", "--exclude-state", type=str, callback=validate_state)
@click.option("--site", "site_selector", default="")
@click.option("-y", "yes", is_flag=True, default=False)
@click.option("--all", is_flag=True, default=False)
def rm(job_ids: List[int], tags: List[str], yes: bool, all: bool) -> None:
def rm(job_ids: List[int], site_selector: str, tags: List[str], state: Optional[JobState], exclude_state: Optional[JobState], yes: bool, all: bool) -> None:
"""
Remove Jobs
Expand All @@ -357,19 +360,37 @@ def rm(job_ids: List[int], tags: List[str], yes: bool, all: bool) -> None:
balsam job rm --tag workflow=temp-test
3) Remove all jobs (DANGER!)
3) Remove Jobs by State
balsam job rm --state FAILED
4) Filter by Site ID or Path fragments (comma-separated)
balsam job rm --site=123,my-cori-site
5) Remove all jobs (DANGER!)
balsam job rm --all
"""
client: RESTClient = load_client()
jobs = client.Job.objects.all()

jobs = filter_by_sites(client.Job.objects.all(), site_selector)

if job_ids:
jobs = jobs.filter(id=job_ids)
elif tags:
jobs = jobs.filter(tags=tags)
elif tags or state or exclude_state:
if tags:
jobs = jobs.filter(tags=tags)
if state:
jobs = jobs.filter(state=state)
click.echo("filtering by state")
if exclude_state:
jobs = jobs.filter(state__ne=exclude_state)
elif all:
click.echo("THIS WILL DELETE ALL JOBS! CAUTION!")
pass
elif site_selector != "":
pass
else:
raise click.BadParameter("Provide either list of Job ids or tags to delete")
count = jobs.count()
Expand Down

0 comments on commit 42295f0

Please sign in to comment.