Cancelling all running or waiting jobs

Hey!

Just wondering if there are any quick cli commands to kill all jobs across all projects and workspaces in the current states: [‘queued’, ‘launched’, ‘started’, ‘waiting’, ‘running’]

Will this terminate the jobs submitted to a Slurm scheduler cleanly?

Cheers!

Keeping in mind that the behavior or availability of CryoSPARC cli commands is subject to change in future versions of CryoSPARC, in CryoSPARC v4.6.2 you should be able to save this script

import cryosparc_compute.client
import os

cli = cryosparc_compute.client.CommandClient(
        host=os.environ['CRYOSPARC_MASTER_HOSTNAME'],
        port=os.environ['CRYOSPARC_COMMAND_CORE_PORT'],
        service='command_core')

for status in ['queued', 'launched', 'started', 'waiting', 'running']:
    for job in cli.get_jobs_by_status(status):
        try:
            cli.kill_job(job['project_uid'], job['uid'])
            print(f"kill_job() was sent to {job['project_uid']} {job['uid']} ({status} {job['job_type']}).")
            continue
        except:
            pass
        try: # kill_job() does not work for queued jobs
            cli.clear_job(job['project_uid'], job['uid'])
            print(f"clear_job() was sent to {job['project_uid']} {job['uid']} ({status} {job['job_type']}).")
            continue
        except:
            print(f"Giving up on trying to terminate job {job['project_uid']} {job['uid']} ({status} {job['job_type']})")

to a file, like terminate_cryosparc_jobs.py, and run it

cryosparcm call python /path/to/terminate_cryosparc_jobs.py

Thank you @wtempel! Worked perfectly.