Skip to content

Commit d483fa9

Browse files
authored
Add new stop queue action (#3054)
* add kill and stop queue * remove kill as it has a different function
1 parent aa3937c commit d483fa9

File tree

9 files changed

+72
-5
lines changed

9 files changed

+72
-5
lines changed

extension/package.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,11 @@
341341
"category": "DVC",
342342
"icon": "$(run-all)"
343343
},
344+
{
345+
"title": "%command.stopExperimentsQueue%",
346+
"command": "dvc.stopExperimentsQueue",
347+
"category": "DVC"
348+
},
344349
{
345350
"title": "%command.resetAndRunCheckpointExperiment%",
346351
"command": "dvc.resetAndRunCheckpointExperiment",
@@ -775,7 +780,11 @@
775780
},
776781
{
777782
"command": "dvc.startExperimentsQueue",
778-
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running"
783+
"when": "dvc.commands.available && dvc.project.available"
784+
},
785+
{
786+
"command": "dvc.stopExperimentsQueue",
787+
"when": "dvc.commands.available && dvc.project.available"
779788
},
780789
{
781790
"command": "dvc.selectForCompare",
@@ -1257,9 +1266,14 @@
12571266
},
12581267
{
12591268
"command": "dvc.startExperimentsQueue",
1260-
"when": "view == dvc.views.experimentsTree && !dvc.experiment.running",
1269+
"when": "view == dvc.views.experimentsTree",
12611270
"group": "3_queue@2"
12621271
},
1272+
{
1273+
"command": "dvc.stopExperimentsQueue",
1274+
"when": "view == dvc.views.experimentsTree",
1275+
"group": "3_queue@3"
1276+
},
12631277
{
12641278
"command": "dvc.addExperimentsTableSort",
12651279
"when": "view == dvc.views.experimentsSortByTree",

extension/package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"command.runExperiment": "Run Experiment",
4646
"command.resumeCheckpointExperiment": "Resume Experiment",
4747
"command.startExperimentsQueue": "Start the Experiments Queue",
48+
"command.stopExperimentsQueue": "Stop the Experiments Queue",
4849
"command.resetAndRunCheckpointExperiment": "Run Experiment",
4950
"command.selectForCompare": "Select for Compare",
5051
"command.selectFocusedProjects": "Select Project(s) to Focus (set dvc.focusedProjects)",

extension/src/cli/dvc/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ export enum ExperimentSubCommand {
6262
}
6363

6464
export enum QueueSubCommand {
65-
START = 'start'
65+
START = 'start',
66+
STOP = 'stop'
6667
}
6768

6869
export enum ExperimentFlag {

extension/src/cli/dvc/executor.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,27 @@ describe('CliExecutor', () => {
585585
})
586586
})
587587

