Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.

Commit f68ae5e

Browse files
committed
Add jobs stop command
1 parent b2717c7 commit f68ae5e

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

paperspace/cli/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import click
2+
3+
api_key_option = click.option(
4+
"--apiKey",
5+
"api_key",
6+
help="API key to use this time only",
7+
)

paperspace/cli/cli.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import click
77

88
from paperspace import constants, client, config
9+
from paperspace.cli import api_key_option
910
from paperspace.cli.jobs.commands import jobs_group
1011
from paperspace.commands import experiments as experiments_commands, deployments as deployments_commands, \
1112
machines as machines_commands, login as login_commands
@@ -58,13 +59,6 @@ def del_if_value_is_none(dict_):
5859
del dict_[key]
5960

6061

61-
api_key_option = click.option(
62-
"--apiKey",
63-
"api_key",
64-
help="API key to use this time only",
65-
)
66-
67-
6862
def validate_mutually_exclusive(options_1, options_2, error_message):
6963
used_option_in_options_1 = any(option is not None for option in options_1)
7064
used_option_in_options_2 = any(option is not None for option in options_2)

paperspace/cli/jobs/commands.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import click
22

33
from paperspace import client, config
4+
from paperspace.cli import api_key_option
45
from paperspace.commands import jobs as jobs_commands
56

67

@@ -15,7 +16,21 @@ def jobs_group():
1516
"job_id",
1617
required=True,
1718
)
19+
@api_key_option
1820
def delete_job(job_id, api_key=None):
1921
jobs_api = client.API(config.CONFIG_HOST, api_key=api_key)
2022
command = jobs_commands.DeleteJobCommand(api=jobs_api)
2123
command.execute(job_id)
24+
25+
26+
@jobs_group.command("stop", help="Stop running job")
27+
@click.option(
28+
"--jobId",
29+
"job_id",
30+
required=True,
31+
)
32+
@api_key_option
33+
def stop_job(job_id, api_key=None):
34+
jobs_api = client.API(config.CONFIG_HOST, api_key=api_key)
35+
command = jobs_commands.StopJobCommand(api=jobs_api)
36+
command.execute(job_id)

paperspace/commands/jobs.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from paperspace.commands import CommandBase
22

33

4-
class _JobsCommandBase(CommandBase):
4+
class JobsCommandBase(CommandBase):
55
def _log_message(self, response, success_msg_template, error_msg):
66
if response.ok:
77
try:
@@ -19,10 +19,19 @@ def _log_message(self, response, success_msg_template, error_msg):
1919
self.logger.log(error_msg)
2020

2121

22-
class DeleteJobCommand(_JobsCommandBase):
22+
class DeleteJobCommand(JobsCommandBase):
2323
def execute(self, job_id):
2424
url = "/jobs/{}/destroy/".format(job_id)
2525
response = self.api.post(url)
2626
self._log_message(response,
2727
"Job deleted",
2828
"Unknown error while deleting job")
29+
30+
31+
class StopJobCommand(JobsCommandBase):
32+
def execute(self, job_id):
33+
url = "/jobs/{}/stop/".format(job_id)
34+
response = self.api.post(url)
35+
self._log_message(response,
36+
"Job stopped",
37+
"Unknown error while stopping job")

0 commit comments

Comments
 (0)