Skip to content

Commit

Permalink
fix docs and examples. Don't use job state file when deleting all
Browse files Browse the repository at this point in the history
  • Loading branch information
busma13 committed Sep 5, 2024
1 parent 8c0901f commit 208d26e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/packages/teraslice-cli/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ Delete a job or jobs by job_id from a teraslice cluster. Jobs must be in a termi
teraslice-cli jobs delete <cluster> <job_id>
# delete a job
teraslice-cli jobs delete cluster1 99999999-9999-9999-9999-999999999999
# delete all jobs on a cluster, no prompt.
# delete all stopped jobs on a cluster, no prompt. Active jobs will be skipped.
teraslice-cli jobs delete cluster1 all -y
```

Expand Down
2 changes: 1 addition & 1 deletion packages/teraslice-cli/src/cmds/ex/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default {
yargs.strict()
.example('$0 ex list cluster1', 'Show executions in a cluster')
.example('$0 ex list cluster1 --status=failing', 'Show all executions in cluster with a status of failing')
.example('$0 ex list cluster1 --deleted=include', 'Show all executions in cluster, including deleted');
.example('$0 ex list cluster1 --deleted=true', 'Show only deleted executions in cluster');
return yargs;
},
async handler(argv) {
Expand Down
2 changes: 1 addition & 1 deletion packages/teraslice-cli/src/cmds/jobs/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {
yargs.strict()
.example('$0 jobs delete CLUSTER_ALIAS JOB_ID', 'deletes job on a cluster')
.example('$0 jobs delete CLUSTER_ALIAS JOB_ID1 JOB_ID2', 'deletes multiple jobs on a cluster')
.example('$0 jobs delete CLUSTER_ALIAS all', 'deletes all jobs on a cluster from the state file');
.example('$0 jobs delete CLUSTER_ALIAS all', 'deletes all non-active jobs on a cluster');
return yargs;
},
async handler(argv: any) {
Expand Down
4 changes: 2 additions & 2 deletions packages/teraslice-cli/src/cmds/jobs/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export default {
yargs.options('active', yargsOptions.buildOption('active-job'));
yargs.strict()
.example('$0 jobs list CLUSTER_ALIAS')
.example('$0 jobs list CLUSTER_ALIAS --deleted include', 'Show all jobs in cluster, including deleted')
.example('$0 jobs list CLUSTER_ALIAS --active true', 'Show only active jobs in cluster');
.example('$0 jobs list CLUSTER_ALIAS --deleted=true', 'Show only deleted jobs in cluster')
.example('$0 jobs list CLUSTER_ALIAS --active=true', 'Show only active jobs in cluster');
return yargs;
},
async handler(argv: any) {
Expand Down
18 changes: 16 additions & 2 deletions packages/teraslice-cli/src/helpers/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,16 +589,21 @@ export default class Jobs {
if (await this.prompt()) {
const { _action: action, clusterAlias } = this.config.args;
// if action is start and not from a restart
// or if action is delete
// then need to get job ids from saved state
if (action === 'start' || action === 'delete') {
if (action === 'start') {
if (fs.pathExistsSync(this.config.jobStateFile) === false) {
reply.fatal(`Could not find job state file for ${clusterAlias}, this is required to ${action} all jobs`);
}

return this.getJobIdsFromSavedState();
}

// if action is delete we need to get inactive
// as well as active jobs
if (action === 'delete') {
return this.getActiveAndInactiveJobIds();
}

return this.getActiveJobIds();
}

Expand All @@ -612,6 +617,15 @@ export default class Jobs {
return Object.keys(state);
}

private async getActiveAndInactiveJobIds() {
try {
const jobs = await this.teraslice.client.jobs.list();
return jobs.map((job) => job.job_id);
} catch (e) {
throw Error(e);
}
}

private async getActiveJobIds(): Promise<string[]> {
const controllers = await this.getClusterControllers();

Expand Down

0 comments on commit 208d26e

Please sign in to comment.