588+
describe('queueStop', () => {
589+
it("should call createProcess with the correct parameters to stop the experiment's queue", async () => {
590+
const cwd = __dirname
591+
592+
const stdout = 'Queue workers will stop after running tasks finish.'
593+
594+
mockedCreateProcess.mockReturnValueOnce(getMockedProcess(stdout))
595+
596+
const output = await dvcExecutor.queueStop(cwd)
597+
598+
expect(output).toStrictEqual(stdout)
599+
600+
expect(mockedCreateProcess).toHaveBeenCalledWith({
601+
args: ['queue', 'stop'],
602+
cwd,
603+
env: mockedEnv,
604+
executable: 'dvc'
605+
})
606+
})
607+
})
608+
588609
describe('remove', () => {
589610
it('should call createProcess with the correct parameters to remove a .dvc file', async () => {
590611
const cwd = __dirname

extension/src/cli/dvc/executor.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const autoRegisteredCommands = {
2727
PULL: 'pull',
2828
PUSH: 'push',
2929
QUEUE_START: 'queueStart',
30+
QUEUE_STOP: 'queueStop',
3031
REMOVE: 'remove'
3132
} as const
3233

@@ -138,6 +139,10 @@ export class DvcExecutor extends DvcCli {
138139
)
139140
}
140141

142+
public queueStop(cwd: string) {
143+
return this.executeDvcProcess(cwd, Command.QUEUE, QueueSubCommand.STOP)
144+
}
145+
141146
public remove(cwd: string, ...args: Args) {
142147
return this.blockAndExecuteProcess(cwd, Command.REMOVE, ...args)
143148
}

extension/src/commands/external.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export enum RegisteredCliCommands {
1212
EXPERIMENT_SHARE_AS_COMMIT = 'dvc.shareExperimentAsCommit',
1313
QUEUE_EXPERIMENT = 'dvc.queueExperiment',
1414
QUEUE_START = 'dvc.startExperimentsQueue',
15+
QUEUE_STOP = 'dvc.stopExperimentsQueue',
1516

1617
EXPERIMENT_VIEW_APPLY = 'dvc.views.experiments.applyExperiment',
1718
EXPERIMENT_VIEW_BRANCH = 'dvc.views.experiments.branchExperiment',

extension/src/experiments/commands/register.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ const registerExperimentCwdCommands = (
2727
)
2828
)
2929

30+
internalCommands.registerExternalCliCommand(
31+
RegisteredCliCommands.QUEUE_STOP,
32+
() => experiments.getCwdThenReport(AvailableCommands.QUEUE_STOP)
33+
)
34+
3035
internalCommands.registerExternalCliCommand(
3136
RegisteredCliCommands.MODIFY_EXPERIMENT_PARAMS_AND_QUEUE,
3237
() =>

extension/src/telemetry/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ export interface IEventNamePropertyMapping {
155155
[EventName.EXPERIMENT_VIEW_SHARE_AS_COMMIT]: undefined
156156
[EventName.QUEUE_EXPERIMENT]: undefined
157157
[EventName.QUEUE_START]: undefined
158+
[EventName.QUEUE_STOP]: undefined
158159

159160
[EventName.EXPERIMENT_VIEW_QUEUE]: undefined
160161
[EventName.EXPERIMENT_VIEW_RESUME]: undefined

extension/src/test/suite/experiments/workspace.test.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ suite('Workspace Experiments Test Suite', () => {
438438
})
439439

440440
describe('dvc.startExperimentsQueue', () => {
441-
it('should be able to execute all experiments in the run queue', async () => {
441+
it('should be able to start the experiments queue with the selected number of workers', async () => {
442442
const mockQueueStart = stub(DvcExecutor.prototype, 'queueStart').resolves(
443443
undefined
444444
)
@@ -454,11 +454,29 @@ suite('Workspace Experiments Test Suite', () => {
454454
await commands.executeCommand(RegisteredCliCommands.QUEUE_START)
455455

456456
expect(mockQueueStart).to.be.calledOnce
457-
expect(mockQueueStart).to.be.calledWith(dvcDemoPath, dDosNumberOfJobs)
457+
expect(mockQueueStart).to.be.calledWithExactly(
458+
dvcDemoPath,
459+
dDosNumberOfJobs
460+
)
458461
expect(mockInputBox)
459462
})
460463
})
461464

465+
describe('dvc.stopExperimentsQueue', () => {
466+
it('should be able to stop the experiments queue', async () => {
467+
const mockQueueStop = stub(DvcExecutor.prototype, 'queueStop').resolves(
468+
undefined
469+
)
470+
471+
stubWorkspaceExperimentsGetters(dvcDemoPath)
472+
473+
await commands.executeCommand(RegisteredCliCommands.QUEUE_STOP)
474+
475+
expect(mockQueueStop).to.be.calledOnce
476+
expect(mockQueueStop).to.be.calledWithExactly(dvcDemoPath)
477+
})
478+
})
479+
462480
describe('dvc.applyExperiment', () => {
463481
it('should ask the user to pick an experiment and then apply that experiment to the workspace', async () => {
464482
const selectedExperiment = 'test-branch'

0 commit comments

Comments
 (0)