Skip to content

Commit 94b729c

Browse files
authored
Add priority option to run the job (#1096)
* Add priority option to run the job Companion PR of #11559 * Update src/datachain/remote/studio.py * fix test
1 parent 526a0ab commit 94b729c

File tree

5 files changed

+19
-0
lines changed

5 files changed

+19
-0
lines changed

docs/commands/job/run.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This command runs a job in Studio using the specified query file. You can config
2929
* `--python-version PYTHON_VERSION` - Python version for the job (e.g., 3.9, 3.10, 3.11)
3030
* `--req-file REQ_FILE` - Python requirements file
3131
* `--req REQ` - Python package requirements
32+
* `--priority PRIORITY` - Priority for the job in range 0-5. Lower value is higher priority (default: 5)
3233
* `-h`, `--help` - Show the help message and exit.
3334
* `-v`, `--verbose` - Be verbose.
3435
* `-q`, `--quiet` - Be quiet.
@@ -65,6 +66,11 @@ datachain job run --env API_KEY=123 --req pandas numpy query.py
6566
datachain job run --repository https://github.com/iterative/datachain query.py
6667
```
6768

69+
7. Run a job with higher priority
70+
```bash
71+
datachain job run --priority 2 query.py
72+
```
73+
6874
## Notes
6975

7076
* Closing the logs command (e.g., with Ctrl+C) will only stop displaying the logs but will not cancel the job execution

src/datachain/cli/parser/job.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ def add_jobs_parser(subparsers, parent_parser) -> None:
8282
nargs="+",
8383
help="Python package requirements",
8484
)
85+
studio_run_parser.add_argument(
86+
"--priority",
87+
type=int,
88+
default=5,
89+
help="Priority for the job in range 0-5. "
90+
"Lower value is higher priority (default: 5)",
91+
)
8592

8693
studio_ls_help = "List jobs in Studio"
8794
studio_ls_description = "List jobs in Studio."

src/datachain/remote/studio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ def create_job(
388388
python_version: Optional[str] = None,
389389
requirements: Optional[str] = None,
390390
repository: Optional[str] = None,
391+
priority: Optional[int] = None,
391392
) -> Response[JobData]:
392393
data = {
393394
"query": query,
@@ -399,6 +400,7 @@ def create_job(
399400
"python_version": python_version,
400401
"requirements": requirements,
401402
"repository": repository,
403+
"priority": priority,
402404
}
403405
return self._send_request("datachain/job", data)
404406

src/datachain/studio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def process_jobs_args(args: "Namespace"):
4040
args.repository,
4141
args.req,
4242
args.req_file,
43+
args.priority,
4344
)
4445

4546
if args.cmd == "cancel":
@@ -266,6 +267,7 @@ def create_job(
266267
repository: Optional[str] = None,
267268
req: Optional[list[str]] = None,
268269
req_file: Optional[str] = None,
270+
priority: Optional[int] = None,
269271
):
270272
query_type = "PYTHON" if query_file.endswith(".py") else "SHELL"
271273
with open(query_file) as f:
@@ -294,6 +296,7 @@ def create_job(
294296
python_version=python_version,
295297
repository=repository,
296298
requirements=requirements,
299+
priority=priority,
297300
)
298301
if not response.ok:
299302
raise DataChainError(response.message)

tests/test_cli_studio.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,4 +424,5 @@ def test_studio_run(capsys, mocker, tmp_dir):
424424
"requirements": "pyjokes\nstupidity",
425425
"team_name": "team_name",
426426
"repository": "https://github.com/iterative/datachain",
427+
"priority": 5,
427428
}

0 commit comments

Comments
 (0)